From: Liam R. Howlett Date: Wed, 24 Sep 2025 15:36:08 +0000 (-0400) Subject: ascend function cleanups X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c5b6647f60b5f7ce3062fc69621510bc7833adc6;p=users%2Fjedix%2Flinux-maple.git ascend function cleanups Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 125556c70b0d..311fb58d9a5f 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2807,8 +2807,11 @@ static inline void cp_dst_to_slots(struct maple_copy *cp, unsigned long min, cp->max = max; } -static inline void cp_new_root(struct maple_copy *cp, struct ma_state *mas) +static inline bool cp_is_new_root(struct maple_copy *cp, struct ma_state *mas) { + if (cp->min || cp->max != ULONG_MAX) + return false; + if (cp->d_count != 1) { enum maple_type mt = maple_arange_64; @@ -2829,6 +2832,18 @@ static inline void cp_new_root(struct maple_copy *cp, struct ma_state *mas) cp->dst[0].node->parent = ma_parent_ptr(mas_tree_parent(mas)); while (!mte_is_root(mas->node)) mas_ascend(mas); + + return true; +} + +static inline bool cp_converged(struct maple_copy *cp, struct ma_state *mas, + struct ma_state *sib) +{ + if (cp->d_count != 1 || sib->end) + return false; + + cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + return true; } static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, @@ -2843,10 +2858,8 @@ static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, } cp_dst_to_slots(cp, l_wr_mas->mas->min, r_wr_mas->mas->max, mas); - if (!cp->min && cp->max == ULONG_MAX) { - cp_new_root(cp, mas); + if (cp_is_new_root(cp, mas)) return false; - } /* Converged and has a single destination */ if ((cp->d_count == 1) && @@ -2855,15 +2868,9 @@ static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, return false; } - MAS_WR_BUG_ON(l_wr_mas, cp->height > 4); cp->height++; wr_mas_ascend(l_wr_mas); wr_mas_ascend(r_wr_mas); - /* - * cp->slot[0] should go in l_wr_mas->offset - * cp->slot[end] should go in r_wr_mas->offset - */ - return true; } @@ -2899,7 +2906,8 @@ static void mas_wr_spanning_rebalance(struct ma_state *mas, * rebalance_ascend() - Ascend the tree and set up for the next loop - if * necessary * - * Returns: True if there is more rebalancing to do, false otherwise. + * Return: True if there another rebalancing operation on the next level is + * needed, false otherwise. */ static inline bool rebalance_ascend(struct maple_copy *cp, struct ma_wr_state *wr_mas, struct ma_state *sib) @@ -2921,17 +2929,12 @@ static inline bool rebalance_ascend(struct maple_copy *cp, } cp_dst_to_slots(cp, min, r->max, mas); - if (!cp->min && cp->max == ULONG_MAX) { - cp_new_root(cp, mas); + if (cp_is_new_root(cp, mas)) return false; - } - if (cp->d_count == 1 && !sib->end) { - cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + if (cp_converged(cp, mas, sib)) return false; - } - MAS_WR_BUG_ON(wr_mas, cp->height > 4); cp->height++; mas_ascend(mas); wr_mas_setup(wr_mas, mas); @@ -3687,6 +3690,15 @@ static inline void mas_wr_append(struct ma_wr_state *wr_mas, return; } +/* + * split_ascend() - See if a split operation has to keep walking up the tree + * @cp: The maple_copy node + * @wr_mas: The maple write state + * @sib: the maple state of the sibling + * + * Return: true if another split operation on the next level is needed, false + * otherwise + */ static bool split_ascend(struct maple_copy *cp, struct ma_wr_state *wr_mas, struct ma_state *sib) { @@ -3704,15 +3716,11 @@ static bool split_ascend(struct maple_copy *cp, } cp_dst_to_slots(cp, min, max, mas); - if (!cp->min && cp->max == ULONG_MAX) { - cp_new_root(cp, mas); + if (cp_is_new_root(cp, mas)) return false; - } - if (cp->d_count == 1 && !sib->end) { - cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + if (cp_converged(cp, mas, sib)) return false; - } cp->height++; mas_ascend(mas);