From: Liam R. Howlett Date: Thu, 21 Aug 2025 19:28:39 +0000 (-0400) Subject: runs through X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2921d244d766832f6eefc8e7c62287a1d809f42e;p=users%2Fjedix%2Flinux-maple.git runs through probably an issue with the end slot checking in mas_wr_spanning_rebalance() Probably an issue ith the split calculation for 3 nodes But I'll kick myself later when I didn't take the time to fix them now. Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index d9744f6cf630..d24b8fb12636 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2960,7 +2960,7 @@ static void mt_dump_node(const struct maple_tree *mt, void *entry, static void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) { struct maple_node *dst, *src; - size_t s, d; + unsigned char s, d; unsigned char dst_offset; unsigned char data, data_offset; unsigned char src_end, s_offset; @@ -3011,7 +3011,7 @@ static void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) s_offset += size; if (s_offset > src_end) { - printk("\t\tnext src %d / %d\n", s +1, cp->s_count); + printk("\t\tnext src %u / %u\n", s +1, cp->s_count); /* This source is exhausted */ s++; if (s >= cp->s_count) { @@ -3053,9 +3053,8 @@ static void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) next_node++; split++; printk("inc split %u\n", split); - if (dst_offset >= mt_pivots[d_mt]) - ma_pivots(dst, d_mt)[dst_offset - 1] = 0; data_offset--; + dst_offset--; } node_finalise(dst, d_mt, dst_offset); mt_dump_node(mas->tree, mt_mk_node(dst, d_mt), 0, ULONG_MAX, 1, mt_dump_hex); @@ -3311,7 +3310,7 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, cp.dst[cp.d_count].mt = mt; cp.dst[cp.d_count++].node = ma_mnode_ptr(mas_pop_node(mas)); /* New root */ - } else if (cp.data > mt_slots[mt] * 2) { + } else if (cp.data >= mt_slots[mt] * 2 - 1) { cp.split = cp.data / 3; cp.dst[cp.d_count].mt = mt; cp.dst[cp.d_count++].node = ma_mnode_ptr(mas_pop_node(mas)); @@ -3327,15 +3326,20 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, cp.dst[cp.d_count].mt = mt; cp.dst[cp.d_count++].node = ma_mnode_ptr(mas_pop_node(mas)); } - printk("split = %u data %u\n", cp.split, cp.data); + printk("split = %u data %u d_count %u\n", cp.split, cp.data, cp.d_count); cp.s_count = 0; if (sib.end && sib.max < l_wr_mas->mas->min) append_node_cp(&cp, &sib, 0, sib.end); /* Copy left 0 - offset */ - if (l_wr_mas->mas->offset || l_wr_mas->r_min < mas->index) - append_node_cp(&cp, l_wr_mas->mas, 0, l_wr_mas->mas->offset); + if (l_wr_mas->mas->offset || l_wr_mas->r_min < mas->index) { + unsigned long l_end = l_wr_mas->mas->offset; + + if (l_wr_mas->r_min == mas->index) + l_end--; + append_node_cp(&cp, l_wr_mas->mas, 0, l_end); + } if (cp.s_count) cp.src[cp.s_count - 1].max = mas->index - 1; @@ -3354,9 +3358,14 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, cp.s_count++; /* Copy right either from offset or offset + 1 pending on r_max */ - if (r_wr_mas->mas->end != r_wr_mas->mas->offset || r_wr_mas->r_max > mas->last) - append_node_cp(&cp, r_wr_mas->mas, r_wr_mas->mas->offset, - r_wr_mas->mas->end); + if (r_wr_mas->mas->end != r_wr_mas->mas->offset || r_wr_mas->r_max > mas->last) { + unsigned long r_start = r_wr_mas->mas->offset; + + if (r_wr_mas->r_max == mas->last) + r_start++; + + append_node_cp(&cp, r_wr_mas->mas, r_wr_mas->mas->offset, r_start); + } if (sib.end) { if (sib.min > r_wr_mas->mas->max) {