public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pankaj Raghav <kernel@pankajraghav.com>
To: minchan@kernel.org, senozhatsky@chromium.org
Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk,
	p.raghav@samsung.com, linux-block@vger.kernel.org,
	kernel@pankajraghav.com, gost.dev@samsung.com
Subject: [PATCH 1/5] zram: move index preparation to a separate function in writeback_store
Date: Mon, 11 Sep 2023 15:34:26 +0200	[thread overview]
Message-ID: <20230911133430.1824564-2-kernel@pankajraghav.com> (raw)
In-Reply-To: <20230911133430.1824564-1-kernel@pankajraghav.com>

From: Pankaj Raghav <p.raghav@samsung.com>

Add a new function writeback_prep_or_skip_index() that does the check
and set the approapriate flags before writeback starts. The function
returns false if the index can be skipped.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 drivers/block/zram/zram_drv.c | 68 +++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 06673c6ca255..eaf9e227778e 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -595,6 +595,46 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
 #define IDLE_WRITEBACK			(1<<1)
 #define INCOMPRESSIBLE_WRITEBACK	(1<<2)
 
+/*
+ * Returns: true if the index was prepared for further processing
+ *          false if the index can be skipped
+ */
+static bool writeback_prep_or_skip_index(struct zram *zram, int mode,
+					 unsigned long index)
+{
+	bool ret = false;
+
+	zram_slot_lock(zram, index);
+	if (!zram_allocated(zram, index))
+		goto skip;
+
+	if (zram_test_flag(zram, index, ZRAM_WB) ||
+	    zram_test_flag(zram, index, ZRAM_SAME) ||
+	    zram_test_flag(zram, index, ZRAM_UNDER_WB))
+		goto skip;
+
+	if (mode & IDLE_WRITEBACK && !zram_test_flag(zram, index, ZRAM_IDLE))
+		goto skip;
+	if (mode & HUGE_WRITEBACK && !zram_test_flag(zram, index, ZRAM_HUGE))
+		goto skip;
+	if (mode & INCOMPRESSIBLE_WRITEBACK &&
+	    !zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE))
+		goto skip;
+
+	/*
+	 * Clearing ZRAM_UNDER_WB is duty of caller.
+	 * IOW, zram_free_page never clear it.
+	 */
+	zram_set_flag(zram, index, ZRAM_UNDER_WB);
+	/* Need for hugepage writeback racing */
+	zram_set_flag(zram, index, ZRAM_IDLE);
+
+	ret = true;
+skip:
+	zram_slot_unlock(zram, index);
+	return ret;
+}
+
 static ssize_t writeback_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
 {
@@ -662,33 +702,9 @@ static ssize_t writeback_store(struct device *dev,
 			}
 		}
 
-		zram_slot_lock(zram, index);
-		if (!zram_allocated(zram, index))
-			goto next;
+		if (!writeback_prep_or_skip_index(zram, mode, index))
+			continue;
 
-		if (zram_test_flag(zram, index, ZRAM_WB) ||
-				zram_test_flag(zram, index, ZRAM_SAME) ||
-				zram_test_flag(zram, index, ZRAM_UNDER_WB))
-			goto next;
-
-		if (mode & IDLE_WRITEBACK &&
-		    !zram_test_flag(zram, index, ZRAM_IDLE))
-			goto next;
-		if (mode & HUGE_WRITEBACK &&
-		    !zram_test_flag(zram, index, ZRAM_HUGE))
-			goto next;
-		if (mode & INCOMPRESSIBLE_WRITEBACK &&
-		    !zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE))
-			goto next;
-
-		/*
-		 * Clearing ZRAM_UNDER_WB is duty of caller.
-		 * IOW, zram_free_page never clear it.
-		 */
-		zram_set_flag(zram, index, ZRAM_UNDER_WB);
-		/* Need for hugepage writeback racing */
-		zram_set_flag(zram, index, ZRAM_IDLE);
-		zram_slot_unlock(zram, index);
 		if (zram_read_page(zram, page, index, NULL)) {
 			zram_slot_lock(zram, index);
 			zram_clear_flag(zram, index, ZRAM_UNDER_WB);
-- 
2.40.1


  reply	other threads:[~2023-09-11 22:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230911133442eucas1p2f773a475e0a6dc1a448c63884d58c8d3@eucas1p2.samsung.com>
2023-09-11 13:34 ` [PATCH 0/5] Improve zram writeback performance Pankaj Raghav
2023-09-11 13:34   ` Pankaj Raghav [this message]
2023-09-11 13:34   ` [PATCH 2/5] zram: encapsulate writeback to the backing bdev in a function Pankaj Raghav
2023-09-11 13:34   ` [PATCH 3/5] zram: add alloc_block_bdev_range() and free_block_bdev_range() Pankaj Raghav
2023-09-11 13:34   ` [PATCH 4/5] zram: batch IOs during writeback to improve performance Pankaj Raghav
2023-09-11 13:34   ` [PATCH 5/5] zram: don't overload blk_idx variable in writeback_store() Pankaj Raghav
2023-09-18 13:53   ` [PATCH 0/5] Improve zram writeback performance Pankaj Raghav
2023-09-19  0:33     ` Sergey Senozhatsky
2023-09-19 14:20       ` Pankaj Raghav
2024-09-25 15:53       ` Jassi Brar
2024-09-26  4:33         ` Sergey Senozhatsky
2024-09-29 22:21           ` Jassi Brar
2024-09-26  4:41   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230911133430.1824564-2-kernel@pankajraghav.com \
    --to=kernel@pankajraghav.com \
    --cc=axboe@kernel.dk \
    --cc=gost.dev@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=p.raghav@samsung.com \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox