From: Liam R. Howlett Date: Tue, 8 Apr 2025 01:49:42 +0000 (-0400) Subject: working new code X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=73db38a79c0abef3ea85824f1c79329d5c772caf;p=users%2Fjedix%2Flinux-maple.git working new code Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index e10a35580085..1902a0494c92 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1709,10 +1709,12 @@ static inline void mas_put_in_tree(struct ma_state *mas, printk("%p is root?\n", mas->node); if (mte_is_root(mas->node)) { + printk("yes\n"); mas_mn(mas)->parent = ma_parent_ptr(mas_tree_parent(mas)); rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); mas_set_height(mas); } else { + printk("no\n"); offset = mte_parent_slot(mas->node); slots = ma_slots(mte_parent(mas->node), @@ -2843,10 +2845,13 @@ static void mas_spanning_rebalance(struct ma_state *mas, mast->r = &r_mas; l_mas.status = r_mas.status = m_mas.status = ma_none; + printk("%d\n", __LINE__); /* Check if this is not root and has sufficient data. */ if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && - unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type])) + unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type])) { mast_spanning_rebalance(mast); + printk("%d\n", __LINE__); + } l_mas.depth = 0; @@ -2878,10 +2883,12 @@ static void mas_spanning_rebalance(struct ma_state *mas, mast->bn->type = mte_node_type(left); l_mas.depth++; + printk("%d\n", __LINE__); /* Root already stored in l->node. */ if (mas_is_root_limits(mast->l)) goto new_root; + printk("%d\n", __LINE__); mast_ascend(mast); mast_combine_cp_left(mast); l_mas.offset = mast->bn->b_end; @@ -2909,6 +2916,7 @@ static void mas_spanning_rebalance(struct ma_state *mas, if (!count) count++; } + printk("%d\n", __LINE__); l_mas.node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), mte_node_type(mast->orig_l->node)); @@ -2923,6 +2931,7 @@ static void mas_spanning_rebalance(struct ma_state *mas, if (mas_is_root_limits(mast->l)) { new_root: + printk("%d\n", __LINE__); mas_mn(mast->l)->parent = ma_parent_ptr(mas_tree_parent(mas)); while (!mte_is_root(mast->orig_l->node)) mast_ascend(mast); @@ -3150,7 +3159,7 @@ struct ma_node_state { }; unsigned char start; /* The start offset into the source*/ unsigned char size; /* The size to copy or insert */ - bool use_part; + bool use_part; /* ma_node_part, not a real node */ struct ma_node_info *dst; /* The destination node */ }; @@ -3204,8 +3213,10 @@ void mni_node_part_init(struct ma_node_part *ma_part, printk("pivot 0 is %lu\n", left->max); ma_part->gaps[0] = left->max_gap; + printk("set slot 1 to %p\n", right->enode); ma_part->slots[1] = right->enode; ma_part->pivots[1] = right->max; + printk("pivot 1 is %lu\n", right->max); ma_part->gaps[1] = right->max_gap; ma_part->pos = 0; @@ -3353,7 +3364,7 @@ void mns_mni_init(struct ma_node_state *mns, struct ma_node_info *dst, mns->start = start; mns->size = len; mns->use_part = false; - printk("Dst %p <= [%u] + %u\n", dst, start, len); + printk("Dst %p <= [%u] + %u\n", dst->node, start, len); } static inline @@ -3839,6 +3850,7 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) printk("%u: dst %p [%u] size %lu\n", i, ns->dst, ns->dst->offset, size); if (ns->use_part) { + printk("Use part\n"); s_slots = ns->part->slots + ns->start; s_piv = ns->part->pivots + ns->start; s_gap = ns->part->gaps + ns->start; @@ -3847,6 +3859,7 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) if (!ns->part->leaf) { int j = 0; + /* Set parent of _new_ children */ printk("not a leaf\n"); do { struct maple_enode *child; @@ -3890,6 +3903,7 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) } ns->dst->offset += size; + printk("offset advances by %u to %u\n", size, ns->dst->offset); ns->dst->end = ns->dst->offset - 1; printk("\t\t set %p end to %u\n", ns->dst->node, ns->dst->end); size -= piv_overflow; @@ -3968,14 +3982,17 @@ static int mt_wr_split_data(struct ma_node_info *src, do { unsigned char copied = 0; - if (offset >= insert && offset < insert_end) { + printk("offset is %u insert %u - %u\n", insert, insert_end); + if (offset >= insert && offset <= insert_end) { copied = min(ma_part->size - part_off, size); - printk("B: Insert at %u/%u size %u (out of %u)\n", offset, total_data, copied, + printk("B: (part) Insert at %u/%u size %u (out of %u)\n", offset, total_data, copied, ma_part->size); state[i].part = ma_part; mns_mni_init(&state[i], to, part_off, copied); state[i].use_part = true; part_off += copied; + printk("copy part size %u\n", copied); + printk("node_off is %u insert end is %u\n", node_off, node_ins_end); node_off = node_ins_end + 1; } else { state[i].info = src; @@ -3986,10 +4003,13 @@ static int mt_wr_split_data(struct ma_node_info *src, */ printk("A: min of %u and %u (%u - %u)\n", size, insert - offset, insert, offset); copied = min(size, insert - offset); + printk("\tcopied = %u\n", copied); } else { printk("C: min of %u and %u\n", size, src->end - node_off + 1); copied = min(size, (src->end - node_off + 1)); + printk("\tcopied = %u\n", copied); } + BUG_ON(copied == 0); printk("size is %u split %u\n", size, split); printk("cp at %u/%u size %u\n", offset, total_data, copied); @@ -4002,29 +4022,42 @@ static int mt_wr_split_data(struct ma_node_info *src, size -= copied; printk("next offset %u\n", offset); if ((to == left) && (offset >= split)) { - printk("Check null\n"); - if (mns_ends_in_null(&state[i])) { - printk("null split, adjust - 1\n"); + if (ma_is_leaf(src->type) && + mns_ends_in_null(&state[i])) { + printk("Check null\n"); if (!state[i].use_part && offset != insert) { - printk("\tuse_part\n"); + /* Setting up a copy from a normal node */ + printk("\t!use_part: expand cp a space\n"); + printk("offset %u insert %u\n", offset, insert); state[i].size++; split++; offset++; size--; node_off++; } else { - printk("\tregular\n"); - state[i].size--; + printk("\tuse_part!!\n"); + printk("\t\t split (%u) - 1\n", split); + printk("\t\t offset (%u) - 1\n", offset); + printk("\t\t size (%u) + 1\n", size); split--; offset--; size++; - part_off--; - if (!state[i].use_part) + if (state[i].use_part) { + printk("\t\t part_off (%u) - 1\n", part_off); + part_off--; + } else { + printk("\t\t node_off %u --\n", node_off); node_off--; + } + printk("\t\t state size (%u) - 1\n", state[i].size); + if (state[i].size == 1) + i--; + else + state[i].size--; } printk("offset %u node_off %u\n", offset, node_off); } - printk("Last pivot in left is %lu\n", to->pivots[node_off - 1]); + //printk("Last pivot in left is %lu\n", to->pivots[node_off - 1]); printk("Switch to right\n"); size = mt_slots[right->type]; printk("size is %u\n", size); @@ -4032,7 +4065,7 @@ static int mt_wr_split_data(struct ma_node_info *src, split = 255; } i++; - printk("node off is %u vs %u\n", node_off, src->end); + printk("\tnode %p off is %u vs %u\n", src->node, node_off, src->end); } while (node_off <= src->end); printk("Last pivot in right is %lu\n", to->pivots[node_off - 1]); @@ -4114,11 +4147,12 @@ try_right: left->min = src->min; right->max = src2.max; printk("right will be rebalanced against this one.\n"); + printk("ma part %p and %p\n", ma_part->slots[0], ma_part->slots[1]); } /* The rebalance operation will succeed. */ printk("\t\t%s\n", __func__); - mt_dump(mas->tree, mt_dump_dec); + //mt_dump(mas->tree, mt_dump_dec); i = 0; offset = 0; @@ -4129,10 +4163,11 @@ try_right: printk("left store at %u\n", insert); size = split; } else { - printk("right store\n"); + printk("right store (into %p)\n", src2.node); /* Right pushes data left */ insert = mas->offset + src2.end + 1; offset += src2.end + 1; + printk("insert %u offset %u\n", insert, offset); size = split - src2.end; printk("size is %u = %u - %u\n", size, split, src2.end); @@ -4154,7 +4189,7 @@ try_right: * There can also be a split between nodes that may happen at these * boundaries, or elsewhere. */ - printk("do the splitting of data\n"); + printk("do the splitting of data %u - node ins end %u\n", offset, node_ins_end); i = mt_wr_split_data(src, left, right, ma_part, split, insert, size, offset, node_ins_end, total_data, state, i); if (left_store) { @@ -4364,7 +4399,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) trace_ma_op(__func__, mas); printk("\t\t%s\n", __func__); - mt_dump(mas->tree, mt_dump_dec); + //mt_dump(mas->tree, mt_dump_dec); printk ("Store %lu - %lu => %p\n", mas->index, mas->last, wr_mas->entry); height = mas_mt_height(mas); mas->depth = height; @@ -4390,7 +4425,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) left.min = mas->min; right.max = mas->max; - mt_dump(wr_mas->mas->tree, mt_dump_dec); + //mt_dump(wr_mas->mas->tree, mt_dump_dec); i = mt_wr_split_data(&src_info, &left, &right, &ma_part, split, mas->offset, split, 0, wr_mas->offset_end, total, state, 0); @@ -4420,7 +4455,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) mni_node_init(&right, mas_pop_node(mas), src_info.type); if ((height > 1) && (mas_wr_try_rebalance(mas, &src_info, mas->end + 1, &left, - &right, &ma_part, src_info.insert_off + 1))) + &right, &ma_part, src_info.insert_off))) goto rebalanced; left.min = src_info.min; @@ -4428,9 +4463,9 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) printk("MIN %lu MAX %lu\n\n", left.min, right.max); split = (total + 1) / 2; - printk("Split data at %u\n", split); + printk("Split data at %u offset %u\n", split, mas->offset); i = mt_wr_split_data(&src_info, &left, &right, &ma_part, split, - mas->offset, split, 0, wr_mas->offset_end, + mas->offset, split, 0, mas->offset, total, state, 0); mns_assemble(state, i); mni_finalise(&left); @@ -4463,7 +4498,7 @@ converged: rebalanced: mas_wmb_replace(mas, src_info.enode); mtree_range_walk(mas); - mt_dump(wr_mas->mas->tree, mt_dump_dec); + //mt_dump(wr_mas->mas->tree, mt_dump_dec); } /* @@ -5150,36 +5185,46 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) switch (mas->store_type) { case wr_slot_store: + printk("%d\n", __LINE__); mas_wr_slot_store(wr_mas); break; case wr_node_store: + printk("%d\n", __LINE__); mas_wr_node_store(wr_mas, new_end); break; case wr_split_store: + printk("%d\n", __LINE__); mas_wr_split(wr_mas); break; case wr_rebalance: mas_wr_bnode(wr_mas); + printk("%d\n", __LINE__); //mas_wr_rebalance(wr_mas); break; case wr_exact_fit: + printk("%d\n", __LINE__); rcu_assign_pointer(wr_mas->slots[mas->offset], wr_mas->entry); if (!!wr_mas->entry ^ !!wr_mas->content) mas_update_gap(mas); break; case wr_new_root: + printk("%d\n", __LINE__); mas_new_root(mas, wr_mas->entry); break; case wr_store_root: + printk("%d\n", __LINE__); mas_store_root(mas, wr_mas->entry); break; case wr_spanning_store: + printk("%d\n", __LINE__); mas_wr_spanning_store(wr_mas); break; case wr_append: + printk("%d\n", __LINE__); mas_wr_append(wr_mas, new_end); break; case wr_invalid: + printk("%d\n", __LINE__); MT_BUG_ON(mas->tree, 1); return; } diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index c0f192a48bc1..8e8b6e91fbbf 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -1298,16 +1298,24 @@ static noinline void __init check_ranges(struct maple_tree *mt) val = i*10; val2 = (i+1)*10; check_store_range(mt, val, val2, xa_mk_value(val), 0); + if (val > 11700) + check_load(mt, 11700, xa_mk_value(11700)); MT_BUG_ON(mt, mt_height(mt) >= 4); } + check_load(mt, 11700, xa_mk_value(11700 & LONG_MAX)); /* Cause a 3 child split all the way up the tree. */ for (i = 5; i < 215; i += 10) { + printk("\n\n: START %lu (%lu)\n", 11450 + i, i); check_store_range(mt, 11450 + i, 11450 + i + 1, NULL, 0); + printk("store %lu-%lu => %p\n", 11450 + i, 11450 + i +1); + check_load(mt, 11700, xa_mk_value(11700)); mt_validate(mt); mt_dump(mt, mt_dump_dec); } for (i = 5; i < 65; i += 10) { + check_load(mt, 11700, xa_mk_value(11700 & LONG_MAX)); check_store_range(mt, 11770 + i, 11770 + i + 1, NULL, 0); + check_load(mt, 11700, xa_mk_value(11700 & LONG_MAX)); mt_validate(mt); mt_dump(mt, mt_dump_dec); MT_BUG_ON(mt, mt_height(mt) >= 4); @@ -1316,6 +1324,7 @@ static noinline void __init check_ranges(struct maple_tree *mt) MT_BUG_ON(mt, mt_height(mt) >= 4); for (i = 5; i < 45; i += 10) { check_store_range(mt, 11700 + i, 11700 + i + 1, NULL, 0); + check_load(mt, 11700, xa_mk_value(11700 & LONG_MAX)); mt_validate(mt); mt_dump(mt, mt_dump_dec); } @@ -1354,10 +1363,16 @@ static noinline void __init check_ranges(struct maple_tree *mt) } check_store_range(mt, 8001, 8001, xa_mk_value(8001), 0); check_store_range(mt, 8002, 8002, xa_mk_value(8002), 0); + check_store_range(mt, 8081, 8081, xa_mk_value(8081), 0); check_store_range(mt, 8082, 8082, xa_mk_value(8082), 0); + check_store_range(mt, 8083, 8083, xa_mk_value(8083), 0); + check_store_range(mt, 8084, 8084, xa_mk_value(8084), 0); + check_store_range(mt, 8085, 8085, xa_mk_value(8085), 0); /* triple split across multiple levels. */ - check_store_range(mt, 8099, 8100, xa_mk_value(8100), 0); + mt_dump(mt, mt_dump_dec); + check_store_range(mt, 8099, 8100, xa_mk_value(1), 0); + mt_dump(mt, mt_dump_dec); if (!MAPLE_32BIT) MT_BUG_ON(mt, mt_height(mt) != 4); } diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 4a46606a227b..b7c5d79b44af 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -35446,12 +35446,13 @@ static void check_dfs_preorder(struct maple_tree *mt) mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE); mas_reset(&mas); count = 0; + e = 76; check_rev_seq(mt, max, false); do { count++; mas_dfs_preorder(&mas); } while (!mas_is_none(&mas)); - //printk("count %lu vs %lu\n", count, e); + printk("count %lu vs %lu\n", count, e); MT_BUG_ON(mt, count != e); mtree_destroy(mt);