From: Liam R. Howlett Date: Tue, 26 Aug 2025 15:36:33 +0000 (-0400) Subject: height fix X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=118acaa3b49bc1a2ba48fe7d63f015bc3e594c52;p=users%2Fjedix%2Flinux-maple.git height fix Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index a148c5315207..d935444cf9cd 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1761,11 +1761,13 @@ static inline void mas_put_in_tree(struct ma_state *mas, void __rcu **slots; if (mte_is_root(mas->node)) { + printk("new root in tree\n"); mas_mn(mas)->parent = ma_parent_ptr(mas_tree_parent(mas)); rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); mt_set_height(mas->tree, new_height); } else { + printk("Replace node in tree\n"); offset = mte_parent_slot(mas->node); slots = ma_slots(mte_parent(mas->node), mas_parent_type(mas, mas->node)); @@ -3312,6 +3314,7 @@ static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, } printk("CONVERGED\n"); + WARN_ON_ONCE(cp->dst[0].node != mte_to_node(cp->slot[0])); cp->dst[0].node->parent = ma_parent_ptr(mas_tree_parent(mas)); while (!mte_is_root(mas->node)) mas_ascend(mas); @@ -3519,13 +3522,13 @@ static void mas_spanning_rebalance(struct ma_state *mas, static void mas_wr_spanning_rebalance(struct ma_state *mas, - unsigned char height, struct ma_wr_state *l_wr_mas, - struct ma_wr_state *r_wr_mas) + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) { struct maple_enode *old_enode; struct ma_state sib; struct maple_copy cp; int debug = 0; + unsigned char count = 1; /* * Spanning store is different in that the write is actually from @@ -3540,6 +3543,7 @@ static void mas_wr_spanning_rebalance(struct ma_state *mas, spanning_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); do { printk("\nlmas %p rmas %p\n", l_wr_mas->node, r_wr_mas->node); + count++; spanning_data_calc(&cp, mas, l_wr_mas, r_wr_mas, &sib); spanning_split_dest_setup(&cp, mas, l_wr_mas->type); @@ -3553,7 +3557,7 @@ static void mas_wr_spanning_rebalance(struct ma_state *mas, for (int i = 0; i < cp.d_count; i++) { printk("dump %p %lx - %lx\n", cp.dst[i].node, min, cp.dst[i].max); mt_dump_node(mas->tree, mt_mk_node(cp.dst[i].node, cp.dst[i].mt), - min, cp.dst[i].max, height, mt_dump_hex); + min, cp.dst[i].max, count, mt_dump_hex); min = cp.dst[i].max + 1; } } @@ -3565,8 +3569,10 @@ static void mas_wr_spanning_rebalance(struct ma_state *mas, old_enode = mas->node; mas->node = cp.slot[0]; printk("Replace %p with %p\n", old_enode, mas->node); - mas_wmb_replace(mas, old_enode, height); + mas_wmb_replace(mas, old_enode, count); mtree_range_walk(mas); + printk("range at %p[%u]\n", mas->node, mas->offset); + mt_dump(mas->tree, mt_dump_hex); } /* @@ -4340,7 +4346,6 @@ done: static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) { struct ma_state *mas; - unsigned char height; /* Left and Right side of spanning store */ MA_STATE(r_mas, NULL, 0, 0); @@ -4368,7 +4373,6 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) * Node rebalancing may occur due to this store, so there may be three new * entries per level plus a new root. */ - height = mas_mt_height(mas); /* * Set up right side. Need to get to the next offset after the spanning @@ -4400,7 +4404,7 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) return mas_new_root(mas, wr_mas->entry); } - mas_wr_spanning_rebalance(mas, height + 1, wr_mas, &r_wr_mas); + mas_wr_spanning_rebalance(mas, wr_mas, &r_wr_mas); } /*