diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2016-12-14 18:08:49 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-14 19:04:10 -0500 |
commit | 148deab223b23734069abcacb5c7118b0e7deadc (patch) | |
tree | 56aae9c91802e9262312f7fcbb3571eb9c8ec0e9 /tools/testing | |
parent | b35df27a39f40e39fabf1b1e9569c7b24e1add6a (diff) |
radix-tree: improve multiorder iterators
This fixes several interlinked problems with the iterators in the
presence of multiorder entries.
1. radix_tree_iter_next() would only advance by one slot, which would
result in the iterators returning the same entry more than once if
there were sibling entries.
2. radix_tree_next_slot() could return an internal pointer instead of
a user pointer if a tagged multiorder entry was immediately followed by
an entry of lower order.
3. radix_tree_next_slot() expanded to a lot more code than it used to
when multiorder support was compiled in. And I wasn't comfortable with
entry_to_node() being in a header file.
Fixing radix_tree_iter_next() for the presence of sibling entries
necessarily involves examining the contents of the radix tree, so we now
need to pass 'slot' to radix_tree_iter_next(), and we need to change the
calling convention so it is called *before* dropping the lock which
protects the tree. Also rename it to radix_tree_iter_resume(), as some
people thought it was necessary to call radix_tree_iter_next() each time
around the loop.
radix_tree_next_slot() becomes closer to how it looked before multiorder
support was introduced. It only checks to see if the next entry in the
chunk is a sibling entry or a pointer to a node; this should be rare
enough that handling this case out of line is not a performance impact
(and such impact is amortised by the fact that the entry we just
processed was a multiorder entry). Also, radix_tree_next_slot() used to
force a new chunk lookup for untagged entries, which is more expensive
than the out of line sibling entry skipping.
Link: http://lkml.kernel.org/r/1480369871-5271-55-git-send-email-mawilcox@linuxonhyperv.com
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing')
-rw-r--r-- | tools/testing/radix-tree/iteration_check.c | 12 | ||||
-rw-r--r-- | tools/testing/radix-tree/multiorder.c | 28 | ||||
-rw-r--r-- | tools/testing/radix-tree/regression3.c | 8 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.h | 1 |
4 files changed, 30 insertions, 19 deletions
diff --git a/tools/testing/radix-tree/iteration_check.c b/tools/testing/radix-tree/iteration_check.c index df71cb841385..f328a66899b4 100644 --- a/tools/testing/radix-tree/iteration_check.c +++ b/tools/testing/radix-tree/iteration_check.c | |||
@@ -48,8 +48,8 @@ static void *add_entries_fn(void *arg) | |||
48 | /* | 48 | /* |
49 | * Iterate over the tagged entries, doing a radix_tree_iter_retry() as we find | 49 | * Iterate over the tagged entries, doing a radix_tree_iter_retry() as we find |
50 | * things that have been removed and randomly resetting our iteration to the | 50 | * things that have been removed and randomly resetting our iteration to the |
51 | * next chunk with radix_tree_iter_next(). Both radix_tree_iter_retry() and | 51 | * next chunk with radix_tree_iter_resume(). Both radix_tree_iter_retry() and |
52 | * radix_tree_iter_next() cause radix_tree_next_slot() to be called with a | 52 | * radix_tree_iter_resume() cause radix_tree_next_slot() to be called with a |
53 | * NULL 'slot' variable. | 53 | * NULL 'slot' variable. |
54 | */ | 54 | */ |
55 | static void *tagged_iteration_fn(void *arg) | 55 | static void *tagged_iteration_fn(void *arg) |
@@ -79,7 +79,7 @@ static void *tagged_iteration_fn(void *arg) | |||
79 | } | 79 | } |
80 | 80 | ||
81 | if (rand_r(&seeds[0]) % 50 == 0) { | 81 | if (rand_r(&seeds[0]) % 50 == 0) { |
82 | slot = radix_tree_iter_next(&iter); | 82 | slot = radix_tree_iter_resume(slot, &iter); |
83 | rcu_read_unlock(); | 83 | rcu_read_unlock(); |
84 | rcu_barrier(); | 84 | rcu_barrier(); |
85 | rcu_read_lock(); | 85 | rcu_read_lock(); |
@@ -96,8 +96,8 @@ static void *tagged_iteration_fn(void *arg) | |||
96 | /* | 96 | /* |
97 | * Iterate over the entries, doing a radix_tree_iter_retry() as we find things | 97 | * Iterate over the entries, doing a radix_tree_iter_retry() as we find things |
98 | * that have been removed and randomly resetting our iteration to the next | 98 | * that have been removed and randomly resetting our iteration to the next |
99 | * chunk with radix_tree_iter_next(). Both radix_tree_iter_retry() and | 99 | * chunk with radix_tree_iter_resume(). Both radix_tree_iter_retry() and |
100 | * radix_tree_iter_next() cause radix_tree_next_slot() to be called with a | 100 | * radix_tree_iter_resume() cause radix_tree_next_slot() to be called with a |
101 | * NULL 'slot' variable. | 101 | * NULL 'slot' variable. |
102 | */ | 102 | */ |
103 | static void *untagged_iteration_fn(void *arg) | 103 | static void *untagged_iteration_fn(void *arg) |
@@ -127,7 +127,7 @@ static void *untagged_iteration_fn(void *arg) | |||
127 | } | 127 | } |
128 | 128 | ||
129 | if (rand_r(&seeds[1]) % 50 == 0) { | 129 | if (rand_r(&seeds[1]) % 50 == 0) { |
130 | slot = radix_tree_iter_next(&iter); | 130 | slot = radix_tree_iter_resume(slot, &iter); |
131 | rcu_read_unlock(); | 131 | rcu_read_unlock(); |
132 | rcu_barrier(); | 132 | rcu_barrier(); |
133 | rcu_read_lock(); | 133 | rcu_read_lock(); |
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c index 8d5865c95664..b9be8856d652 100644 --- a/tools/testing/radix-tree/multiorder.c +++ b/tools/testing/radix-tree/multiorder.c | |||
@@ -231,11 +231,14 @@ void multiorder_iteration(void) | |||
231 | radix_tree_for_each_slot(slot, &tree, &iter, j) { | 231 | radix_tree_for_each_slot(slot, &tree, &iter, j) { |
232 | int height = order[i] / RADIX_TREE_MAP_SHIFT; | 232 | int height = order[i] / RADIX_TREE_MAP_SHIFT; |
233 | int shift = height * RADIX_TREE_MAP_SHIFT; | 233 | int shift = height * RADIX_TREE_MAP_SHIFT; |
234 | int mask = (1 << order[i]) - 1; | 234 | unsigned long mask = (1UL << order[i]) - 1; |
235 | struct item *item = *slot; | ||
235 | 236 | ||
236 | assert(iter.index >= (index[i] &~ mask)); | 237 | assert((iter.index | mask) == (index[i] | mask)); |
237 | assert(iter.index <= (index[i] | mask)); | ||
238 | assert(iter.shift == shift); | 238 | assert(iter.shift == shift); |
239 | assert(!radix_tree_is_internal_node(item)); | ||
240 | assert((item->index | mask) == (index[i] | mask)); | ||
241 | assert(item->order == order[i]); | ||
239 | i++; | 242 | i++; |
240 | } | 243 | } |
241 | } | 244 | } |
@@ -269,7 +272,7 @@ void multiorder_tagged_iteration(void) | |||
269 | assert(radix_tree_tag_set(&tree, tag_index[i], 1)); | 272 | assert(radix_tree_tag_set(&tree, tag_index[i], 1)); |
270 | 273 | ||
271 | for (j = 0; j < 256; j++) { | 274 | for (j = 0; j < 256; j++) { |
272 | int mask, k; | 275 | int k; |
273 | 276 | ||
274 | for (i = 0; i < TAG_ENTRIES; i++) { | 277 | for (i = 0; i < TAG_ENTRIES; i++) { |
275 | for (k = i; index[k] < tag_index[i]; k++) | 278 | for (k = i; index[k] < tag_index[i]; k++) |
@@ -279,12 +282,16 @@ void multiorder_tagged_iteration(void) | |||
279 | } | 282 | } |
280 | 283 | ||
281 | radix_tree_for_each_tagged(slot, &tree, &iter, j, 1) { | 284 | radix_tree_for_each_tagged(slot, &tree, &iter, j, 1) { |
285 | unsigned long mask; | ||
286 | struct item *item = *slot; | ||
282 | for (k = i; index[k] < tag_index[i]; k++) | 287 | for (k = i; index[k] < tag_index[i]; k++) |
283 | ; | 288 | ; |
284 | mask = (1 << order[k]) - 1; | 289 | mask = (1UL << order[k]) - 1; |
285 | 290 | ||
286 | assert(iter.index >= (tag_index[i] &~ mask)); | 291 | assert((iter.index | mask) == (tag_index[i] | mask)); |
287 | assert(iter.index <= (tag_index[i] | mask)); | 292 | assert(!radix_tree_is_internal_node(item)); |
293 | assert((item->index | mask) == (tag_index[i] | mask)); | ||
294 | assert(item->order == order[k]); | ||
288 | i++; | 295 | i++; |
289 | } | 296 | } |
290 | } | 297 | } |
@@ -303,12 +310,15 @@ void multiorder_tagged_iteration(void) | |||
303 | } | 310 | } |
304 | 311 | ||
305 | radix_tree_for_each_tagged(slot, &tree, &iter, j, 2) { | 312 | radix_tree_for_each_tagged(slot, &tree, &iter, j, 2) { |
313 | struct item *item = *slot; | ||
306 | for (k = i; index[k] < tag_index[i]; k++) | 314 | for (k = i; index[k] < tag_index[i]; k++) |
307 | ; | 315 | ; |
308 | mask = (1 << order[k]) - 1; | 316 | mask = (1 << order[k]) - 1; |
309 | 317 | ||
310 | assert(iter.index >= (tag_index[i] &~ mask)); | 318 | assert((iter.index | mask) == (tag_index[i] | mask)); |
311 | assert(iter.index <= (tag_index[i] | mask)); | 319 | assert(!radix_tree_is_internal_node(item)); |
320 | assert((item->index | mask) == (tag_index[i] | mask)); | ||
321 | assert(item->order == order[k]); | ||
312 | i++; | 322 | i++; |
313 | } | 323 | } |
314 | } | 324 | } |
diff --git a/tools/testing/radix-tree/regression3.c b/tools/testing/radix-tree/regression3.c index 1f06ed73d0a8..b594841fae85 100644 --- a/tools/testing/radix-tree/regression3.c +++ b/tools/testing/radix-tree/regression3.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * In following radix_tree_next_slot current chunk size becomes zero. | 5 | * In following radix_tree_next_slot current chunk size becomes zero. |
6 | * This isn't checked and it tries to dereference null pointer in slot. | 6 | * This isn't checked and it tries to dereference null pointer in slot. |
7 | * | 7 | * |
8 | * Helper radix_tree_iter_next reset slot to NULL and next_index to index + 1, | 8 | * Helper radix_tree_iter_resume reset slot to NULL and next_index to index + 1, |
9 | * for tagger iteraction it also must reset cached tags in iterator to abort | 9 | * for tagger iteraction it also must reset cached tags in iterator to abort |
10 | * next radix_tree_next_slot and go to slow-path into radix_tree_next_chunk. | 10 | * next radix_tree_next_slot and go to slow-path into radix_tree_next_chunk. |
11 | * | 11 | * |
@@ -88,7 +88,7 @@ void regression3_test(void) | |||
88 | printf("slot %ld %p\n", iter.index, *slot); | 88 | printf("slot %ld %p\n", iter.index, *slot); |
89 | if (!iter.index) { | 89 | if (!iter.index) { |
90 | printf("next at %ld\n", iter.index); | 90 | printf("next at %ld\n", iter.index); |
91 | slot = radix_tree_iter_next(&iter); | 91 | slot = radix_tree_iter_resume(slot, &iter); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
@@ -96,7 +96,7 @@ void regression3_test(void) | |||
96 | printf("contig %ld %p\n", iter.index, *slot); | 96 | printf("contig %ld %p\n", iter.index, *slot); |
97 | if (!iter.index) { | 97 | if (!iter.index) { |
98 | printf("next at %ld\n", iter.index); | 98 | printf("next at %ld\n", iter.index); |
99 | slot = radix_tree_iter_next(&iter); | 99 | slot = radix_tree_iter_resume(slot, &iter); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
@@ -106,7 +106,7 @@ void regression3_test(void) | |||
106 | printf("tagged %ld %p\n", iter.index, *slot); | 106 | printf("tagged %ld %p\n", iter.index, *slot); |
107 | if (!iter.index) { | 107 | if (!iter.index) { |
108 | printf("next at %ld\n", iter.index); | 108 | printf("next at %ld\n", iter.index); |
109 | slot = radix_tree_iter_next(&iter); | 109 | slot = radix_tree_iter_resume(slot, &iter); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h index 423c528aaee9..617416ec3c5e 100644 --- a/tools/testing/radix-tree/test.h +++ b/tools/testing/radix-tree/test.h | |||
@@ -41,6 +41,7 @@ void verify_tag_consistency(struct radix_tree_root *root, unsigned int tag); | |||
41 | extern int nr_allocated; | 41 | extern int nr_allocated; |
42 | 42 | ||
43 | /* Normally private parts of lib/radix-tree.c */ | 43 | /* Normally private parts of lib/radix-tree.c */ |
44 | struct radix_tree_node *entry_to_node(void *ptr); | ||
44 | void radix_tree_dump(struct radix_tree_root *root); | 45 | void radix_tree_dump(struct radix_tree_root *root); |
45 | int root_tag_get(struct radix_tree_root *root, unsigned int tag); | 46 | int root_tag_get(struct radix_tree_root *root, unsigned int tag); |
46 | unsigned long node_maxindex(struct radix_tree_node *); | 47 | unsigned long node_maxindex(struct radix_tree_node *); |