Skip to content

Commit 7d8d357

Browse files
Matthew Wilcox (Oracle)axboe
authored andcommitted
brd: Remove use of page->index
This debugging check will become more costly in the future when we shrink struct page. It has not proven to be useful, so simply remove it. This lets us use __xa_insert instead of __xa_cmpxchg() as we no longer need to know about the page that is currently stored in the XArray. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Link: https://lore.kernel.org/r/20240315181212.2573753-1-willy@infradead.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 39cd87c commit 7d8d357

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

drivers/block/brd.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929

3030
/*
3131
* Each block ramdisk device has a xarray brd_pages of pages that stores
32-
* the pages containing the block device's contents. A brd page's ->index is
33-
* its offset in PAGE_SIZE units. This is similar to, but in no way connected
34-
* with, the kernel's pagecache or buffer cache (which sit above our block
35-
* device).
32+
* the pages containing the block device's contents.
3633
*/
3734
struct brd_device {
3835
int brd_number;
@@ -51,24 +48,16 @@ struct brd_device {
5148
*/
5249
static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
5350
{
54-
pgoff_t idx;
55-
struct page *page;
56-
57-
idx = sector >> PAGE_SECTORS_SHIFT; /* sector to page index */
58-
page = xa_load(&brd->brd_pages, idx);
59-
60-
BUG_ON(page && page->index != idx);
61-
62-
return page;
51+
return xa_load(&brd->brd_pages, sector >> PAGE_SECTORS_SHIFT);
6352
}
6453

6554
/*
6655
* Insert a new page for a given sector, if one does not already exist.
6756
*/
6857
static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp)
6958
{
70-
pgoff_t idx;
71-
struct page *page, *cur;
59+
pgoff_t idx = sector >> PAGE_SECTORS_SHIFT;
60+
struct page *page;
7261
int ret = 0;
7362

7463
page = brd_lookup_page(brd, sector);
@@ -80,23 +69,16 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp)
8069
return -ENOMEM;
8170

8271
xa_lock(&brd->brd_pages);
83-
84-
idx = sector >> PAGE_SECTORS_SHIFT;
85-
page->index = idx;
86-
87-
cur = __xa_cmpxchg(&brd->brd_pages, idx, NULL, page, gfp);
88-
89-
if (unlikely(cur)) {
90-
__free_page(page);
91-
ret = xa_err(cur);
92-
if (!ret && (cur->index != idx))
93-
ret = -EIO;
94-
} else {
72+
ret = __xa_insert(&brd->brd_pages, idx, page, gfp);
73+
if (!ret)
9574
brd->brd_nr_pages++;
96-
}
97-
9875
xa_unlock(&brd->brd_pages);
9976

77+
if (ret < 0) {
78+
__free_page(page);
79+
if (ret == -EBUSY)
80+
ret = 0;
81+
}
10082
return ret;
10183
}
10284

0 commit comments

Comments
 (0)