aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
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 /tools/testing
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 'tools/testing')
-rw-r--r--tools/testing/radix-tree/main.c61
-rw-r--r--tools/testing/radix-tree/test.c22
-rw-r--r--tools/testing/radix-tree/test.h1
3 files changed, 0 insertions, 84 deletions
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index 09deaf4f0959..79589ea570ab 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -236,63 +236,6 @@ void copy_tag_check(void)
236 item_kill_tree(&tree); 236 item_kill_tree(&tree);
237} 237}
238 238
239static void __locate_check(struct radix_tree_root *tree, unsigned long index,
240 unsigned order)
241{
242 struct item *item;
243 unsigned long index2;
244
245 item_insert_order(tree, index, order);
246 item = item_lookup(tree, index);
247 index2 = find_item(tree, item);
248 if (index != index2) {
249 printv(2, "index %ld order %d inserted; found %ld\n",
250 index, order, index2);
251 abort();
252 }
253}
254
255static void __order_0_locate_check(void)
256{
257 RADIX_TREE(tree, GFP_KERNEL);
258 int i;
259
260 for (i = 0; i < 50; i++)
261 __locate_check(&tree, rand() % INT_MAX, 0);
262
263 item_kill_tree(&tree);
264}
265
266static void locate_check(void)
267{
268 RADIX_TREE(tree, GFP_KERNEL);
269 unsigned order;
270 unsigned long offset, index;
271
272 __order_0_locate_check();
273
274 for (order = 0; order < 20; order++) {
275 for (offset = 0; offset < (1 << (order + 3));
276 offset += (1UL << order)) {
277 for (index = 0; index < (1UL << (order + 5));
278 index += (1UL << order)) {
279 __locate_check(&tree, index + offset, order);
280 }
281 if (find_item(&tree, &tree) != -1)
282 abort();
283
284 item_kill_tree(&tree);
285 }
286 }
287
288 if (find_item(&tree, &tree) != -1)
289 abort();
290 __locate_check(&tree, -1, 0);
291 if (find_item(&tree, &tree) != -1)
292 abort();
293 item_kill_tree(&tree);
294}
295
296static void single_thread_tests(bool long_run) 239static void single_thread_tests(bool long_run)
297{ 240{
298 int i; 241 int i;
@@ -303,10 +246,6 @@ static void single_thread_tests(bool long_run)
303 rcu_barrier(); 246 rcu_barrier();
304 printv(2, "after multiorder_check: %d allocated, preempt %d\n", 247 printv(2, "after multiorder_check: %d allocated, preempt %d\n",
305 nr_allocated, preempt_count); 248 nr_allocated, preempt_count);
306 locate_check();
307 rcu_barrier();
308 printv(2, "after locate_check: %d allocated, preempt %d\n",
309 nr_allocated, preempt_count);
310 tag_check(); 249 tag_check();
311 rcu_barrier(); 250 rcu_barrier();
312 printv(2, "after tag_check: %d allocated, preempt %d\n", 251 printv(2, "after tag_check: %d allocated, preempt %d\n",
diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c
index 70ddf964d51c..470419bfd49d 100644
--- a/tools/testing/radix-tree/test.c
+++ b/tools/testing/radix-tree/test.c
@@ -209,28 +209,6 @@ int tag_tagged_items(struct radix_tree_root *root, pthread_mutex_t *lock,
209 return tagged; 209 return tagged;
210} 210}
211 211
212/* Use the same pattern as find_swap_entry() in mm/shmem.c */
213unsigned long find_item(struct radix_tree_root *root, void *item)
214{
215 struct radix_tree_iter iter;
216 void **slot;
217 unsigned long found = -1;
218 unsigned long checked = 0;
219
220 radix_tree_for_each_slot(slot, root, &iter, 0) {
221 if (*slot == item) {
222 found = iter.index;
223 break;
224 }
225 checked++;
226 if ((checked % 4) != 0)
227 continue;
228 slot = radix_tree_iter_resume(slot, &iter);
229 }
230
231 return found;
232}
233
234static int verify_node(struct radix_tree_node *slot, unsigned int tag, 212static int verify_node(struct radix_tree_node *slot, unsigned int tag,
235 int tagged) 213 int tagged)
236{ 214{
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h
index e3dc7a16f09b..9532c18c6cb1 100644
--- a/tools/testing/radix-tree/test.h
+++ b/tools/testing/radix-tree/test.h
@@ -32,7 +32,6 @@ void item_kill_tree(struct radix_tree_root *root);
32int tag_tagged_items(struct radix_tree_root *, pthread_mutex_t *, 32int tag_tagged_items(struct radix_tree_root *, pthread_mutex_t *,
33 unsigned long start, unsigned long end, unsigned batch, 33 unsigned long start, unsigned long end, unsigned batch,
34 unsigned iftag, unsigned thentag); 34 unsigned iftag, unsigned thentag);
35unsigned long find_item(struct radix_tree_root *, void *item);
36 35
37void xarray_tests(void); 36void xarray_tests(void);
38void tag_check(void); 37void tag_check(void);