Skip to content

Commit f611ff6

Browse files
author
Matthew Wilcox
committed
nilfs2: Convert to XArray
This is close to a 1:1 replacement of radix tree APIs with their XArray equivalents. It would be possible to optimise nilfs_copy_back_pages(), but that doesn't seem to be in the performance path. Also, I think it has a pre-existing bug, and I've added a note to that effect in the source code. Signed-off-by: Matthew Wilcox <willy@infradead.org>
1 parent 04edf02 commit f611ff6

2 files changed

Lines changed: 22 additions & 33 deletions

File tree

‎fs/nilfs2/btnode.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,32 +168,25 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
168168
ctxt->newbh = NULL;
169169

170170
if (inode->i_blkbits == PAGE_SHIFT) {
171-
lock_page(obh->b_page);
172-
/*
173-
* We cannot call radix_tree_preload for the kernels older
174-
* than 2.6.23, because it is not exported for modules.
175-
*/
171+
struct page *opage = obh->b_page;
172+
lock_page(opage);
176173
retry:
177-
err = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM);
178-
if (err)
179-
goto failed_unlock;
180174
/* BUG_ON(oldkey != obh->b_page->index); */
181-
if (unlikely(oldkey != obh->b_page->index))
182-
NILFS_PAGE_BUG(obh->b_page,
175+
if (unlikely(oldkey != opage->index))
176+
NILFS_PAGE_BUG(opage,
183177
"invalid oldkey %lld (newkey=%lld)",
184178
(unsigned long long)oldkey,
185179
(unsigned long long)newkey);
186180

187181
xa_lock_irq(&btnc->i_pages);
188-
err = radix_tree_insert(&btnc->i_pages, newkey, obh->b_page);
182+
err = __xa_insert(&btnc->i_pages, newkey, opage, GFP_NOFS);
189183
xa_unlock_irq(&btnc->i_pages);
190184
/*
191185
* Note: page->index will not change to newkey until
192186
* nilfs_btnode_commit_change_key() will be called.
193187
* To protect the page in intermediate state, the page lock
194188
* is held.
195189
*/
196-
radix_tree_preload_end();
197190
if (!err)
198191
return 0;
199192
else if (err != -EEXIST)
@@ -203,7 +196,7 @@ int nilfs_btnode_prepare_change_key(struct address_space *btnc,
203196
if (!err)
204197
goto retry;
205198
/* fallback to copy mode */
206-
unlock_page(obh->b_page);
199+
unlock_page(opage);
207200
}
208201

209202
nbh = nilfs_btnode_create_block(btnc, newkey);
@@ -243,9 +236,8 @@ void nilfs_btnode_commit_change_key(struct address_space *btnc,
243236
mark_buffer_dirty(obh);
244237

245238
xa_lock_irq(&btnc->i_pages);
246-
radix_tree_delete(&btnc->i_pages, oldkey);
247-
radix_tree_tag_set(&btnc->i_pages, newkey,
248-
PAGECACHE_TAG_DIRTY);
239+
__xa_erase(&btnc->i_pages, oldkey);
240+
__xa_set_mark(&btnc->i_pages, newkey, PAGECACHE_TAG_DIRTY);
249241
xa_unlock_irq(&btnc->i_pages);
250242

251243
opage->index = obh->b_blocknr = newkey;
@@ -275,7 +267,7 @@ void nilfs_btnode_abort_change_key(struct address_space *btnc,
275267

276268
if (nbh == NULL) { /* blocksize == pagesize */
277269
xa_lock_irq(&btnc->i_pages);
278-
radix_tree_delete(&btnc->i_pages, newkey);
270+
__xa_erase(&btnc->i_pages, newkey);
279271
xa_unlock_irq(&btnc->i_pages);
280272
unlock_page(ctxt->bh->b_page);
281273
} else

‎fs/nilfs2/page.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ int nilfs_copy_dirty_pages(struct address_space *dmap,
289289
* @dmap: destination page cache
290290
* @smap: source page cache
291291
*
292-
* No pages must no be added to the cache during this process.
292+
* No pages must be added to the cache during this process.
293293
* This must be ensured by the caller.
294294
*/
295295
void nilfs_copy_back_pages(struct address_space *dmap,
@@ -298,7 +298,6 @@ void nilfs_copy_back_pages(struct address_space *dmap,
298298
struct pagevec pvec;
299299
unsigned int i, n;
300300
pgoff_t index = 0;
301-
int err;
302301

303302
pagevec_init(&pvec);
304303
repeat:
@@ -313,35 +312,34 @@ void nilfs_copy_back_pages(struct address_space *dmap,
313312
lock_page(page);
314313
dpage = find_lock_page(dmap, offset);
315314
if (dpage) {
316-
/* override existing page on the destination cache */
315+
/* overwrite existing page in the destination cache */
317316
WARN_ON(PageDirty(dpage));
318317
nilfs_copy_page(dpage, page, 0);
319318
unlock_page(dpage);
320319
put_page(dpage);
320+
/* Do we not need to remove page from smap here? */
321321
} else {
322-
struct page *page2;
322+
struct page *p;
323323

324324
/* move the page to the destination cache */
325325
xa_lock_irq(&smap->i_pages);
326-
page2 = radix_tree_delete(&smap->i_pages, offset);
327-
WARN_ON(page2 != page);
328-
326+
p = __xa_erase(&smap->i_pages, offset);
327+
WARN_ON(page != p);
329328
smap->nrpages--;
330329
xa_unlock_irq(&smap->i_pages);
331330

332331
xa_lock_irq(&dmap->i_pages);
333-
err = radix_tree_insert(&dmap->i_pages, offset, page);
334-
if (unlikely(err < 0)) {
335-
WARN_ON(err == -EEXIST);
332+
p = __xa_store(&dmap->i_pages, offset, page, GFP_NOFS);
333+
if (unlikely(p)) {
334+
/* Probably -ENOMEM */
336335
page->mapping = NULL;
337-
put_page(page); /* for cache */
336+
put_page(page);
338337
} else {
339338
page->mapping = dmap;
340339
dmap->nrpages++;
341340
if (PageDirty(page))
342-
radix_tree_tag_set(&dmap->i_pages,
343-
offset,
344-
PAGECACHE_TAG_DIRTY);
341+
__xa_set_mark(&dmap->i_pages, offset,
342+
PAGECACHE_TAG_DIRTY);
345343
}
346344
xa_unlock_irq(&dmap->i_pages);
347345
}
@@ -467,8 +465,7 @@ int __nilfs_clear_page_dirty(struct page *page)
467465
if (mapping) {
468466
xa_lock_irq(&mapping->i_pages);
469467
if (test_bit(PG_dirty, &page->flags)) {
470-
radix_tree_tag_clear(&mapping->i_pages,
471-
page_index(page),
468+
__xa_clear_mark(&mapping->i_pages, page_index(page),
472469
PAGECACHE_TAG_DIRTY);
473470
xa_unlock_irq(&mapping->i_pages);
474471
return clear_page_dirty_for_io(page);

0 commit comments

Comments
 (0)