]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: break on convergence in mas_spanning_rebalance()
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Thu, 27 Feb 2025 20:48:21 +0000 (20:48 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 4 Mar 2025 05:50:38 +0000 (21:50 -0800)
This allows support for using the vacant height to calculate the worst
case number of nodes needed for wr_rebalance operation.
mas_spanning_rebalance() was seen to perform unnecessary node allocations.
We can reduce allocations by breaking early during the rebalancing loop
once we realize that we have ascended to a common ancestor.

Link: https://lkml.kernel.org/r/20250227204823.758784-5-sidhartha.kumar@oracle.com
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Suggested-by: Liam Howlett <liam.howlett@oracle.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/maple_tree.c

index 6a59f2d15769877812879020713cc77442decdca..8cea953a0cb5672cfee16eebb99f524465734875 100644 (file)
@@ -2895,11 +2895,24 @@ static void mas_spanning_rebalance(struct ma_state *mas,
                mast_combine_cp_right(mast);
                mast->orig_l->last = mast->orig_l->max;
 
-               if (mast_sufficient(mast))
-                       continue;
+               if (mast_sufficient(mast)) {
+                       if (mast_overflow(mast))
+                               continue;
+
+                       if (mast->orig_l->node == mast->orig_r->node) {
+                              /*
+                               * The data in b_node should be stored in one
+                               * node and in the tree
+                               */
+                               slot = mast->l->offset;
+                               /* May be a new root stored in mast->bn */
+                               if (mas_is_root_limits(mast->orig_l))
+                                       new_height++;
+                               break;
+                       }
 
-               if (mast_overflow(mast))
                        continue;
+               }
 
                /* May be a new root stored in mast->bn */
                if (mas_is_root_limits(mast->orig_l)) {