* [patch] radix-tree: fix preload vector size
@ 2012-05-01 10:36 Nick Piggin
0 siblings, 0 replies; only message in thread
From: Nick Piggin @ 2012-05-01 10:36 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
radix-tree: fix preload vector size
Signed-off-by: Nick Piggin <npiggin@kernel.dk>
---
Verified behaviour with rtth.
This was brought to my attention by someone at some point a while
back, but I can't for the life of me work out who, and give proper
credit. Anyway:
Index: linux/lib/radix-tree.c
===================================================================
--- linux.orig/lib/radix-tree.c
+++ linux/lib/radix-tree.c
@@ -73,11 +73,24 @@ static unsigned long height_to_maxindex[
static struct kmem_cache *radix_tree_node_cachep;
/*
+ * The radix tree is variable-height, so an insert operation not only has
+ * to build the branch to its corresponding item, it also has to build the
+ * branch to existing items if the size has to be increased (by
+ * radix_tree_extend).
+ *
+ * The worst case is a zero height tree with just a single item at index 0,
+ * and then inserting an item at index ULONG_MAX. This requires 2 new branches
+ * of RADIX_TREE_MAX_PATH size to be created, with only the root node shared.
+ * Hence:
+ */
+#define RADIX_TREE_PRELOAD_SIZE (RADIX_TREE_MAX_PATH * 2 - 1)
+
+/*
* Per-cpu pool of preloaded nodes
*/
struct radix_tree_preload {
int nr;
- struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
+ struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
};
static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-05-01 10:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-01 10:36 [patch] radix-tree: fix preload vector size Nick Piggin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome