]> 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>
Mon, 7 Apr 2025 18:41:00 +0000 (18:41 +0000)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 8 Apr 2025 20:01:43 +0000 (16:01 -0400)
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.

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: Sidhartha Kumar <sidhartha.kumar@oracle.com>
lib/maple_tree.c

index 066edcab96d76f4d1c1cb266b928453f932f86c3..0cacb8f07550d226d184e1dd6af1d374520dfc8e 100644 (file)
@@ -2899,11 +2899,21 @@ 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;
+                               break;
+                       }
 
-               if (mast_overflow(mast))
                        continue;
+               }
 
                /* May be a new root stored in mast->bn */
                if (mas_is_root_limits(mast->orig_l))