Commit 633769c9 authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton
Browse files

maple_tree: avoid unnecessary ascending

The maple tree node limits are implied by the parent.  When walking up the
tree, the limit may not be known until a slot that does not have implied
limits are encountered.  However, if the node is the left-most or
right-most node, the walking up to find that limit can be skipped.

This commit also fixes the debug/testing code that was not setting the
limit on walking down the tree as that optimization is not compatible with
this change.

Link: https://lkml.kernel.org/r/20230518145544.1722059-4-Liam.Howlett@oracle.com


Signed-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: default avatarPeng Zhang <zhangpeng.00@bytedance.com>
Cc: David Binderman <dcb314@hotmail.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Vernon Yang <vernon2gm@gmail.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent afc754c6
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -1103,7 +1103,6 @@ static int mas_ascend(struct ma_state *mas)
	enum maple_type a_type;
	enum maple_type a_type;
	unsigned long min, max;
	unsigned long min, max;
	unsigned long *pivots;
	unsigned long *pivots;
	unsigned char offset;
	bool set_max = false, set_min = false;
	bool set_max = false, set_min = false;


	a_node = mas_mn(mas);
	a_node = mas_mn(mas);
@@ -1115,8 +1114,9 @@ static int mas_ascend(struct ma_state *mas)
	p_node = mte_parent(mas->node);
	p_node = mte_parent(mas->node);
	if (unlikely(a_node == p_node))
	if (unlikely(a_node == p_node))
		return 1;
		return 1;

	a_type = mas_parent_type(mas, mas->node);
	a_type = mas_parent_type(mas, mas->node);
	offset = mte_parent_slot(mas->node);
	mas->offset = mte_parent_slot(mas->node);
	a_enode = mt_mk_node(p_node, a_type);
	a_enode = mt_mk_node(p_node, a_type);


	/* Check to make sure all parent information is still accurate */
	/* Check to make sure all parent information is still accurate */
@@ -1124,7 +1124,6 @@ static int mas_ascend(struct ma_state *mas)
		return 1;
		return 1;


	mas->node = a_enode;
	mas->node = a_enode;
	mas->offset = offset;


	if (mte_is_root(a_enode)) {
	if (mte_is_root(a_enode)) {
		mas->max = ULONG_MAX;
		mas->max = ULONG_MAX;
@@ -1132,6 +1131,12 @@ static int mas_ascend(struct ma_state *mas)
		return 0;
		return 0;
	}
	}


	if (!mas->min)
		set_min = true;

	if (mas->max == ULONG_MAX)
		set_max = true;

	min = 0;
	min = 0;
	max = ULONG_MAX;
	max = ULONG_MAX;
	do {
	do {
+4 −0
Original line number Original line Diff line number Diff line
@@ -35259,6 +35259,7 @@ static void mas_dfs_preorder(struct ma_state *mas)
	struct maple_enode *prev;
	struct maple_enode *prev;
	unsigned char end, slot = 0;
	unsigned char end, slot = 0;
	unsigned long *pivots;
	if (mas->node == MAS_START) {
	if (mas->node == MAS_START) {
		mas_start(mas);
		mas_start(mas);
@@ -35291,6 +35292,9 @@ static void mas_dfs_preorder(struct ma_state *mas)
		mas_ascend(mas);
		mas_ascend(mas);
		goto walk_up;
		goto walk_up;
	}
	}
	pivots = ma_pivots(mte_to_node(prev), mte_node_type(prev));
	mas->max = mas_safe_pivot(mas, pivots, slot, mte_node_type(prev));
	mas->min = mas_safe_min(mas, pivots, slot);
	return;
	return;
done:
done: