diff mbox series

[3/4] maple_tree: use the correct min to calculate split

Message ID 20241020024628.22469-4-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series maple_tree: current split may result in deficient node | expand

Commit Message

Wei Yang Oct. 20, 2024, 2:46 a.m. UTC
The check in mab_calc_split() is to make sure the gap between
[0, split] won't be too small. But we don't pass the correct min.

First we may encounter a pivot[split] smaller than min. For example:

       mt_init_flags(mt, 0);
       for (count = 0; count <= 240; count++) {
               mas_set(&mas, count);
               mas_store(&mas, xa_mk_value(count));
       }

On splitting root for storing 240, the pivot[split] is smaller than min.
This result a huge (pivot[split] - min).

Second prev_l_mas.min is not initialized for the first iteration. This
means on splitting leaf node, this value is mostly taking no effect.

Since we are now calculating the split of mas->node, we should use the
mas->min instead of prev_l_mas.min.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 894dc5e9436e..c2d4b188646c 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -3357,7 +3357,7 @@  static void mas_split(struct ma_state *mas, struct maple_big_node *b_node)
 		if (mas_push_data(mas, height, &mast, false))
 			break;
 
-		split = mab_calc_split(mas, b_node, &mid_split, prev_l_mas.min);
+		split = mab_calc_split(mas, b_node, &mid_split, mas->min);
 		mast_split_data(&mast, mas, split);
 		/*
 		 * Usually correct, mab_mas_cp in the above call overwrites