> this on one of my 64bit test systems successfully for about a day,
> now. The one code path I was concerned about was
> radix_tree_node_alloc, since the prealloc array changes size with this
> patch. I stepped through the code by hand and it looks right to me.
> Additionally, I wrote a kprobe that would simulate the
> kmem_cache_alloc failure. I then inserted a node at max height into
> an empty tree with preemption disabled. I verified, using the crash
> utility, that the tree was constructed and filled in properly.
>
> You can find the kprobe at
http://people.redhat.com/jmoyer/radix-tree/.
>
> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
>
> diff --git a/lib/radix-tree.c b/lib/radix-tree.c
> index 514efb2..d2655cb 100644
> --- a/lib/radix-tree.c
> +++ b/lib/radix-tree.c
> @@ -60,9 +60,14 @@ struct radix_tree_path {
> };
>
> #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 (DIV_ROUND_UP(RADIX_TREE_INDEX_BITS, \
> + RADIX_TREE_MAP_SHIFT))
>
> -static unsigned long height_to_maxindex[RADIX_TREE_MAX_PATH] __read_mostly;
> +/*
> + * The height_to_maxindex array needs to be one deeper than the maximum
> + * path as height 0 holds only 1 entry.
> + */
> +static unsigned long height_to_maxindex[RADIX_TREE_MAX_PATH + 1] __read_mostly;
>
> /*
> * Radix tree node cache.
> @@ -487,7 +492,11 @@ EXPORT_SYMBOL(radix_tree_tag_set);
> void *radix_tree_tag_clear(struct radix_tree_root *root,
> unsigned long index, unsigned int tag)
> {
> - struct radix_tree_path path[RADIX_TREE_MAX_PATH], *pathp = path;
> + /*
> + * The radix tree path needs to be one longer than the maximum path
> + * since the "list" is null terminated.
> + */
> + struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
> struct radix_tree_node *slot = NULL;
> unsigned int height, shift;
>
> @@ -882,7 +891,11 @@ static inline void radix_tree_shrink(struct radix_tree_root *root)
> */
> void *radix_tree_delete(struct radix_tree_root *root, unsigned long index)
> {
> - struct radix_tree_path path[RADIX_TREE_MAX_PATH], *pathp = path;
> + /*
> + * The radix tree path needs to be one longer than the maximum path
> + * since the "list" is null terminated.
> + */
> + struct radix_tree_path path[RADIX_TREE_MAX_PATH + 1], *pathp = path;
> struct radix_tree_node *slot = NULL;
> struct radix_tree_node *to_free;
> unsigned int height, shift;