]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
span_leaf part
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 7 May 2025 15:23:12 +0000 (11:23 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 7 May 2025 15:23:12 +0000 (11:23 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 9482a0e413733018905960382e02181e9a4b9241..7b89feda40ccd3e3682f2f9d5d18e2fbbd3f559e 100644 (file)
@@ -2191,7 +2191,6 @@ static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas)
 
 
        index = mas->index;
-       printk("%s: index %lu\n", __func__, index);
        if (unlikely(ma_is_dense(wr_mas->type))) {
                wr_mas->r_max = wr_mas->r_min = index;
                mas->offset = mas->index = mas->min;
@@ -2199,13 +2198,11 @@ static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas)
        }
 
        wr_mas->node = mas_mn(mas);
-       printk("at node %p\n", wr_mas->node);
        pivs = wr_mas->pivots = ma_pivots(wr_mas->node, wr_mas->type);
        count = mas->end = ma_data_end(wr_mas->node, wr_mas->type,
                                       pivs, mas->max);
        offset = mas->offset;
 
-       printk("start offset is %u\n", offset);
        if (index > pivs[count - 1]) {
                wr_mas->r_max = mas->max;
                wr_mas->offset_end = mas->offset = count;
@@ -2216,7 +2213,6 @@ static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas)
        while (index > pivs[offset])
                offset++;
 
-       printk("end offset is %u\n", offset);
        wr_mas->r_max = pivs[offset];
        wr_mas->r_min = mas_safe_min(mas, pivs, offset);
        wr_mas->offset_end = mas->offset = offset;
@@ -3123,11 +3119,40 @@ void mns_node_part_leaf_init(struct ma_node_part *part,
                part->size++;
        }
 
+       printk("offset end is %u offset is %u\n",
+              wr_mas->offset_end, wr_mas->mas->offset);
        part->skip = wr_mas->offset_end - wr_mas->mas->offset + 1;
        part->leaf = true;
        printk("%s skip %u\n", __func__, part->skip);
 }
 
+static __always_inline
+void mns_node_part_span_leaf_init(struct ma_node_part *part,
+               struct ma_wr_state *wr_l, struct ma_wr_state *wr_r,
+               struct ma_node_info *src)
+{
+       part->pos = 0;
+       part->size = 0;
+       if (wr_l->r_min < wr_l->mas->index) {
+               part->pivots[0] = wr_l->mas->index - 1;
+               part->slots[0] = wr_l->content;
+               part->size++;
+       }
+
+       part->pivots[part->size] = wr_r->mas->last;
+       part->slots[part->size] = wr_l->entry;
+       part->size++;
+
+       if (wr_r->end_piv > wr_r->mas->last) {
+               part->pivots[part->size] = wr_r->end_piv;
+               part->slots[part->size] = src->slots[wr_r->offset_end];
+               part->size++;
+       }
+
+       part->skip = wr_r->offset_end - wr_l->mas->offset + wr_l->mas->end + 1;
+       part->leaf = true;
+       printk("%s skip %u\n", __func__, part->skip);
+}
 static inline
 void mni_node_part_init(struct ma_node_part *part,
                struct ma_node_info *left, struct ma_node_info *right)
@@ -4814,9 +4839,10 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
        unsigned char height;
 
        mas = wr_mas->mas;
-       utrace_ma_op(__func__, mas);
+       trace_ma_op(__func__, mas);
 
        mt_dump(mas->tree, mt_dump_dec);
+       printk("\t\t\t\t%s\n", __func__);
        printk("Storing %lu - %lu -> %p\n", mas->index, mas->last, wr_mas->entry);
 
        if (unlikely(!mas->index && mas->last == ULONG_MAX))
@@ -4847,8 +4873,9 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
        sd.left_store = true;
        sd.insert = mas->offset;
        sd.src_ins_end = wr_mas->offset_end + mas->end + 1;
-       wr_mas->offset_end += mas->end + part.skip + 1;
-       mns_node_part_leaf_init(&part, wr_mas, &right);
+       wr_mas->offset_end = r_wr_mas.offset_end + mas->end + 1;
+       printk("src is %p slots is %p\n", r_src.node, r_src.slots);
+       mns_node_part_span_leaf_init(&part, wr_mas, &r_wr_mas, &r_src);
        do {
                struct ma_node_state *state;
 
@@ -4856,7 +4883,8 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
                        printk("slot %u is %lu -> %p\n", i, part.pivots[i], part.slots[i]);
                printk("skip %u\n", part.skip);
 
-               sd.new_end = r_mas.end + mas->end - part.skip;
+               sd.new_end = r_mas.end + mas->end - part.skip + 1 + part.size;
+               printk("r is %u l is %u part skip is %u\n", r_mas.end, mas->end, part.skip);
                sd.len = 0;
                r_src.offset = r_wr_mas.offset_end + 1;
                printk("new end is %u\n", sd.new_end);
@@ -4867,6 +4895,19 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
                mas->end = parent.end;
                mas_wr_ascend_init(&r_mas, &r_parent);
                r_mas.end = r_parent.end;
+               if (sd.new_end < mt_min_slots[src.type]) {
+                       /* Take in more nodes */
+                       printk("!!! %d min slots not met\n", __LINE__);
+                       if (r_parent.insert_off < r_parent.end)
+                               printk("Looks like there is a right sibling\n");
+                       else if (parent.insert_off) {
+                               printk("Looks like there is a left sibling\n");
+                       } else if (r_parent.max > ULONG_MAX)
+                               printk("Looks like there is a right cousin\n");
+                       else if (parent.min)
+                               printk("Looks like there is a left cousin\n");
+               }
+
                if (sd.new_end < mt_slots[src.type]) {
                        /* Single node at this level */
                        printk("%d\n", __LINE__);
@@ -4876,7 +4917,9 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas)
                        sd.split = mt_slots[src.type];
                        rebalance_reduce(&left, &src, &r_src, &part, &sd);
                        if (ma_is_root(parent.node)) {
-                               sd.new_end = r_parent.offset - parent.offset;
+                               printk("r offset %u p offset %u end %u\n",
+                                      r_parent.offset, parent.offset, parent.end);
+                               sd.new_end = r_parent.insert_off - parent.insert_off;
                                sd.new_end = parent.end - sd.new_end;
                                printk("sd.new_end is %u\n", sd.new_end);
                                /* This is wrong...