From: Liam R. Howlett Date: Mon, 22 Sep 2025 20:06:38 +0000 (-0400) Subject: debug X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=77e7e272bfd8f5d6955e0cac3877fbc65e614c03;p=users%2Fjedix%2Flinux-maple.git debug Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3792ba2782ff..647ecd95b688 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1173,9 +1173,12 @@ static inline struct maple_node *mas_pop_node(struct ma_state *mas) if (!total) { printk("Ran out of nodes\n"); mt_dump(mas->tree, mt_dump_hex); + fflush(stdout); + sleep(1); } if (WARN_ON(!total)) return NULL; + printk("pop\n"); if (total == 1) { /* single allocation in this ma_state */ @@ -2320,13 +2323,17 @@ static inline void rebalance_sib(struct ma_state *mas, struct ma_state *sib) mas_ascend(sib); end = mas_data_end(sib); /* Prioritize move right to pull data left */ - if (sib->offset < end) + if (sib->offset < end) { sib->offset++; - else + printk("sib right\n"); + } else { sib->offset--; + printk("sib left\n"); + } mas_descend(sib); sib->end = mas_data_end(sib); + printk("%p limits %lx - %lx\n", mas_mn(sib), sib->min, sib->max); } static inline @@ -2936,6 +2943,8 @@ unsigned long node_copy(struct ma_state *mas, struct maple_node *src, d_pivots = ma_pivots(dst, d_mt) + d_start; s_slots = ma_slots(src, s_mt) + start; s_pivots = ma_pivots(src, s_mt) + start; + printk("cp %p[%u]+%u to %p[%u] + %u\n", src, start, size, + dst, d_start, size); memcpy(d_slots, s_slots, size * sizeof(void __rcu*)); if (!ma_is_leaf(d_mt) && s_mt == maple_copy) { struct maple_enode *edst = mt_mk_node(dst, d_mt); @@ -3043,14 +3052,17 @@ static inline void cp_leaf_init(struct maple_copy *cp, cp->gap[0] = 0; else cp->gap[0] = mas->index - l_wr_mas->r_min; + printk("start piv\n"); } cp->slot[end] = l_wr_mas->entry; cp->pivot[end] = mas->last; + printk("new data (%p) %lx\n", l_wr_mas->entry, mas->last); if (l_wr_mas->entry) cp->gap[end] = 0; else cp->gap[end] = mas->last - mas->index + 1; + printk("end_piv %lx last %lx\n", r_wr_mas->end_piv, mas->last); if (r_wr_mas->end_piv > mas->last) { end++; cp->slot[end] = r_wr_mas->slots[r_wr_mas->offset_end]; @@ -3059,6 +3071,7 @@ static inline void cp_leaf_init(struct maple_copy *cp, cp->gap[end] = 0; else cp->gap[end] = r_wr_mas->end_piv - mas->last + 1; + printk("end data\n"); } cp->min = l_wr_mas->r_min; @@ -3102,10 +3115,14 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, space = 2 * mt_slots[type]; end = sib->end; + printk("%d\n", __LINE__); new_data = end + 1 + cp->data; if (new_data > space) return false; + printk("end %u cp->data %u cp->end %u\n", end, cp->data, cp->end); + printk("offset %u\n", mas->offset); + printk("%d\n", __LINE__); /* * This is off by one by design. The extra space is left to reduce * jitter in operations that add then remove two entries. @@ -3127,6 +3144,7 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, * location. */ if (sib->max < mas->min) { + printk("Trying left\n"); /* * Pushing to left, there must be room so the last slot is not * occupied. @@ -3137,11 +3155,14 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, new_data = mt_slots[type] - end - 2; if (mas->offset == new_data || mas->offset + cp->end == new_data) { + printk("use cp "); new_data -= mas->offset; slots = cp->slot; } else { + printk("use mas "); slots = ma_slots(mas_mn(mas), type); } + printk("Check slot %u\n", new_data); } else { unsigned char split; /* @@ -3152,15 +3173,21 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, * The split must fall either in the new data or the end of the * existing mas node. */ + printk("Trying right\n"); + printk("data is %u end is %u\n", cp->data, end); /* size - size to index (-1) */ split = (new_data - 1) / 2; + printk("split will be %u\n", split); if (split >= mas->offset && split <= mas->offset + cp->end + 1) { new_data = split - mas->offset; slots = cp->slot; + printk("Check new data %u\n", new_data); } else { if (mas->offset < split) { + printk("offset is smaller than expected split\n"); + printk("new_data %u offset %u end %u\n", new_data, mas->offset, cp->end); /* * The last slot in the previous node is the one * before the overflow. @@ -3172,9 +3199,12 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, new_data = mas->end - (cp->data - 1 - split); } slots = ma_slots(mas_mn(mas), type); + printk("Check mas %u\n", new_data); } } + fflush(stdout); + printk("Check %u\n", new_data); if (slots[new_data]) return true; @@ -3196,6 +3226,7 @@ static void push_data_sib(struct maple_copy *cp, struct ma_state *mas, sib->end = mas_data_end(sib); if (data_fits(sib, mas, cp)) { /* Push left */ + printk("push left\n"); return; } @@ -3211,11 +3242,13 @@ static void push_data_sib(struct maple_copy *cp, struct ma_state *mas, mas_descend(sib); sib->end = mas_data_end(sib); if (data_fits(sib, mas, cp)) { + printk("push right (%p and %p)\n", mas_mn(mas), mas_mn(sib)); /* Push right*/ return; } no_push: + printk("no pushing\n"); sib->end = 0; } @@ -3226,6 +3259,7 @@ static inline void rebalance_data_calc(struct maple_copy *cp, sib->end = 0; if (cp->data >= mt_slots[wr_mas->type]) { + printk("Push data\n"); push_data_sib(cp, wr_mas->mas, sib); if (sib->end) { cp->data += sib->end + 1; @@ -3235,6 +3269,7 @@ static inline void rebalance_data_calc(struct maple_copy *cp, if (((wr_mas->mas->min != 0) || (wr_mas->mas->max != ULONG_MAX)) && (cp->data <= mt_min_slots[wr_mas->type])) { + printk("Rebalance sibling\n"); rebalance_sib(wr_mas->mas, sib); cp->data += sib->end + 1; } @@ -3264,6 +3299,7 @@ void multi_dst_setup(struct maple_copy *cp, struct ma_state *mas, { /* Data is 1 indexed, every src has +1 added. */ + printk("data is %u vs slots %u\n", cp->data, mt_slots[mt]); if (cp->data <= mt_slots[mt]) { cp->split = cp->data - 1; cp->d_count = 1; @@ -3279,6 +3315,7 @@ void multi_dst_setup(struct maple_copy *cp, struct ma_state *mas, if (!ma_is_leaf(mt)) goto node_setup; + printk("Check leaf\n"); #if 1 /* @@ -3286,17 +3323,21 @@ void multi_dst_setup(struct maple_copy *cp, struct ma_state *mas, * can fit due to the NULL limitation on node ends. */ off = cp->split; + printk("off start %u\n", off); for (s = 0; s < cp->s_count; s++) { unsigned char s_off; s_off = cp->src[s].end - cp->src[s].start; + printk("src end %u start %u\n", cp->src[s].end, cp->src[s].start); if (s_off >= off) break; s_off++; off -= s_off; + printk("off = %u\n", off); } off += cp->src[s].start; + printk("Check src %u slot %u\n", s, off); if (ma_slots(cp->src[s].node, cp->src[s].mt)[off]) goto node_setup; @@ -3397,9 +3438,12 @@ void cp_data_write(struct maple_copy *cp, struct ma_state *mas) else size = dst_size; + printk("cp %p[%u] + %u ", src, s_offset, size); + printk("to %p[%u]\n", dst, dst_offset); d_max = node_copy(mas, src, s_offset, size, s_max, s_mt, dst, dst_offset, d_mt); + printk("d_max returned %lx\n", d_max); dst_offset += size; s_offset += size; if (s_offset > src_end) { @@ -3460,19 +3504,20 @@ static inline void cp_dst_to_slots(struct maple_copy *cp, unsigned long min, unsigned long max, struct ma_state *mas) { unsigned char d; + unsigned long slot_min = min; for (d = 0; d < cp->d_count; d++) { struct maple_node *mn = cp->dst[d].node; enum maple_type mt = cp->dst[d].mt; - unsigned long max = cp->dst[d].max; + unsigned long slot_max = cp->dst[d].max; cp->slot[d] = mt_mk_node(mn, mt); - cp->pivot[d] = max; + cp->pivot[d] = slot_max; if (mt_is_alloc(mas->tree)) { if (ma_is_leaf(mt)) { - cp->gap[d] = ma_leaf_max_gap(mn, mt, min, max, - ma_pivots(mn, mt), - ma_slots(mn,mt)); + cp->gap[d] = ma_leaf_max_gap(mn, mt, slot_min, + slot_max, ma_pivots(mn, mt), + ma_slots(mn,mt)); } else { unsigned long *gaps = ma_gaps(mn, mt); @@ -3484,7 +3529,7 @@ static inline void cp_dst_to_slots(struct maple_copy *cp, unsigned long min, } } } - min = max + 1; + slot_min = slot_max + 1; } cp->end = cp->d_count - 1; @@ -3595,18 +3640,23 @@ static inline bool rebalance_ascend(struct maple_copy *cp, mas = wr_mas->mas; if (!sib->end) { + printk("no sibling, must be last run\n"); min = mas->min; r = mas; } else if (sib->min > mas->max) { /* Move right succeeded */ min = mas->min; + printk("mas min %lx\n", min); r = sib; } else { min = sib->min; + printk("sib min %lx\n", min); r = mas; } cp_dst_to_slots(cp, min, r->max, mas); if (!cp->min && cp->max == ULONG_MAX) { + printk("new root\n"); + printk("mas is at %p\n", mas_mn(mas)); rebalance_new_root(cp, mas); return false; } @@ -3625,6 +3675,7 @@ static inline bool rebalance_ascend(struct maple_copy *cp, wr_mas->offset_end++; else wr_mas->mas->offset--; + printk("next\n\n"); return true; } @@ -4161,8 +4212,9 @@ static bool mas_wr_walk(struct ma_wr_state *wr_mas) /* root needs more than 2 entries to be sufficient + 1 */ if (mas->end > 2) wr_mas->sufficient_height = 1; - } else if (mas->end > mt_min_slots[wr_mas->type] + 1) + } else if (mas->end > mt_min_slots[wr_mas->type] + 1) { wr_mas->sufficient_height = mas->depth + 1; + } mas_wr_walk_traverse(wr_mas); } @@ -4346,6 +4398,7 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) trace_ma_write(__func__, wr_mas->mas, 0, wr_mas->entry); mas = wr_mas->mas; + mt_dump(mas->tree, mt_dump_hex); if (unlikely(!mas->index && mas->last == ULONG_MAX)) return mas_new_root(mas, wr_mas->entry); /* @@ -4642,15 +4695,21 @@ static bool split_ascend(struct maple_copy *cp, min = mas->min; /* push right, or normal split */ max = mas->max; if (sib->end) { + printk("sib was used\n"); if (sib->max < mas->min) { min = sib->min; /* push left */ + printk("pushed left, min %lx\n", min); } else { max = sib->max; /* push right */ + printk("pushed right, max %lx\n", max); } } + printk("min is %lx max is %lx\n", min, max); cp_dst_to_slots(cp, min, max, mas); + printk("min is %lx max is %lx\n", min, max); if (!cp->min && cp->max == ULONG_MAX) { + printk("rebalance new root\n"); rebalance_new_root(cp, mas); return false; } @@ -4671,6 +4730,7 @@ static bool split_ascend(struct maple_copy *cp, wr_mas->offset_end++; } + printk("ascend\n\n"); return true; } @@ -4681,12 +4741,15 @@ static void split_data_calc(struct maple_copy *cp, if (cp->data <= mt_slots[wr_mas->type]) { MAS_BUG_ON(wr_mas->mas, cp->height == 1); sib->end = 0; + printk("Split fits in %p\n", mas_mn(wr_mas->mas)); return; } + printk("Try to push\n"); push_data_sib(cp, wr_mas->mas, sib); if (sib->end) { cp->data += sib->end + 1; + printk("%d\n", __LINE__); } } @@ -4708,6 +4771,7 @@ static noinline_for_kasan void mas_wr_split(struct ma_wr_state *wr_mas) mas = wr_mas->mas; cp_leaf_init(&cp, mas, wr_mas, wr_mas); do { + printk("height %u\n", cp.height); split_data_calc(&cp, wr_mas, &sib); multi_src_setup(&cp, wr_mas, wr_mas, &sib); multi_dst_setup(&cp, mas, wr_mas->type); @@ -4720,6 +4784,7 @@ static noinline_for_kasan void mas_wr_split(struct ma_wr_state *wr_mas) mtree_range_walk(mas); //mt_dump(wr_mas->mas->tree, mt_dump_hex); + printk("Done\n\n"); mt_validate(wr_mas->mas->tree); #else @@ -4765,6 +4830,7 @@ static void mas_wr_rebalance(struct ma_wr_state *wr_mas) mas = wr_mas->mas; cp_leaf_init(&cp, mas, wr_mas, wr_mas); do { + printk("height %u\n", cp.height); rebalance_data_calc(&cp, wr_mas, &sib); multi_src_setup(&cp, wr_mas, wr_mas, &sib); multi_dst_setup(&cp, mas, wr_mas->type); @@ -4773,6 +4839,7 @@ static void mas_wr_rebalance(struct ma_wr_state *wr_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, cp.height); mtree_range_walk(mas); } @@ -4786,6 +4853,7 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) struct ma_state *mas = wr_mas->mas; unsigned char new_end = mas_wr_new_end(wr_mas); + printk("Write %lx - %lx => %p\n", mas->index, mas->last, wr_mas->entry); switch (mas->store_type) { case wr_exact_fit: rcu_assign_pointer(wr_mas->slots[mas->offset], wr_mas->entry); @@ -4985,6 +5053,7 @@ static inline void mas_wr_preallocate(struct ma_wr_state *wr_mas, void *entry) mas_wr_prealloc_setup(wr_mas); wr_mas->mas->store_type = mas_wr_store_type(wr_mas); + printk("store type %u\n", wr_mas->mas->store_type); request = mas_prealloc_calc(wr_mas, entry); if (!request) return; @@ -6229,6 +6298,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) mas_wr_prealloc_setup(&wr_mas); mas->store_type = mas_wr_store_type(&wr_mas); + printk("Sufficient is %u\n", wr_mas.sufficient_height); request = mas_prealloc_calc(&wr_mas, entry); if (!request) goto set_flag;