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()). Link: http://lkml.kernel.org/r/1480369871-5271-60-git-send-email-mawilcox@linuxonhyperv.com Signed-off-by: Matthew Wilcox <willy@linux.intel.com> Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
e157b55594
commit
2791653a68
@@ -368,7 +368,7 @@ radix_tree_node_free(struct radix_tree_node *node)
|
||||
* 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_mask)
|
||||
}
|
||||
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.
|
||||
|
Reference in New Issue
Block a user