maple_tree: use vacant nodes to reduce worst case allocations
In order to determine the store type for a maple tree operation, a walk of the tree is done through mas_wr_walk(). This function descends the tree until a spanning write is detected or we reach a leaf node. While descending, keep track of the height at which we encounter a node with available space. This is done by checking if mas->end is less than the number of slots a given node type can fit. Now that the height of the vacant node is tracked, we can use the difference between the height of the tree and the height of the vacant node to know how many levels we will have to propagate creating new nodes. Update mas_prealloc_calc() to consider the vacant height and reduce the number of worst-case allocations. Rebalancing and spanning stores are not supported and fall back to using the full height of the tree for allocations. Update preallocation testing assertions to take into account vacant height. Link: https://lkml.kernel.org/r/20250410191446.2474640-4-sidhartha.kumar@oracle.com Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Wei Yang <richard.weiyang@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
f9d3a963fe
commit
ad88fc17d2
@@ -3537,6 +3537,9 @@ static bool mas_wr_walk(struct ma_wr_state *wr_mas)
|
||||
if (ma_is_leaf(wr_mas->type))
|
||||
return true;
|
||||
|
||||
if (mas->end < mt_slots[wr_mas->type] - 1)
|
||||
wr_mas->vacant_height = mas->depth + 1;
|
||||
|
||||
mas_wr_walk_traverse(wr_mas);
|
||||
}
|
||||
|
||||
@@ -4152,7 +4155,9 @@ set_content:
|
||||
static inline int mas_prealloc_calc(struct ma_wr_state *wr_mas, void *entry)
|
||||
{
|
||||
struct ma_state *mas = wr_mas->mas;
|
||||
int ret = mas_mt_height(mas) * 3 + 1;
|
||||
unsigned char height = mas_mt_height(mas);
|
||||
int ret = height * 3 + 1;
|
||||
unsigned char delta = height - wr_mas->vacant_height;
|
||||
|
||||
switch (mas->store_type) {
|
||||
case wr_invalid:
|
||||
@@ -4170,13 +4175,13 @@ static inline int mas_prealloc_calc(struct ma_wr_state *wr_mas, void *entry)
|
||||
ret = 0;
|
||||
break;
|
||||
case wr_spanning_store:
|
||||
ret = mas_mt_height(mas) * 3 + 1;
|
||||
WARN_ON_ONCE(ret != height * 3 + 1);
|
||||
break;
|
||||
case wr_split_store:
|
||||
ret = mas_mt_height(mas) * 2 + 1;
|
||||
ret = delta * 2 + 1;
|
||||
break;
|
||||
case wr_rebalance:
|
||||
ret = mas_mt_height(mas) * 2 - 1;
|
||||
ret = height * 2 + 1;
|
||||
break;
|
||||
case wr_node_store:
|
||||
ret = mt_in_rcu(mas->tree) ? 1 : 0;
|
||||
|
||||
Reference in New Issue
Block a user