From: Liam R. Howlett Date: Thu, 21 Aug 2025 20:21:57 +0000 (-0400) Subject: abstract data calc from mas_wr_spanning_rebalance() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b322873f0df82e9b856ddada5b69c1afc336e3ad;p=users%2Fjedix%2Flinux-maple.git abstract data calc from mas_wr_spanning_rebalance() Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index d24b8fb12636..a83d5a5b01d9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2957,6 +2957,48 @@ static void mt_dump_node(const struct maple_tree *mt, void *entry, unsigned long min, unsigned long max, unsigned int depth, enum mt_dump_format format); +static inline void spanning_data_calc(struct maple_copy *cp, + struct ma_state *mas, struct maple_subtree_state *mast, + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas, + struct ma_state *sib) +{ + /* data from left + new entry */ + cp->data = mast->orig_l->offset + 1; + printk("data size is off %u + 1\n", mast->orig_l->offset); + printk("write is now %lx - %lx => %p\n", mas->index, mas->last, l_wr_mas->entry); + /* new entry will overwrite one part of left */ + if (l_wr_mas->r_min == mas->index) { + printk("min doesn't split, subtrack one\n"); + cp->data--; + } else { + printk("min splits start %lx vs %lx\n", l_wr_mas->r_min, mas->index); + } + + printk("%p data + 1 = %u\n", mast->orig_l->node, cp->data); + + /* Data from right (offset to end) + 1 for zero, +1 for splitting */ + cp->data += mast->orig_r->end - mast->orig_r->offset + 2; + printk("end %u - off %u + 1\n", mast->orig_r->end, mast->orig_r->offset); + /* new entry splits the insert location */ + printk("end piv %lx vs last %lx\n", r_wr_mas->r_max, mas->last); + if (r_wr_mas->r_max == mas->last) { + printk("cp->data--\n"); + cp->data--; + } + + printk("%p data = %u\n", mast->orig_r->node, cp->data); + + if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && + (cp->data < mt_min_slots[l_wr_mas->type])) { + mas_spanning_move(mast, sib); + cp->data += sib->end + 1; + printk("%p data = %u\n", sib->node, cp->data); + } else { + sib->end = 0; + } + +} + static void spanning_data_write(struct maple_copy *cp, struct ma_state *mas) { struct maple_node *dst, *src; @@ -3267,42 +3309,9 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, */ mt_dump(mas->tree, mt_dump_hex); - /* data from left + new entry */ - cp.data = mast->orig_l->offset + 1; - printk("data size is off %u + 1\n", mast->orig_l->offset); - printk("write is now %lx - %lx => %p\n", mas->index, mas->last, l_wr_mas->entry); - /* new entry will overwrite one part of left */ - if (l_wr_mas->r_min == mas->index) { - printk("min doesn't split, subtrack one\n"); - cp.data--; - } else { - printk("min splits start %lx vs %lx\n", l_wr_mas->r_min, mas->index); - } - - printk("%p data + 1 = %u\n", mast->orig_l->node, cp.data); - - /* Data from right (offset to end) + 1 for zero, +1 for splitting */ - cp.data += mast->orig_r->end - mast->orig_r->offset + 2; - printk("end %u - off %u + 1\n", mast->orig_r->end, mast->orig_r->offset); - /* new entry splits the insert location */ - printk("end piv %lx vs last %lx\n", r_wr_mas->r_max, mas->last); - if (r_wr_mas->r_max == mas->last) { - printk("cp.data--\n"); - cp.data--; - } - - printk("%p data = %u\n", mast->orig_r->node, cp.data); + spanning_data_calc(&cp, mas, mast, l_wr_mas, r_wr_mas, &sib); mt = l_wr_mas->type; - if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && - (cp.data < mt_min_slots[mt])) { - mas_spanning_move(mast, &sib); - cp.data += sib.end + 1; - printk("%p data = %u\n", sib.node, cp.data); - } else { - sib.end = 0; - } - cp.d_count = 0; /* Calc split here */ if (cp.data < mt_slots[mt]) {