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 Signed-off-by: Nilay Vaish --- 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