summaryrefslogtreecommitdiffstats
path: root/mm/shmem.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2017-11-22 08:36:00 -0500
committerMatthew Wilcox <willy@infradead.org>2018-10-21 10:46:39 -0400
commite21a29552fa3f44ea41c53488875015ae70fd7f8 (patch)
tree615c10e662faa49f3910fb269d4be6d029513632 /mm/shmem.c
parenta12831bf4293d38518e41b80dd897af0122bb268 (diff)
shmem: Convert find_swap_entry to XArray
This is a 1:1 conversion. The major part of this patch is converting the test framework from userspace to kernel space and mirroring the algorithm now used in find_swap_entry(). Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index ce91569426f3..a305529d6b89 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1100,34 +1100,27 @@ static void shmem_evict_inode(struct inode *inode)
1100 clear_inode(inode); 1100 clear_inode(inode);
1101} 1101}
1102 1102
1103static unsigned long find_swap_entry(struct radix_tree_root *root, void *item) 1103static unsigned long find_swap_entry(struct xarray *xa, void *item)
1104{ 1104{
1105 struct radix_tree_iter iter; 1105 XA_STATE(xas, xa, 0);
1106 void __rcu **slot;
1107 unsigned long found = -1;
1108 unsigned int checked = 0; 1106 unsigned int checked = 0;
1107 void *entry;
1109 1108
1110 rcu_read_lock(); 1109 rcu_read_lock();
1111 radix_tree_for_each_slot(slot, root, &iter, 0) { 1110 xas_for_each(&xas, entry, ULONG_MAX) {
1112 void *entry = radix_tree_deref_slot(slot); 1111 if (xas_retry(&xas, entry))
1113
1114 if (radix_tree_deref_retry(entry)) {
1115 slot = radix_tree_iter_retry(&iter);
1116 continue; 1112 continue;
1117 } 1113 if (entry == item)
1118 if (entry == item) {
1119 found = iter.index;
1120 break; 1114 break;
1121 }
1122 checked++; 1115 checked++;
1123 if ((checked % 4096) != 0) 1116 if ((checked % XA_CHECK_SCHED) != 0)
1124 continue; 1117 continue;
1125 slot = radix_tree_iter_resume(slot, &iter); 1118 xas_pause(&xas);
1126 cond_resched_rcu(); 1119 cond_resched_rcu();
1127 } 1120 }
1128
1129 rcu_read_unlock(); 1121 rcu_read_unlock();
1130 return found; 1122
1123 return entry ? xas.xa_index : -1;
1131} 1124}
1132 1125
1133/* 1126/*