Skip to content

Commit 4249f13

Browse files
sidkumar99akpm00
authored andcommitted
maple_tree: do not preallocate nodes for slot stores
mas_preallocate() defaults to requesting 1 node for preallocation and then ,depending on the type of store, will update the request variable. There isn't a check for a slot store type, so slot stores are preallocating the default 1 node. Slot stores do not require any additional nodes, so add a check for the slot store case that will bypass node_count_gfp(). Update the tests to reflect that slot stores do not require allocations. User visible effects of this bug include increased memory usage from the unneeded node that was allocated. Link: https://lkml.kernel.org/r/[email protected] Fixes: 0b8bb54 ("maple_tree: update mas_preallocate() testing") Signed-off-by: Sidhartha Kumar <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Peng Zhang <[email protected]> Cc: <[email protected]> [6.6+] Signed-off-by: Andrew Morton <[email protected]>
1 parent e2c27b8 commit 4249f13

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/maple_tree.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,6 +5501,17 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
55015501

55025502
mas_wr_end_piv(&wr_mas);
55035503
node_size = mas_wr_new_end(&wr_mas);
5504+
5505+
/* Slot store, does not require additional nodes */
5506+
if (node_size == wr_mas.node_end) {
5507+
/* reuse node */
5508+
if (!mt_in_rcu(mas->tree))
5509+
return 0;
5510+
/* shifting boundary */
5511+
if (wr_mas.offset_end - mas->offset == 1)
5512+
return 0;
5513+
}
5514+
55045515
if (node_size >= mt_slots[wr_mas.type]) {
55055516
/* Split, worst case for now. */
55065517
request = 1 + mas_mt_height(mas) * 2;

tools/testing/radix-tree/maple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35538,7 +35538,7 @@ static noinline void __init check_prealloc(struct maple_tree *mt)
3553835538
MT_BUG_ON(mt, mas_preallocate(&mas, ptr, GFP_KERNEL) != 0);
3553935539
allocated = mas_allocated(&mas);
3554035540
height = mas_mt_height(&mas);
35541-
MT_BUG_ON(mt, allocated != 1);
35541+
MT_BUG_ON(mt, allocated != 0);
3554235542
mas_store_prealloc(&mas, ptr);
3554335543
MT_BUG_ON(mt, mas_allocated(&mas) != 0);
3554435544

0 commit comments

Comments
 (0)