From 511fc5e7ec70a47b03d3819bf682da11a8fe01bb Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Sat, 30 Aug 2025 20:43:17 -0400 Subject: [PATCH] node_copy(): try to fix max of nodes Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 53 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6a00380b7d35..75cec454d050 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2936,19 +2936,35 @@ unsigned long node_copy(struct ma_state *mas, struct maple_node *src, memcpy(d_gaps, s_gaps, size * sizeof(unsigned long)); } - d_max = s_max; - if (start + size < mt_pivots[s_mt]) + /* This is wrong.. */ + printk("\t\tAssume s_max..\n"); + printk("\t\tLast src is %u\n", start + size); +#if 0 + d_max = 0; + if (start + size <= mt_pivots[s_mt]) d_max = s_pivots[size - 1]; - if (d_start + size - 1 < mt_pivots[d_mt]) + if (d_max > s_max) + d_max = s_max; +#else + d_max = s_max; + printk("\t\t d_start + size = %u\n", d_start + size); + if (start + size < mt_pivots[s_mt]) { + if (s_max > s_pivots[size - 1]) + d_max = s_pivots[size - 1]; + printk("\t\td_max %lx\n", d_max); + } +#endif + if (d_start + size <= mt_pivots[d_mt]) { + printk("Set final pivot at %u to %lx\n", size + d_start - 1, d_max); d_pivots[size - 1] = d_max; + } - printk("cp from %p -> %p %u\n", d_pivots, s_pivots, size); +// printk("cp from %p -> %p %u\n", d_pivots, s_pivots, size); fflush(stdout); - if (size) { - size--; + size--; + if (size) memcpy(d_pivots, s_pivots, size * sizeof(unsigned long)); - } return d_max; } @@ -3218,10 +3234,9 @@ void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) } printk("%d: size %u\n", __LINE__, size); - cp->dst[d].max = node_copy(mas, src, s_offset, size, - s_max, s_mt, dst, dst_offset, - d_mt); - printk("%d: set dest max %lx\n", __LINE__, cp->dst[d].max); + node_copy(mas, src, s_offset, size, s_max, s_mt, dst, + dst_offset, d_mt); + //printk("%d: set dest max %lx\n", __LINE__, cp->dst[d].max); #if 0 { unsigned long min = cp->min; @@ -3242,8 +3257,10 @@ void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) if (s_offset > src_end) { printk("\t\tnext src %u / %u\n", s +1, cp->s_count); /* This source is exhausted */ + cp->dst[d].max = s_max; s++; if (s >= cp->s_count) { + printk("Forced final\n"); node_finalise(dst, d_mt, dst_offset); return; } @@ -3266,11 +3283,21 @@ void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) split = cp->split; printk("reset split %u\n", split); /* Handle null entries */ - if (s_max != ULONG_MAX && !ma_slots(dst, d_mt)[dst_offset - 1]) { + if (dst_offset <= mt_pivots[d_mt]) { + cp->dst[d].max = ma_pivots(dst, d_mt)[dst_offset - 1]; + printk("%d: set dest max %lx\n", __LINE__, cp->dst[d].max); + printk("===================>slot is %p\n", ma_slots(dst,d_mt)[dst_offset - 1]); + } else { + cp->dst[d].max = s_max; + printk("%d: set dest max %lx\n", __LINE__, cp->dst[d].max); + } + if (cp->dst[d].max != ULONG_MAX && + !ma_slots(dst, d_mt)[dst_offset - 1]) { printk("NULL entry end %u and max %lx\n", dst_offset - 1, cp->dst[d].max); //BUG_ON(1); if (s_offset == cp->src[s].start) { - src = cp->src[--s].node; + s--; + src = cp->src[s].node; src_end = cp->src[s].end; s_max = cp->src[s].max; s_mt = cp->src[s].mt; -- 2.51.0