]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
node_copy(): try to fix max of nodes
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Sun, 31 Aug 2025 00:43:17 +0000 (20:43 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Sun, 31 Aug 2025 00:43:54 +0000 (20:43 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 6a00380b7d357b4866fe72f8957546f7d2f2675c..75cec454d050d5e760005c4d6f6ad3933beb7a88 100644 (file)
@@ -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;