Commit 7ae3424f authored by Matthew Wilcox's avatar Matthew Wilcox

shmem: Convert shmem_partial_swap_usage to XArray

Simpler code because the xarray takes care of things like the limit and
dereferencing the slot.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent c121d3bb
...@@ -676,29 +676,19 @@ static int shmem_free_swap(struct address_space *mapping, ...@@ -676,29 +676,19 @@ static int shmem_free_swap(struct address_space *mapping,
unsigned long shmem_partial_swap_usage(struct address_space *mapping, unsigned long shmem_partial_swap_usage(struct address_space *mapping,
pgoff_t start, pgoff_t end) pgoff_t start, pgoff_t end)
{ {
struct radix_tree_iter iter; XA_STATE(xas, &mapping->i_pages, start);
void __rcu **slot;
struct page *page; struct page *page;
unsigned long swapped = 0; unsigned long swapped = 0;
rcu_read_lock(); rcu_read_lock();
xas_for_each(&xas, page, end - 1) {
radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, start) { if (xas_retry(&xas, page))
if (iter.index >= end)
break;
page = radix_tree_deref_slot(slot);
if (radix_tree_deref_retry(page)) {
slot = radix_tree_iter_retry(&iter);
continue; continue;
}
if (xa_is_value(page)) if (xa_is_value(page))
swapped++; swapped++;
if (need_resched()) { if (need_resched()) {
slot = radix_tree_iter_resume(slot, &iter); xas_pause(&xas);
cond_resched_rcu(); cond_resched_rcu();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment