Skip to contentSkip to conversation

radix-tree: add radix_tree_split_preload()

PATCH New [email protected] 1 participant 1 message Dec 14, 2016

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 103/114 radix-tree: add radix_tree_split_preload()

From: Matthew Wilcox <[email protected]>
Subject: radix-tree: add radix_tree_split_preload()

Calculate how many nodes we need to allocate to split an old_order entry into multiple entries, each of size new_order. The test suite checks that we allocated exactly the right number of nodes; neither too many (checked by rtp->nr == 0), nor too few (checked by comparing nr_allocated before and after the call to radix_tree_split()).

---

 include/linux/radix-tree.h            |    1 
 lib/radix-tree.c                      |   24 +++++++++++++
 tools/testing/radix-tree/multiorder.c |   42 ++++++++++++++++++++++--
 tools/testing/radix-tree/test.h       |    5 ++
 4 files changed, 69 insertions(+), 3 deletions(-)
include/linux/radix-tree.h renamed from include/linux/radix-tree.h~radix-tree-add-radix_tree_split_preload +1 -0
diff -puN include/linux/radix-tree.h~radix-tree-add-radix_tree_split_preload include/linux/radix-tree.h
@@ -345,6 +345,7 @@ static inline void radix_tree_preload_en
 	preempt_enable();
 }
 
+int radix_tree_split_preload(unsigned old_order, unsigned new_order, gfp_t);
 int radix_tree_split(struct radix_tree_root *, unsigned long index,
 			unsigned new_order);
 int radix_tree_join(struct radix_tree_root *, unsigned long index,
lib/radix-tree.c renamed from lib/radix-tree.c~radix-tree-add-radix_tree_split_preload +23 -1
diff -puN lib/radix-tree.c~radix-tree-add-radix_tree_split_preload lib/radix-tree.c
@@ -368,7 +368,7 @@ radix_tree_node_free(struct radix_tree_n
  * To make use of this facility, the radix tree must be initialised without
  * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE().
  */
-static int __radix_tree_preload(gfp_t gfp_mask, int nr)
+static int __radix_tree_preload(gfp_t gfp_mask, unsigned nr)
 {
 	struct radix_tree_preload *rtp;
 	struct radix_tree_node *node;
@@ -434,6 +434,28 @@ int radix_tree_maybe_preload(gfp_t gfp_m
 }
 EXPORT_SYMBOL(radix_tree_maybe_preload);
 
+#ifdef CONFIG_RADIX_TREE_MULTIORDER
+/*
+ * Preload with enough objects to ensure that we can split a single entry
+ * of order @old_order into many entries of size @new_order
+ */
+int radix_tree_split_preload(unsigned int old_order, unsigned int new_order,
+							gfp_t gfp_mask)
+{
+	unsigned top = 1 << (old_order % RADIX_TREE_MAP_SHIFT);
+	unsigned layers = (old_order / RADIX_TREE_MAP_SHIFT) -
+				(new_order / RADIX_TREE_MAP_SHIFT);
+	unsigned nr = 0;
+
+	WARN_ON_ONCE(!gfpflags_allow_blocking(gfp_mask));
+	BUG_ON(new_order >= old_order);
+
+	while (layers--)
+		nr = nr * RADIX_TREE_MAP_SIZE + 1;
+	return __radix_tree_preload(gfp_mask, top * nr);
+}
+#endif
+
 /*
  * The same as function above, but preload number of nodes required to insert
  * (1 << order) continuous naturally-aligned elements.
tools/testing/radix-tree/multiorder.c renamed from tools/testing/radix-tree/multiorder.c~radix-tree-add-radix_tree_split_preload +40 -2

95 lines not on this page · raw message

tools/testing/radix-tree/test.h renamed from tools/testing/radix-tree/test.h~radix-tree-add-radix_tree_split_preload +5 -0
diff -puN tools/testing/radix-tree/test.h~radix-tree-add-radix_tree_split_preload tools/testing/radix-tree/test.h
@@ -52,3 +52,8 @@ int root_tag_get(struct radix_tree_root
 unsigned long node_maxindex(struct radix_tree_node *);
 unsigned long shift_maxindex(unsigned int shift);
 int radix_tree_cpu_dead(unsigned int cpu);
+struct radix_tree_preload {
+	unsigned nr;
+	struct radix_tree_node *nodes;
+};
+extern struct radix_tree_preload radix_tree_preloads;

_