aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <mawilcox@microsoft.com>2017-01-16 16:41:29 -0500
committerMatthew Wilcox <mawilcox@microsoft.com>2017-02-13 21:44:04 -0500
commit1293d5c5f54d5118fbb34fc94e01ba02fcd25fc1 (patch)
treed2ff3550817eb4110766b56e4a2032e8502a0b33
parent73bc029b76482260a144219786d19951f561716e (diff)
radix-tree: Chain preallocated nodes through ->parent
Chaining through the ->private_data member means we have to zero ->private_data after removing preallocated nodes from the list. We're about to initialise ->parent anyway, so we can avoid zeroing it. Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
-rw-r--r--lib/radix-tree.c9
-rw-r--r--tools/testing/radix-tree/linux.c6
2 files changed, 7 insertions, 8 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 14130ab197c0..66c71312c381 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -82,7 +82,7 @@ static struct kmem_cache *radix_tree_node_cachep;
82 */ 82 */
83struct radix_tree_preload { 83struct radix_tree_preload {
84 unsigned nr; 84 unsigned nr;
85 /* nodes->private_data points to next preallocated node */ 85 /* nodes->parent points to next preallocated node */
86 struct radix_tree_node *nodes; 86 struct radix_tree_node *nodes;
87}; 87};
88static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, }; 88static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
@@ -405,8 +405,7 @@ radix_tree_node_alloc(gfp_t gfp_mask, struct radix_tree_node *parent,
405 rtp = this_cpu_ptr(&radix_tree_preloads); 405 rtp = this_cpu_ptr(&radix_tree_preloads);
406 if (rtp->nr) { 406 if (rtp->nr) {
407 ret = rtp->nodes; 407 ret = rtp->nodes;
408 rtp->nodes = ret->private_data; 408 rtp->nodes = ret->parent;
409 ret->private_data = NULL;
410 rtp->nr--; 409 rtp->nr--;
411 } 410 }
412 /* 411 /*
@@ -483,7 +482,7 @@ static int __radix_tree_preload(gfp_t gfp_mask, unsigned nr)
483 preempt_disable(); 482 preempt_disable();
484 rtp = this_cpu_ptr(&radix_tree_preloads); 483 rtp = this_cpu_ptr(&radix_tree_preloads);
485 if (rtp->nr < nr) { 484 if (rtp->nr < nr) {
486 node->private_data = rtp->nodes; 485 node->parent = rtp->nodes;
487 rtp->nodes = node; 486 rtp->nodes = node;
488 rtp->nr++; 487 rtp->nr++;
489 } else { 488 } else {
@@ -2260,7 +2259,7 @@ static int radix_tree_cpu_dead(unsigned int cpu)
2260 rtp = &per_cpu(radix_tree_preloads, cpu); 2259 rtp = &per_cpu(radix_tree_preloads, cpu);
2261 while (rtp->nr) { 2260 while (rtp->nr) {
2262 node = rtp->nodes; 2261 node = rtp->nodes;
2263 rtp->nodes = node->private_data; 2262 rtp->nodes = node->parent;
2264 kmem_cache_free(radix_tree_node_cachep, node); 2263 kmem_cache_free(radix_tree_node_cachep, node);
2265 rtp->nr--; 2264 rtp->nr--;
2266 } 2265 }
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c
index 94bcdb992bbf..cf48c8473f48 100644
--- a/tools/testing/radix-tree/linux.c
+++ b/tools/testing/radix-tree/linux.c
@@ -35,9 +35,9 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
35 if (cachep->nr_objs) { 35 if (cachep->nr_objs) {
36 cachep->nr_objs--; 36 cachep->nr_objs--;
37 node = cachep->objs; 37 node = cachep->objs;
38 cachep->objs = node->private_data; 38 cachep->objs = node->parent;
39 pthread_mutex_unlock(&cachep->lock); 39 pthread_mutex_unlock(&cachep->lock);
40 node->private_data = NULL; 40 node->parent = NULL;
41 } else { 41 } else {
42 pthread_mutex_unlock(&cachep->lock); 42 pthread_mutex_unlock(&cachep->lock);
43 node = malloc(cachep->size); 43 node = malloc(cachep->size);
@@ -64,7 +64,7 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
64 } else { 64 } else {
65 struct radix_tree_node *node = objp; 65 struct radix_tree_node *node = objp;
66 cachep->nr_objs++; 66 cachep->nr_objs++;
67 node->private_data = cachep->objs; 67 node->parent = cachep->objs;
68 cachep->objs = node; 68 cachep->objs = node;
69 } 69 }
70 pthread_mutex_unlock(&cachep->lock); 70 pthread_mutex_unlock(&cachep->lock);