Commit 85b392db authored by Matthew Wilcox's avatar Matthew Wilcox

mm: Convert khugepaged_scan_shmem to XArray

Slightly shorter and easier to read code.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent 77da9389
...@@ -1542,8 +1542,7 @@ static void khugepaged_scan_shmem(struct mm_struct *mm, ...@@ -1542,8 +1542,7 @@ static void khugepaged_scan_shmem(struct mm_struct *mm,
pgoff_t start, struct page **hpage) pgoff_t start, struct page **hpage)
{ {
struct page *page = NULL; struct page *page = NULL;
struct radix_tree_iter iter; XA_STATE(xas, &mapping->i_pages, start);
void **slot;
int present, swap; int present, swap;
int node = NUMA_NO_NODE; int node = NUMA_NO_NODE;
int result = SCAN_SUCCEED; int result = SCAN_SUCCEED;
...@@ -1552,17 +1551,11 @@ static void khugepaged_scan_shmem(struct mm_struct *mm, ...@@ -1552,17 +1551,11 @@ static void khugepaged_scan_shmem(struct mm_struct *mm,
swap = 0; swap = 0;
memset(khugepaged_node_load, 0, sizeof(khugepaged_node_load)); memset(khugepaged_node_load, 0, sizeof(khugepaged_node_load));
rcu_read_lock(); rcu_read_lock();
radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, start) { xas_for_each(&xas, page, start + HPAGE_PMD_NR - 1) {
if (iter.index >= start + HPAGE_PMD_NR) if (xas_retry(&xas, page))
break;
page = radix_tree_deref_slot(slot);
if (radix_tree_deref_retry(page)) {
slot = radix_tree_iter_retry(&iter);
continue; continue;
}
if (radix_tree_exception(page)) { if (xa_is_value(page)) {
if (++swap > khugepaged_max_ptes_swap) { if (++swap > khugepaged_max_ptes_swap) {
result = SCAN_EXCEED_SWAP_PTE; result = SCAN_EXCEED_SWAP_PTE;
break; break;
...@@ -1601,7 +1594,7 @@ static void khugepaged_scan_shmem(struct mm_struct *mm, ...@@ -1601,7 +1594,7 @@ static void khugepaged_scan_shmem(struct mm_struct *mm,
present++; present++;
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