[patch 2/5] radix tree: use prealloc

From: Nick Piggin
Date: Sat Oct 29 2005 - 19:48:16 EST


2/5

--
SUSE Labs, Novell Inc.

Prefer radix_tree_preloads to kmem_cache_alloc. If we've allocated them,
why not use them? They're also faster because they needn't turn off
interrupts, so using them in radix tree critical sections is a good idea.

Signed-off-by: Nick Piggin <npiggin@xxxxxxx>

Index: linux-2.6/lib/radix-tree.c
===================================================================
--- linux-2.6.orig/lib/radix-tree.c
+++ linux-2.6/lib/radix-tree.c
@@ -82,20 +82,18 @@ DEFINE_PER_CPU(struct radix_tree_preload
static struct radix_tree_node *
radix_tree_node_alloc(struct radix_tree_root *root)
{
- struct radix_tree_node *ret;
-
- ret = kmem_cache_alloc(radix_tree_node_cachep, root->gfp_mask);
- if (ret == NULL && !(root->gfp_mask & __GFP_WAIT)) {
- struct radix_tree_preload *rtp;
+ struct radix_tree_preload *rtp;

- rtp = &__get_cpu_var(radix_tree_preloads);
- if (rtp->nr) {
- ret = rtp->nodes[rtp->nr - 1];
- rtp->nodes[rtp->nr - 1] = NULL;
- rtp->nr--;
- }
+ rtp = &__get_cpu_var(radix_tree_preloads);
+ if (rtp->nr) {
+ struct radix_tree_node *ret;
+ ret = rtp->nodes[rtp->nr - 1];
+ rtp->nodes[rtp->nr - 1] = NULL;
+ rtp->nr--;
+ return ret;
}
- return ret;
+
+ return kmem_cache_alloc(radix_tree_node_cachep, root->gfp_mask);
}

static inline void