shmem: Convert shmem_radix_tree_replace to XArray

Rename shmem_radix_tree_replace() to shmem_replace_entry() and
convert it to use the XArray API.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
This commit is contained in:
Matthew Wilcox 2017-11-17 10:22:37 -05:00
parent 10bbd23585
commit 62f945b6a7
1 changed files with 8 additions and 14 deletions

View File

@ -322,24 +322,20 @@ void shmem_uncharge(struct inode *inode, long pages)
} }
/* /*
* Replace item expected in radix tree by a new item, while holding tree lock. * Replace item expected in xarray by a new item, while holding xa_lock.
*/ */
static int shmem_radix_tree_replace(struct address_space *mapping, static int shmem_replace_entry(struct address_space *mapping,
pgoff_t index, void *expected, void *replacement) pgoff_t index, void *expected, void *replacement)
{ {
struct radix_tree_node *node; XA_STATE(xas, &mapping->i_pages, index);
void __rcu **pslot;
void *item; void *item;
VM_BUG_ON(!expected); VM_BUG_ON(!expected);
VM_BUG_ON(!replacement); VM_BUG_ON(!replacement);
item = __radix_tree_lookup(&mapping->i_pages, index, &node, &pslot); item = xas_load(&xas);
if (!item)
return -ENOENT;
if (item != expected) if (item != expected)
return -ENOENT; return -ENOENT;
__radix_tree_replace(&mapping->i_pages, node, pslot, xas_store(&xas, replacement);
replacement, NULL);
return 0; return 0;
} }
@ -624,8 +620,7 @@ static int shmem_add_to_page_cache(struct page *page,
} else if (!expected) { } else if (!expected) {
error = radix_tree_insert(&mapping->i_pages, index, page); error = radix_tree_insert(&mapping->i_pages, index, page);
} else { } else {
error = shmem_radix_tree_replace(mapping, index, expected, error = shmem_replace_entry(mapping, index, expected, page);
page);
} }
if (!error) { if (!error) {
@ -654,7 +649,7 @@ static void shmem_delete_from_page_cache(struct page *page, void *radswap)
VM_BUG_ON_PAGE(PageCompound(page), page); VM_BUG_ON_PAGE(PageCompound(page), page);
xa_lock_irq(&mapping->i_pages); xa_lock_irq(&mapping->i_pages);
error = shmem_radix_tree_replace(mapping, page->index, page, radswap); error = shmem_replace_entry(mapping, page->index, page, radswap);
page->mapping = NULL; page->mapping = NULL;
mapping->nrpages--; mapping->nrpages--;
__dec_node_page_state(page, NR_FILE_PAGES); __dec_node_page_state(page, NR_FILE_PAGES);
@ -1578,8 +1573,7 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp,
* a nice clean interface for us to replace oldpage by newpage there. * a nice clean interface for us to replace oldpage by newpage there.
*/ */
xa_lock_irq(&swap_mapping->i_pages); xa_lock_irq(&swap_mapping->i_pages);
error = shmem_radix_tree_replace(swap_mapping, swap_index, oldpage, error = shmem_replace_entry(swap_mapping, swap_index, oldpage, newpage);
newpage);
if (!error) { if (!error) {
__inc_node_page_state(newpage, NR_FILE_PAGES); __inc_node_page_state(newpage, NR_FILE_PAGES);
__dec_node_page_state(oldpage, NR_FILE_PAGES); __dec_node_page_state(oldpage, NR_FILE_PAGES);