]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Avoid unnecessary ascending
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Mon, 17 Apr 2023 16:10:57 +0000 (12:10 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 2 May 2023 03:00:31 +0000 (23:00 -0400)
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.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c
tools/testing/radix-tree/maple.c

index 9fe25ce9937b81a1ef675353018c84363de235c3..bc848d68f8295df820a51ca5c3003e85f8828cee 100644 (file)
@@ -1101,7 +1101,6 @@ static int mas_ascend(struct ma_state *mas)
        enum maple_type a_type;
        unsigned long min, max;
        unsigned long *pivots;
-       unsigned char offset;
        bool set_max = false, set_min = false;
 
        a_node = mas_mn(mas);
@@ -1114,7 +1113,7 @@ static int mas_ascend(struct ma_state *mas)
        if (unlikely(a_node == p_node))
                return 1;
        a_type = mas_parent_enum(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);
 
        /* Check to make sure all parent information is still accurate */
@@ -1122,7 +1121,6 @@ static int mas_ascend(struct ma_state *mas)
                return 1;
 
        mas->node = a_enode;
-       mas->offset = offset;
 
        if (mte_is_root(a_enode)) {
                mas->max = ULONG_MAX;
@@ -1130,6 +1128,12 @@ static int mas_ascend(struct ma_state *mas)
                return 0;
        }
 
+       if (!mas->min)
+               set_min = true;
+
+       if (mas->max == ULONG_MAX)
+               set_max = true;
+
        min = 0;
        max = ULONG_MAX;
        do {
index 18e319e6ce33547bfcb1af47ce16d18b359f51dd..1049f934caa859ee97950c19877d4fbf371d0ba9 100644 (file)
@@ -35234,6 +35234,7 @@ static void mas_dfs_preorder(struct ma_state *mas)
 
        struct maple_enode *prev;
        unsigned char end, slot = 0;
+       unsigned long *pivots;
 
        if (mas->node == MAS_START) {
                mas_start(mas);
@@ -35266,6 +35267,9 @@ walk_up:
                mas_ascend(mas);
                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;
 done: