mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 11:41:38 -04:00
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/[email protected] Signed-off-by: Matthew Wilcox <[email protected]> Tested-by: Kirill A. Shutemov <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Matthew Wilcox <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
e157b55594
commit
2791653a68
4 changed files with 69 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue