From: Liam R. Howlett Date: Wed, 24 Sep 2025 14:03:25 +0000 (-0400) Subject: working and drop debug X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=35c021cc6cec104befd99f9e37dd7276fbb186b1;p=users%2Fjedix%2Flinux-maple.git working and drop debug Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 31f7f95e30b5..2b36ffc11e7d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1170,15 +1170,8 @@ static inline struct maple_node *mas_pop_node(struct ma_state *mas) unsigned int req = mas_alloc_req(mas); /* nothing or a request pending. */ - 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 */ @@ -2323,17 +2316,13 @@ 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++; - printk("sib right\n"); - } else { + 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 @@ -2943,8 +2932,6 @@ 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); @@ -3052,17 +3039,14 @@ 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]; @@ -3071,7 +3055,6 @@ 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; @@ -3115,15 +3098,10 @@ 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; - printk("new_data %u vs %u\n", new_data, space); 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. @@ -3143,6 +3121,7 @@ static bool data_fits(struct ma_state *sib, struct ma_state *mas, if (new_data < space) return true; } + return false; #else /* Leave some room to reduce jitter. */ @@ -3238,11 +3217,8 @@ static void push_data_sib(struct maple_copy *cp, struct ma_state *mas, sib->offset--; mas_descend(sib); sib->end = mas_data_end(sib); - if (data_fits(sib, mas, cp)) { - /* Push left */ - printk("push left\n"); + if (data_fits(sib, mas, cp)) /* Push left */ return; - } mas_ascend(sib); sib->offset++; @@ -3255,14 +3231,10 @@ static void push_data_sib(struct maple_copy *cp, struct ma_state *mas, sib->offset++; 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*/ + if (data_fits(sib, mas, cp)) /* Push right*/ return; - } no_push: - printk("no pushing\n"); sib->end = 0; } @@ -3273,21 +3245,22 @@ 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; - return; - } + if (sib->end) + goto use_sib; } 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; + goto use_sib; } + + return; +use_sib: + cp->data += sib->end + 1; } + /* * cp->data will not be 0 indexed. */ @@ -3313,7 +3286,6 @@ 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; @@ -3329,38 +3301,36 @@ 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 - /* * Leaf nodes are a bit tricky because we cannot assume the data * 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; - cp->split; + cp->split++; if (cp->split < mt_slots[mt]) goto node_setup; + cp->split -= 2; + if (cp->data - 2 - cp->split < mt_slots[mt]) + goto node_setup; + } -#endif + /* No other choice but to 3-way split the data */ cp->split = (cp->data + 2) / 3; cp->d_count = 3; @@ -3452,12 +3422,9 @@ 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) { @@ -3503,13 +3470,15 @@ void cp_data_write(struct maple_copy *cp, struct ma_state *mas) } node_finalise(dst, d_mt, dst_offset); + ++d; /* Next destination */ + if (d == cp->d_count - 1) + split = cp->data - data_offset; + if (d >= cp->d_count) { WARN_ON(data_offset < cp->data); return; } - /* Next dst */ - ++d; } while (data_offset <= cp->data); } @@ -3654,23 +3623,18 @@ 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; } @@ -3689,7 +3653,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; } @@ -4412,7 +4376,6 @@ 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); /* @@ -4434,7 +4397,6 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) mas_wr_walk_index(&r_wr_mas); r_mas.last = r_mas.index = mas->last; r_wr_mas.end_piv = r_wr_mas.r_max; - BUG_ON(!r_mas.end); /* Set up left side. */ mas_wr_walk_index(wr_mas); @@ -4709,21 +4671,14 @@ 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) { + if (sib->max < mas->min) min = sib->min; /* push left */ - printk("pushed left, min %lx\n", min); - } else { + 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; } @@ -4744,7 +4699,6 @@ static bool split_ascend(struct maple_copy *cp, wr_mas->offset_end++; } - printk("ascend\n\n"); return true; } @@ -4755,16 +4709,12 @@ 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) { + if (sib->end) cp->data += sib->end + 1; - printk("%d\n", __LINE__); - } } /* @@ -4780,11 +4730,9 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) trace_ma_write(__func__, wr_mas->mas, 0, wr_mas->entry); - //mt_dump(wr_mas->mas->tree, mt_dump_hex); 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); @@ -4795,10 +4743,6 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) mas->node = cp.slot[0]; mas_wmb_replace(mas, old_enode, cp.height); mtree_range_walk(mas); - - //mt_dump(wr_mas->mas->tree, mt_dump_hex); - printk("Done\n\n"); - mt_validate(wr_mas->mas->tree); } /* @@ -4833,7 +4777,6 @@ 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); @@ -4842,7 +4785,6 @@ 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); } @@ -4856,7 +4798,6 @@ 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); @@ -5056,7 +4997,6 @@ 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; @@ -6301,7 +6241,6 @@ 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;