Skip to content

Commit 19fc795

Browse files
RichardWeiYanggregkh
authored andcommitted
maple_tree: simplify split calculation
commit 4f6a6be upstream. Patch series "simplify split calculation", v3. This patch (of 3): The current calculation for splitting nodes tries to enforce a minimum span on the leaf nodes. This code is complex and never worked correctly to begin with, due to the min value being passed as 0 for all leaves. The calculation should just split the data as equally as possible between the new nodes. Note that b_end will be one more than the data, so the left side is still favoured in the calculation. The current code may also lead to a deficient node by not leaving enough data for the right side of the split. This issue is also addressed with the split calculation change. [Liam.Howlett@Oracle.com: rephrase the change log] Link: https://lkml.kernel.org/r/20241113031616.10530-1-richard.weiyang@gmail.com Link: https://lkml.kernel.org/r/20241113031616.10530-2-richard.weiyang@gmail.com Fixes: 54a611b ("Maple Tree: add new data structure") Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aab2bc4 commit 19fc795

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

lib/maple_tree.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,11 +1849,11 @@ static inline int mab_no_null_split(struct maple_big_node *b_node,
18491849
* Return: The first split location. The middle split is set in @mid_split.
18501850
*/
18511851
static inline int mab_calc_split(struct ma_state *mas,
1852-
struct maple_big_node *bn, unsigned char *mid_split, unsigned long min)
1852+
struct maple_big_node *bn, unsigned char *mid_split)
18531853
{
18541854
unsigned char b_end = bn->b_end;
18551855
int split = b_end / 2; /* Assume equal split. */
1856-
unsigned char slot_min, slot_count = mt_slots[bn->type];
1856+
unsigned char slot_count = mt_slots[bn->type];
18571857

18581858
/*
18591859
* To support gap tracking, all NULL entries are kept together and a node cannot
@@ -1886,18 +1886,7 @@ static inline int mab_calc_split(struct ma_state *mas,
18861886
split = b_end / 3;
18871887
*mid_split = split * 2;
18881888
} else {
1889-
slot_min = mt_min_slots[bn->type];
1890-
18911889
*mid_split = 0;
1892-
/*
1893-
* Avoid having a range less than the slot count unless it
1894-
* causes one node to be deficient.
1895-
* NOTE: mt_min_slots is 1 based, b_end and split are zero.
1896-
*/
1897-
while ((split < slot_count - 1) &&
1898-
((bn->pivot[split] - min) < slot_count - 1) &&
1899-
(b_end - split > slot_min))
1900-
split++;
19011890
}
19021891

19031892
/* Avoid ending a node on a NULL entry */
@@ -2366,7 +2355,7 @@ static inline struct maple_enode
23662355
static inline unsigned char mas_mab_to_node(struct ma_state *mas,
23672356
struct maple_big_node *b_node, struct maple_enode **left,
23682357
struct maple_enode **right, struct maple_enode **middle,
2369-
unsigned char *mid_split, unsigned long min)
2358+
unsigned char *mid_split)
23702359
{
23712360
unsigned char split = 0;
23722361
unsigned char slot_count = mt_slots[b_node->type];
@@ -2379,7 +2368,7 @@ static inline unsigned char mas_mab_to_node(struct ma_state *mas,
23792368
if (b_node->b_end < slot_count) {
23802369
split = b_node->b_end;
23812370
} else {
2382-
split = mab_calc_split(mas, b_node, mid_split, min);
2371+
split = mab_calc_split(mas, b_node, mid_split);
23832372
*right = mas_new_ma_node(mas, b_node);
23842373
}
23852374

@@ -2866,7 +2855,7 @@ static void mas_spanning_rebalance(struct ma_state *mas,
28662855
mast->bn->b_end--;
28672856
mast->bn->type = mte_node_type(mast->orig_l->node);
28682857
split = mas_mab_to_node(mas, mast->bn, &left, &right, &middle,
2869-
&mid_split, mast->orig_l->min);
2858+
&mid_split);
28702859
mast_set_split_parents(mast, left, middle, right, split,
28712860
mid_split);
28722861
mast_cp_to_nodes(mast, left, middle, right, split, mid_split);
@@ -3357,7 +3346,7 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node)
33573346
if (mas_push_data(mas, height, &mast, false))
33583347
break;
33593348

3360-
split = mab_calc_split(mas, b_node, &mid_split, prev_l_mas.min);
3349+
split = mab_calc_split(mas, b_node, &mid_split);
33613350
mast_split_data(&mast, mas, split);
33623351
/*
33633352
* Usually correct, mab_mas_cp in the above call overwrites

0 commit comments

Comments
 (0)