Linux block layer
 help / color / mirror / Atom feed
From: Nilay Vaish <nilayvaish@google.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@infradead.org>,
	Bart Van Assche <bvanassche@acm.org>,
	linux-block@vger.kernel.org,  Nilay Vaish <nilayvaish@google.com>
Subject: [PATCH v2 2/2] null_blk: stop storing the page index in page->private
Date: Thu, 26 Nov 2026 13:23:41 -0800	[thread overview]
Message-ID: <20261126212341.916839-3-nilayvaish@google.com> (raw)
In-Reply-To: <20261126212341.916839-1-nilayvaish@google.com>

Each backing page records its own index in page->private. The index was
only needed because radix_tree_gang_lookup() returns entries without
their indices. The XArray iteration provides the index, and every other
user already has it at hand.

Take the index from the iteration when flushing the cache, pass it to
null_flush_cache_page(), and drop the copy kept in the page together
with the sanity checks that compared it with the lookup index.

null_blk no longer uses page->private.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Nilay Vaish <nilayvaish@google.com>
---

Notes:
    These patches were written with the help of an AI coding assistant (Gemini).

 drivers/block/null_blk/main.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index e073eca48655..299cf57b1c12 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -961,8 +961,6 @@ static struct nullb_page *__null_lookup_page(struct nullb *nullb,
 
 	xa = is_cache ? &nullb->dev->cache : &nullb->dev->data;
 	t_page = xa_load(xa, idx);
-	WARN_ON(t_page && t_page->page->private != idx);
-
 	if (t_page && (for_write || test_bit(sector_bit, t_page->bitmap)))
 		return t_page;
 
@@ -1000,7 +998,6 @@ static struct nullb_page *null_insert_page(struct nullb *nullb,
 	t_page = null_alloc_page();
 	if (!t_page)
 		goto out_lock;
-	t_page->page->private = idx;
 
 	/*
 	 * The store has to happen under nullb->lock, where it cannot sleep.
@@ -1026,7 +1023,6 @@ static struct nullb_page *null_insert_page(struct nullb *nullb,
 	if (cur) {
 		/* Somebody else inserted a page while the lock was dropped. */
 		null_free_page(t_page);
-		WARN_ON(cur->page->private != idx);
 		return cur;
 	}
 	if (!ignore_cache)
@@ -1040,17 +1036,15 @@ static struct nullb_page *null_insert_page(struct nullb *nullb,
 	return null_lookup_page(nullb, sector, true, ignore_cache);
 }
 
-static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page)
+static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page,
+				 unsigned long idx)
 {
 	int i;
 	unsigned int offset;
-	u64 idx;
 	struct nullb_page *t_page;
 	void *dst, *src;
 
-	idx = c_page->page->private;
-
-	t_page = null_insert_page(nullb, idx << PAGE_SECTORS_SHIFT, true);
+	t_page = null_insert_page(nullb, (sector_t)idx << PAGE_SECTORS_SHIFT, true);
 
 	__clear_bit(NULLB_PAGE_LOCK, c_page->bitmap);
 	if (test_bit(NULLB_PAGE_FREE, c_page->bitmap)) {
@@ -1092,7 +1086,8 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
 {
 	int i, err, nr_pages;
 	struct nullb_page *c_pages[FREE_BATCH], *c_page;
-	unsigned long flushed = 0, one_round, idx;
+	unsigned long c_idx[FREE_BATCH], idx;
+	unsigned long flushed = 0, one_round;
 
 again:
 	if ((nullb->dev->cache_size * 1024 * 1024) >
@@ -1102,8 +1097,9 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
 	nr_pages = 0;
 	xa_for_each_start(&nullb->dev->cache, idx, c_page,
 			  nullb->cache_flush_pos) {
-		c_pages[nr_pages++] = c_page;
-		if (nr_pages == FREE_BATCH)
+		c_pages[nr_pages] = c_page;
+		c_idx[nr_pages] = idx;
+		if (++nr_pages == FREE_BATCH)
 			break;
 	}
 	/*
@@ -1111,7 +1107,7 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
 	 * avoid race, we don't allow page free
 	 */
 	for (i = 0; i < nr_pages; i++) {
-		nullb->cache_flush_pos = c_pages[i]->page->private;
+		nullb->cache_flush_pos = c_idx[i];
 		/*
 		 * We found the page which is being flushed to disk by other
 		 * threads
@@ -1126,7 +1122,7 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
 	for (i = 0; i < nr_pages; i++) {
 		if (c_pages[i] == NULL)
 			continue;
-		err = null_flush_cache_page(nullb, c_pages[i]);
+		err = null_flush_cache_page(nullb, c_pages[i], c_idx[i]);
 		if (err)
 			return err;
 		one_round++;
-- 
2.56.1.839.g22a8290db9-goog


      parent reply	other threads:[~2026-11-26 21:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 21:23 [PATCH v2 0/2] null_blk: stop using page->private Nilay Vaish
2026-11-26 21:23 ` [PATCH v2 1/2] null_blk: convert the page stores to XArray Nilay Vaish
2026-11-26 21:23 ` Nilay Vaish [this message]

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=20261126212341.916839-3-nilayvaish@google.com \
    --to=nilayvaish@google.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.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