Commit fe2701f1 authored by Andrew Morton's avatar Andrew Morton Committed by Jens Axboe

[PATCH] Use table lookup for radix_tree_maxindex()

Patch from Szabolcs Berecz <szabi@mplayerhq.hu>

With the following patch maxindex is taken from an array instead of
recalculating it all the time.
parent 8042ffff
...@@ -46,6 +46,8 @@ struct radix_tree_path { ...@@ -46,6 +46,8 @@ struct radix_tree_path {
#define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long)) #define RADIX_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
#define RADIX_TREE_MAX_PATH (RADIX_TREE_INDEX_BITS/RADIX_TREE_MAP_SHIFT + 2) #define RADIX_TREE_MAX_PATH (RADIX_TREE_INDEX_BITS/RADIX_TREE_MAP_SHIFT + 2)
static unsigned long height_to_maxindex[RADIX_TREE_MAX_PATH];
/* /*
* Radix tree node cache. * Radix tree node cache.
*/ */
...@@ -126,12 +128,7 @@ int radix_tree_preload(int gfp_mask) ...@@ -126,12 +128,7 @@ int radix_tree_preload(int gfp_mask)
*/ */
static inline unsigned long radix_tree_maxindex(unsigned int height) static inline unsigned long radix_tree_maxindex(unsigned int height)
{ {
unsigned int tmp = height * RADIX_TREE_MAP_SHIFT; return height_to_maxindex[height];
unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
if (tmp >= RADIX_TREE_INDEX_BITS)
index = ~0UL;
return index;
} }
/* /*
...@@ -401,6 +398,24 @@ radix_tree_node_ctor(void *node, kmem_cache_t *cachep, unsigned long flags) ...@@ -401,6 +398,24 @@ radix_tree_node_ctor(void *node, kmem_cache_t *cachep, unsigned long flags)
memset(node, 0, sizeof(struct radix_tree_node)); memset(node, 0, sizeof(struct radix_tree_node));
} }
static __init unsigned long __maxindex(unsigned int height)
{
unsigned int tmp = height * RADIX_TREE_MAP_SHIFT;
unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
if (tmp >= RADIX_TREE_INDEX_BITS)
index = ~0UL;
return index;
}
static __init void radix_tree_init_maxindex(void)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(height_to_maxindex); i++)
height_to_maxindex[i] = __maxindex(i);
}
void __init radix_tree_init(void) void __init radix_tree_init(void)
{ {
radix_tree_node_cachep = kmem_cache_create("radix_tree_node", radix_tree_node_cachep = kmem_cache_create("radix_tree_node",
...@@ -408,4 +423,5 @@ void __init radix_tree_init(void) ...@@ -408,4 +423,5 @@ void __init radix_tree_init(void)
0, radix_tree_node_ctor, NULL); 0, radix_tree_node_ctor, NULL);
if (!radix_tree_node_cachep) if (!radix_tree_node_cachep)
panic ("Failed to create radix_tree_node cache\n"); panic ("Failed to create radix_tree_node cache\n");
radix_tree_init_maxindex();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment