multiorder.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * multiorder.c: Multi-order radix tree entry testing
  3. * Copyright (c) 2016 Intel Corporation
  4. * Author: Ross Zwisler <ross.zwisler@linux.intel.com>
  5. * Author: Matthew Wilcox <matthew.r.wilcox@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include <linux/radix-tree.h>
  17. #include <linux/slab.h>
  18. #include <linux/errno.h>
  19. #include <pthread.h>
  20. #include "test.h"
  21. #define for_each_index(i, base, order) \
  22. for (i = base; i < base + (1 << order); i++)
  23. static void __multiorder_tag_test(int index, int order)
  24. {
  25. RADIX_TREE(tree, GFP_KERNEL);
  26. int base, err, i;
  27. /* our canonical entry */
  28. base = index & ~((1 << order) - 1);
  29. printv(2, "Multiorder tag test with index %d, canonical entry %d\n",
  30. index, base);
  31. err = item_insert_order(&tree, index, order);
  32. assert(!err);
  33. /*
  34. * Verify we get collisions for covered indices. We try and fail to
  35. * insert an exceptional entry so we don't leak memory via
  36. * item_insert_order().
  37. */
  38. for_each_index(i, base, order) {
  39. err = __radix_tree_insert(&tree, i, order,
  40. (void *)(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY));
  41. assert(err == -EEXIST);
  42. }
  43. for_each_index(i, base, order) {
  44. assert(!radix_tree_tag_get(&tree, i, 0));
  45. assert(!radix_tree_tag_get(&tree, i, 1));
  46. }
  47. assert(radix_tree_tag_set(&tree, index, 0));
  48. for_each_index(i, base, order) {
  49. assert(radix_tree_tag_get(&tree, i, 0));
  50. assert(!radix_tree_tag_get(&tree, i, 1));
  51. }
  52. assert(tag_tagged_items(&tree, NULL, 0, ~0UL, 10, 0, 1) == 1);
  53. assert(radix_tree_tag_clear(&tree, index, 0));
  54. for_each_index(i, base, order) {
  55. assert(!radix_tree_tag_get(&tree, i, 0));
  56. assert(radix_tree_tag_get(&tree, i, 1));
  57. }
  58. assert(radix_tree_tag_clear(&tree, index, 1));
  59. assert(!radix_tree_tagged(&tree, 0));
  60. assert(!radix_tree_tagged(&tree, 1));
  61. item_kill_tree(&tree);
  62. }
  63. static void __multiorder_tag_test2(unsigned order, unsigned long index2)
  64. {
  65. RADIX_TREE(tree, GFP_KERNEL);
  66. unsigned long index = (1 << order);
  67. index2 += index;
  68. assert(item_insert_order(&tree, 0, order) == 0);
  69. assert(item_insert(&tree, index2) == 0);
  70. assert(radix_tree_tag_set(&tree, 0, 0));
  71. assert(radix_tree_tag_set(&tree, index2, 0));
  72. assert(tag_tagged_items(&tree, NULL, 0, ~0UL, 10, 0, 1) == 2);
  73. item_kill_tree(&tree);
  74. }
  75. static void multiorder_tag_tests(void)
  76. {
  77. int i, j;
  78. /* test multi-order entry for indices 0-7 with no sibling pointers */
  79. __multiorder_tag_test(0, 3);
  80. __multiorder_tag_test(5, 3);
  81. /* test multi-order entry for indices 8-15 with no sibling pointers */
  82. __multiorder_tag_test(8, 3);
  83. __multiorder_tag_test(15, 3);
  84. /*
  85. * Our order 5 entry covers indices 0-31 in a tree with height=2.
  86. * This is broken up as follows:
  87. * 0-7: canonical entry
  88. * 8-15: sibling 1
  89. * 16-23: sibling 2
  90. * 24-31: sibling 3
  91. */
  92. __multiorder_tag_test(0, 5);
  93. __multiorder_tag_test(29, 5);
  94. /* same test, but with indices 32-63 */
  95. __multiorder_tag_test(32, 5);
  96. __multiorder_tag_test(44, 5);
  97. /*
  98. * Our order 8 entry covers indices 0-255 in a tree with height=3.
  99. * This is broken up as follows:
  100. * 0-63: canonical entry
  101. * 64-127: sibling 1
  102. * 128-191: sibling 2
  103. * 192-255: sibling 3
  104. */
  105. __multiorder_tag_test(0, 8);
  106. __multiorder_tag_test(190, 8);
  107. /* same test, but with indices 256-511 */
  108. __multiorder_tag_test(256, 8);
  109. __multiorder_tag_test(300, 8);
  110. __multiorder_tag_test(0x12345678UL, 8);
  111. for (i = 1; i < 10; i++)
  112. for (j = 0; j < (10 << i); j++)
  113. __multiorder_tag_test2(i, j);
  114. }
  115. static void multiorder_check(unsigned long index, int order)
  116. {
  117. unsigned long i;
  118. unsigned long min = index & ~((1UL << order) - 1);
  119. unsigned long max = min + (1UL << order);
  120. void **slot;
  121. struct item *item2 = item_create(min, order);
  122. RADIX_TREE(tree, GFP_KERNEL);
  123. printv(2, "Multiorder index %ld, order %d\n", index, order);
  124. assert(item_insert_order(&tree, index, order) == 0);
  125. for (i = min; i < max; i++) {
  126. struct item *item = item_lookup(&tree, i);
  127. assert(item != 0);
  128. assert(item->index == index);
  129. }
  130. for (i = 0; i < min; i++)
  131. item_check_absent(&tree, i);
  132. for (i = max; i < 2*max; i++)
  133. item_check_absent(&tree, i);
  134. for (i = min; i < max; i++)
  135. assert(radix_tree_insert(&tree, i, item2) == -EEXIST);
  136. slot = radix_tree_lookup_slot(&tree, index);
  137. free(*slot);
  138. radix_tree_replace_slot(&tree, slot, item2);
  139. for (i = min; i < max; i++) {
  140. struct item *item = item_lookup(&tree, i);
  141. assert(item != 0);
  142. assert(item->index == min);
  143. }
  144. assert(item_delete(&tree, min) != 0);
  145. for (i = 0; i < 2*max; i++)
  146. item_check_absent(&tree, i);
  147. }
  148. static void multiorder_shrink(unsigned long index, int order)
  149. {
  150. unsigned long i;
  151. unsigned long max = 1 << order;
  152. RADIX_TREE(tree, GFP_KERNEL);
  153. struct radix_tree_node *node;
  154. printv(2, "Multiorder shrink index %ld, order %d\n", index, order);
  155. assert(item_insert_order(&tree, 0, order) == 0);
  156. node = tree.rnode;
  157. assert(item_insert(&tree, index) == 0);
  158. assert(node != tree.rnode);
  159. assert(item_delete(&tree, index) != 0);
  160. assert(node == tree.rnode);
  161. for (i = 0; i < max; i++) {
  162. struct item *item = item_lookup(&tree, i);
  163. assert(item != 0);
  164. assert(item->index == 0);
  165. }
  166. for (i = max; i < 2*max; i++)
  167. item_check_absent(&tree, i);
  168. if (!item_delete(&tree, 0)) {
  169. printv(2, "failed to delete index %ld (order %d)\n", index, order);
  170. abort();
  171. }
  172. for (i = 0; i < 2*max; i++)
  173. item_check_absent(&tree, i);
  174. }
  175. static void multiorder_insert_bug(void)
  176. {
  177. RADIX_TREE(tree, GFP_KERNEL);
  178. item_insert(&tree, 0);
  179. radix_tree_tag_set(&tree, 0, 0);
  180. item_insert_order(&tree, 3 << 6, 6);
  181. item_kill_tree(&tree);
  182. }
  183. void multiorder_iteration(void)
  184. {
  185. RADIX_TREE(tree, GFP_KERNEL);
  186. struct radix_tree_iter iter;
  187. void **slot;
  188. int i, j, err;
  189. printv(1, "Multiorder iteration test\n");
  190. #define NUM_ENTRIES 11
  191. int index[NUM_ENTRIES] = {0, 2, 4, 8, 16, 32, 34, 36, 64, 72, 128};
  192. int order[NUM_ENTRIES] = {1, 1, 2, 3, 4, 1, 0, 1, 3, 0, 7};
  193. for (i = 0; i < NUM_ENTRIES; i++) {
  194. err = item_insert_order(&tree, index[i], order[i]);
  195. assert(!err);
  196. }
  197. for (j = 0; j < 256; j++) {
  198. for (i = 0; i < NUM_ENTRIES; i++)
  199. if (j <= (index[i] | ((1 << order[i]) - 1)))
  200. break;
  201. radix_tree_for_each_slot(slot, &tree, &iter, j) {
  202. int height = order[i] / RADIX_TREE_MAP_SHIFT;
  203. int shift = height * RADIX_TREE_MAP_SHIFT;
  204. unsigned long mask = (1UL << order[i]) - 1;
  205. struct item *item = *slot;
  206. assert((iter.index | mask) == (index[i] | mask));
  207. assert(iter.shift == shift);
  208. assert(!radix_tree_is_internal_node(item));
  209. assert((item->index | mask) == (index[i] | mask));
  210. assert(item->order == order[i]);
  211. i++;
  212. }
  213. }
  214. item_kill_tree(&tree);
  215. }
  216. void multiorder_tagged_iteration(void)
  217. {
  218. RADIX_TREE(tree, GFP_KERNEL);
  219. struct radix_tree_iter iter;
  220. void **slot;
  221. int i, j;
  222. printv(1, "Multiorder tagged iteration test\n");
  223. #define MT_NUM_ENTRIES 9
  224. int index[MT_NUM_ENTRIES] = {0, 2, 4, 16, 32, 40, 64, 72, 128};
  225. int order[MT_NUM_ENTRIES] = {1, 0, 2, 4, 3, 1, 3, 0, 7};
  226. #define TAG_ENTRIES 7
  227. int tag_index[TAG_ENTRIES] = {0, 4, 16, 40, 64, 72, 128};
  228. for (i = 0; i < MT_NUM_ENTRIES; i++)
  229. assert(!item_insert_order(&tree, index[i], order[i]));
  230. assert(!radix_tree_tagged(&tree, 1));
  231. for (i = 0; i < TAG_ENTRIES; i++)
  232. assert(radix_tree_tag_set(&tree, tag_index[i], 1));
  233. for (j = 0; j < 256; j++) {
  234. int k;
  235. for (i = 0; i < TAG_ENTRIES; i++) {
  236. for (k = i; index[k] < tag_index[i]; k++)
  237. ;
  238. if (j <= (index[k] | ((1 << order[k]) - 1)))
  239. break;
  240. }
  241. radix_tree_for_each_tagged(slot, &tree, &iter, j, 1) {
  242. unsigned long mask;
  243. struct item *item = *slot;
  244. for (k = i; index[k] < tag_index[i]; k++)
  245. ;
  246. mask = (1UL << order[k]) - 1;
  247. assert((iter.index | mask) == (tag_index[i] | mask));
  248. assert(!radix_tree_is_internal_node(item));
  249. assert((item->index | mask) == (tag_index[i] | mask));
  250. assert(item->order == order[k]);
  251. i++;
  252. }
  253. }
  254. assert(tag_tagged_items(&tree, NULL, 0, ~0UL, TAG_ENTRIES, 1, 2) ==
  255. TAG_ENTRIES);
  256. for (j = 0; j < 256; j++) {
  257. int mask, k;
  258. for (i = 0; i < TAG_ENTRIES; i++) {
  259. for (k = i; index[k] < tag_index[i]; k++)
  260. ;
  261. if (j <= (index[k] | ((1 << order[k]) - 1)))
  262. break;
  263. }
  264. radix_tree_for_each_tagged(slot, &tree, &iter, j, 2) {
  265. struct item *item = *slot;
  266. for (k = i; index[k] < tag_index[i]; k++)
  267. ;
  268. mask = (1 << order[k]) - 1;
  269. assert((iter.index | mask) == (tag_index[i] | mask));
  270. assert(!radix_tree_is_internal_node(item));
  271. assert((item->index | mask) == (tag_index[i] | mask));
  272. assert(item->order == order[k]);
  273. i++;
  274. }
  275. }
  276. assert(tag_tagged_items(&tree, NULL, 1, ~0UL, MT_NUM_ENTRIES * 2, 1, 0)
  277. == TAG_ENTRIES);
  278. i = 0;
  279. radix_tree_for_each_tagged(slot, &tree, &iter, 0, 0) {
  280. assert(iter.index == tag_index[i]);
  281. i++;
  282. }
  283. item_kill_tree(&tree);
  284. }
  285. /*
  286. * Basic join checks: make sure we can't find an entry in the tree after
  287. * a larger entry has replaced it
  288. */
  289. static void multiorder_join1(unsigned long index,
  290. unsigned order1, unsigned order2)
  291. {
  292. unsigned long loc;
  293. void *item, *item2 = item_create(index + 1, order1);
  294. RADIX_TREE(tree, GFP_KERNEL);
  295. item_insert_order(&tree, index, order2);
  296. item = radix_tree_lookup(&tree, index);
  297. radix_tree_join(&tree, index + 1, order1, item2);
  298. loc = find_item(&tree, item);
  299. if (loc == -1)
  300. free(item);
  301. item = radix_tree_lookup(&tree, index + 1);
  302. assert(item == item2);
  303. item_kill_tree(&tree);
  304. }
  305. /*
  306. * Check that the accounting of exceptional entries is handled correctly
  307. * by joining an exceptional entry to a normal pointer.
  308. */
  309. static void multiorder_join2(unsigned order1, unsigned order2)
  310. {
  311. RADIX_TREE(tree, GFP_KERNEL);
  312. struct radix_tree_node *node;
  313. void *item1 = item_create(0, order1);
  314. void *item2;
  315. item_insert_order(&tree, 0, order2);
  316. radix_tree_insert(&tree, 1 << order2, (void *)0x12UL);
  317. item2 = __radix_tree_lookup(&tree, 1 << order2, &node, NULL);
  318. assert(item2 == (void *)0x12UL);
  319. assert(node->exceptional == 1);
  320. item2 = radix_tree_lookup(&tree, 0);
  321. free(item2);
  322. radix_tree_join(&tree, 0, order1, item1);
  323. item2 = __radix_tree_lookup(&tree, 1 << order2, &node, NULL);
  324. assert(item2 == item1);
  325. assert(node->exceptional == 0);
  326. item_kill_tree(&tree);
  327. }
  328. /*
  329. * This test revealed an accounting bug for exceptional entries at one point.
  330. * Nodes were being freed back into the pool with an elevated exception count
  331. * by radix_tree_join() and then radix_tree_split() was failing to zero the
  332. * count of exceptional entries.
  333. */
  334. static void multiorder_join3(unsigned int order)
  335. {
  336. RADIX_TREE(tree, GFP_KERNEL);
  337. struct radix_tree_node *node;
  338. void **slot;
  339. struct radix_tree_iter iter;
  340. unsigned long i;
  341. for (i = 0; i < (1 << order); i++) {
  342. radix_tree_insert(&tree, i, (void *)0x12UL);
  343. }
  344. radix_tree_join(&tree, 0, order, (void *)0x16UL);
  345. rcu_barrier();
  346. radix_tree_split(&tree, 0, 0);
  347. radix_tree_for_each_slot(slot, &tree, &iter, 0) {
  348. radix_tree_iter_replace(&tree, &iter, slot, (void *)0x12UL);
  349. }
  350. __radix_tree_lookup(&tree, 0, &node, NULL);
  351. assert(node->exceptional == node->count);
  352. item_kill_tree(&tree);
  353. }
  354. static void multiorder_join(void)
  355. {
  356. int i, j, idx;
  357. for (idx = 0; idx < 1024; idx = idx * 2 + 3) {
  358. for (i = 1; i < 15; i++) {
  359. for (j = 0; j < i; j++) {
  360. multiorder_join1(idx, i, j);
  361. }
  362. }
  363. }
  364. for (i = 1; i < 15; i++) {
  365. for (j = 0; j < i; j++) {
  366. multiorder_join2(i, j);
  367. }
  368. }
  369. for (i = 3; i < 10; i++) {
  370. multiorder_join3(i);
  371. }
  372. }
  373. static void check_mem(unsigned old_order, unsigned new_order, unsigned alloc)
  374. {
  375. struct radix_tree_preload *rtp = &radix_tree_preloads;
  376. if (rtp->nr != 0)
  377. printv(2, "split(%u %u) remaining %u\n", old_order, new_order,
  378. rtp->nr);
  379. /*
  380. * Can't check for equality here as some nodes may have been
  381. * RCU-freed while we ran. But we should never finish with more
  382. * nodes allocated since they should have all been preloaded.
  383. */
  384. if (nr_allocated > alloc)
  385. printv(2, "split(%u %u) allocated %u %u\n", old_order, new_order,
  386. alloc, nr_allocated);
  387. }
  388. static void __multiorder_split(int old_order, int new_order)
  389. {
  390. RADIX_TREE(tree, GFP_ATOMIC);
  391. void **slot;
  392. struct radix_tree_iter iter;
  393. unsigned alloc;
  394. struct item *item;
  395. radix_tree_preload(GFP_KERNEL);
  396. assert(item_insert_order(&tree, 0, old_order) == 0);
  397. radix_tree_preload_end();
  398. /* Wipe out the preloaded cache or it'll confuse check_mem() */
  399. radix_tree_cpu_dead(0);
  400. item = radix_tree_tag_set(&tree, 0, 2);
  401. radix_tree_split_preload(old_order, new_order, GFP_KERNEL);
  402. alloc = nr_allocated;
  403. radix_tree_split(&tree, 0, new_order);
  404. check_mem(old_order, new_order, alloc);
  405. radix_tree_for_each_slot(slot, &tree, &iter, 0) {
  406. radix_tree_iter_replace(&tree, &iter, slot,
  407. item_create(iter.index, new_order));
  408. }
  409. radix_tree_preload_end();
  410. item_kill_tree(&tree);
  411. free(item);
  412. }
  413. static void __multiorder_split2(int old_order, int new_order)
  414. {
  415. RADIX_TREE(tree, GFP_KERNEL);
  416. void **slot;
  417. struct radix_tree_iter iter;
  418. struct radix_tree_node *node;
  419. void *item;
  420. __radix_tree_insert(&tree, 0, old_order, (void *)0x12);
  421. item = __radix_tree_lookup(&tree, 0, &node, NULL);
  422. assert(item == (void *)0x12);
  423. assert(node->exceptional > 0);
  424. radix_tree_split(&tree, 0, new_order);
  425. radix_tree_for_each_slot(slot, &tree, &iter, 0) {
  426. radix_tree_iter_replace(&tree, &iter, slot,
  427. item_create(iter.index, new_order));
  428. }
  429. item = __radix_tree_lookup(&tree, 0, &node, NULL);
  430. assert(item != (void *)0x12);
  431. assert(node->exceptional == 0);
  432. item_kill_tree(&tree);
  433. }
  434. static void __multiorder_split3(int old_order, int new_order)
  435. {
  436. RADIX_TREE(tree, GFP_KERNEL);
  437. void **slot;
  438. struct radix_tree_iter iter;
  439. struct radix_tree_node *node;
  440. void *item;
  441. __radix_tree_insert(&tree, 0, old_order, (void *)0x12);
  442. item = __radix_tree_lookup(&tree, 0, &node, NULL);
  443. assert(item == (void *)0x12);
  444. assert(node->exceptional > 0);
  445. radix_tree_split(&tree, 0, new_order);
  446. radix_tree_for_each_slot(slot, &tree, &iter, 0) {
  447. radix_tree_iter_replace(&tree, &iter, slot, (void *)0x16);
  448. }
  449. item = __radix_tree_lookup(&tree, 0, &node, NULL);
  450. assert(item == (void *)0x16);
  451. assert(node->exceptional > 0);
  452. item_kill_tree(&tree);
  453. __radix_tree_insert(&tree, 0, old_order, (void *)0x12);
  454. item = __radix_tree_lookup(&tree, 0, &node, NULL);
  455. assert(item == (void *)0x12);
  456. assert(node->exceptional > 0);
  457. radix_tree_split(&tree, 0, new_order);
  458. radix_tree_for_each_slot(slot, &tree, &iter, 0) {
  459. if (iter.index == (1 << new_order))
  460. radix_tree_iter_replace(&tree, &iter, slot,
  461. (void *)0x16);
  462. else
  463. radix_tree_iter_replace(&tree, &iter, slot, NULL);
  464. }
  465. item = __radix_tree_lookup(&tree, 1 << new_order, &node, NULL);
  466. assert(item == (void *)0x16);
  467. assert(node->count == node->exceptional);
  468. do {
  469. node = node->parent;
  470. if (!node)
  471. break;
  472. assert(node->count == 1);
  473. assert(node->exceptional == 0);
  474. } while (1);
  475. item_kill_tree(&tree);
  476. }
  477. static void multiorder_split(void)
  478. {
  479. int i, j;
  480. for (i = 3; i < 11; i++)
  481. for (j = 0; j < i; j++) {
  482. __multiorder_split(i, j);
  483. __multiorder_split2(i, j);
  484. __multiorder_split3(i, j);
  485. }
  486. }
  487. static void multiorder_account(void)
  488. {
  489. RADIX_TREE(tree, GFP_KERNEL);
  490. struct radix_tree_node *node;
  491. void **slot;
  492. item_insert_order(&tree, 0, 5);
  493. __radix_tree_insert(&tree, 1 << 5, 5, (void *)0x12);
  494. __radix_tree_lookup(&tree, 0, &node, NULL);
  495. assert(node->count == node->exceptional * 2);
  496. radix_tree_delete(&tree, 1 << 5);
  497. assert(node->exceptional == 0);
  498. __radix_tree_insert(&tree, 1 << 5, 5, (void *)0x12);
  499. __radix_tree_lookup(&tree, 1 << 5, &node, &slot);
  500. assert(node->count == node->exceptional * 2);
  501. __radix_tree_replace(&tree, node, slot, NULL, NULL);
  502. assert(node->exceptional == 0);
  503. item_kill_tree(&tree);
  504. }
  505. bool stop_iteration = false;
  506. static void *creator_func(void *ptr)
  507. {
  508. /* 'order' is set up to ensure we have sibling entries */
  509. unsigned int order = RADIX_TREE_MAP_SHIFT - 1;
  510. struct radix_tree_root *tree = ptr;
  511. int i;
  512. for (i = 0; i < 10000; i++) {
  513. item_insert_order(tree, 0, order);
  514. item_delete_rcu(tree, 0);
  515. }
  516. stop_iteration = true;
  517. return NULL;
  518. }
  519. static void *iterator_func(void *ptr)
  520. {
  521. struct radix_tree_root *tree = ptr;
  522. struct radix_tree_iter iter;
  523. struct item *item;
  524. void **slot;
  525. while (!stop_iteration) {
  526. rcu_read_lock();
  527. radix_tree_for_each_slot(slot, tree, &iter, 0) {
  528. item = radix_tree_deref_slot(slot);
  529. if (!item)
  530. continue;
  531. if (radix_tree_deref_retry(item)) {
  532. slot = radix_tree_iter_retry(&iter);
  533. continue;
  534. }
  535. item_sanity(item, iter.index);
  536. }
  537. rcu_read_unlock();
  538. }
  539. return NULL;
  540. }
  541. static void multiorder_iteration_race(void)
  542. {
  543. const int num_threads = sysconf(_SC_NPROCESSORS_ONLN);
  544. pthread_t worker_thread[num_threads];
  545. RADIX_TREE(tree, GFP_KERNEL);
  546. int i;
  547. pthread_create(&worker_thread[0], NULL, &creator_func, &tree);
  548. for (i = 1; i < num_threads; i++)
  549. pthread_create(&worker_thread[i], NULL, &iterator_func, &tree);
  550. for (i = 0; i < num_threads; i++)
  551. pthread_join(worker_thread[i], NULL);
  552. item_kill_tree(&tree);
  553. }
  554. void multiorder_checks(void)
  555. {
  556. int i;
  557. for (i = 0; i < 20; i++) {
  558. multiorder_check(200, i);
  559. multiorder_check(0, i);
  560. multiorder_check((1UL << i) + 1, i);
  561. }
  562. for (i = 0; i < 15; i++)
  563. multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i);
  564. multiorder_insert_bug();
  565. multiorder_tag_tests();
  566. multiorder_iteration();
  567. multiorder_tagged_iteration();
  568. multiorder_join();
  569. multiorder_split();
  570. multiorder_account();
  571. multiorder_iteration_race();
  572. radix_tree_cpu_dead(0);
  573. }
  574. int __weak main(void)
  575. {
  576. radix_tree_init();
  577. multiorder_checks();
  578. return 0;
  579. }