if (wr_mas->r_min < wr_mas->mas->index) {
part->pivots[0] = wr_mas->mas->index - 1;
part->slots[0] = wr_mas->content;
- printk("%s zero piv is %lu\n", __func__,part->pivots[part->size]);
part->size++;
}
part->pivots[part->size] = wr_mas->mas->last;
part->slots[part->size] = wr_mas->entry;
- printk("%s one piv is %lu\n", __func__,part->pivots[part->size]);
part->size++;
if (wr_mas->end_piv > wr_mas->mas->last) {
part->pivots[part->size] = wr_mas->end_piv;
part->slots[part->size] = src->slots[wr_mas->offset_end];
- printk("%s last piv is %lx\n", __func__,part->pivots[part->size]);
part->size++;
}
part->skip = wr_mas->offset_end - wr_mas->mas->offset + 1;
- printk("skip %u\n", part->skip);
part->leaf = true;
}
unsigned long max_gap;
unsigned char len;
- if (!sd->is_alloc)
- printk("\n\n\nNOT ALLOC\n\n\n");
len = mt_slots[p->type] - p->offset;
if (len) {
memset(p->slots + p->offset, 0, len * sizeof(void *));
if (p->offset <= mt_pivots[p->type]) {
ma_set_meta(p->node, p->type, 0, p->offset - 1);
}
- if (p->max != ULONG_MAX) {
- if (p->slots[p->offset - 1] == NULL) {
- printk("last slot %u has %lu\n", p->offset - 1,
- p->pivots[p->offset - 1]);
- }
+ if (p->max != ULONG_MAX)
BUG_ON(p->slots[p->offset - 1] == NULL);
- }
} else {
unsigned long gap_off = 0;
if (p->gaps) {
if (last_dst != ns->dst) {
WARN_ON_ONCE(!max);
ns->dst->min = max + 1;
- printk("%p max set to %lu\n", last_dst->node, last_dst->max);
- printk("%p min set to %lu\n", ns->dst->node, ns->dst->min);
}
last_dst = ns->dst;
if (ns->start + size > mt_pivots[ns->info->type]) {
piv_overflow = 1;
max = ns->info->max;
- printk("max fro ns->info->max\n");
} else {
- printk("max from %lu\n", size - 1 );
max = s_piv[size - 1];
}
}
{
unsigned char off = 0;
- printk("\t%s\n", __func__);
sd->len = 0;
mni_node_init(dst, mas_pop_node(mas), src->type);
if (src->insert_off) {
off += part->skip;
if (src->end >= off) {
- unsigned char start = off;
- unsigned char size = src->end - start + 1;
- mns_mni_init(&sd->states[sd->len], dst, start, size);
+ unsigned char size;
+
+ size = src->end - off + 1;
+ mns_mni_init(&sd->states[sd->len], dst, off, size);
sd->states[sd->len].info = src;
sd->len++;
- off += size - 1;
}
mns_assemble(sd->states, sd->len);
unsigned char copied;
/* Configure one state */
- printk("\t set up state %u\n", sd->len);
- printk("\t insert from %u - %u\n", sd->insert, sd->insert_end);
state = &sd->states[sd->len];
if (sd->offset >= sd->insert && sd->offset <= sd->insert_end) {
copied = min(part->size - part->pos, sd->space);
state->part = part;
- printk("insert part at %u first entry is %p\n", sd->offset, part->slots[0]);
- printk("Size is %u/%u\n", copied, part->size);
mns_mni_init(state, dst, part->pos , copied);
state->use_part = true;
part->pos += copied;
src->offset = sd->src_ins_end + 1;
- printk("Set src %p offset to %u\n", src->node, src->offset);
} else {
state->info = src;
if (sd->offset < sd->insert_end) {
* First part of node, may split across node
* boundaries though
*/
- printk("%d\n", __LINE__);
copied = min(sd->space, sd->insert - sd->offset);
} else {
- printk("%d\n", __LINE__);
copied = min(sd->space, (src->end - src->offset + 1));
}
BUG_ON(copied == 0);
- printk("src offset is %u\n", src->offset);
mns_mni_init(state, dst, src->offset, copied);
src->offset += copied;
}
sd->offset += copied;
sd->space -= copied;
- printk("offset %u split %u\n", sd->offset, sd->split);
}
/*
struct ma_node_state *state;
- printk("%s\n", __func__);
/* Offset into the destination data where the insert ends */
sd->insert_end = sd->insert + part->size - 1;
to = left;
sd->split = 255;
}
sd->len++;
- printk("node off %u src end %u\n", src->offset, src->end);
} while (src->offset <= src->end);
}
bool can_rebalance_right(struct ma_state *tmp_mas, struct ma_node_info *parent,
struct ma_node_info *src2, struct split_data *sd)
{
- printk("\t%s %u %u\n", __func__, parent->insert_off, parent->end);
if (parent->insert_off >= parent->end) /* No right node */
return false;
tmp_mas->offset++;
- printk("Check %p[%u]\n", tmp_mas->node, tmp_mas->offset);
mas_descend(tmp_mas);
mni_mas_init(src2, tmp_mas);
mni_set_end(src2);
sd->split = mas_wr_rebalance_calc(src2->end + sd->new_end, src2->type);
- printk("split is %u\n", sd->split);
if (!sd->split) {
mas_ascend(tmp_mas);
tmp_mas->offset--;
bool can_rebalance_left(struct ma_state *tmp_mas, struct ma_node_info *parent,
struct ma_node_info *src2, struct split_data *sd)
{
- printk("\t%s %u %u\n", __func__, parent->insert_off, parent->end);
if (!parent->insert_off) /* No left node */
return false;
tmp_mas->offset--;
- printk("Check %p[%u]\n", tmp_mas->node, tmp_mas->offset);
mas_descend(tmp_mas);
mni_mas_init(src2, tmp_mas);
mni_set_end(src2);
sd->split = mas_wr_rebalance_calc(src2->end + sd->new_end, src2->type);
- printk("split is %u\n", sd->split);
if (!sd->split) {
mas_ascend(tmp_mas);
tmp_mas->offset++;
struct ma_node_info *dst;
struct ma_node_state *state;
- printk("\t\t%s \n", __func__);
sd->insert_end = sd->insert + part->size - 1;
if (!left_store) {
char len;
* Store to the right implies left is going to donate data to
* the right node
*/
- printk("store is in right\n");
state = &sd->states[sd->len];
left->min = src2->min;
right->max = src->max;
sd->offset = src2->end + 1;
state->info = src2;
- printk("cp from %p\n", src2->node);
/* The first state to copy is the left node */
- printk("cp to left %u+%u\n", 0, sd->split);
mns_mni_init(state, left, 0, sd->split);
if (ma_is_leaf(src->type) && mns_ends_in_null(state)) {
- printk("ends in null\n");
sd->split--;
state->size--;
- printk("NEW cp to left %u-%u\n", 0, sd->split);
}
sd->len++;
len = src2->end + 1 - sd->split;
sd->states[sd->len].info = src2;
mns_mni_init(&sd->states[sd->len], right, sd->split, len);
- printk("cp to right %u-%u (%u + 1 - %u\n", sd->split, len, src2->end, sd->split);
sd->len++;
sd->space = mt_slots[right->type];
dst = right;
- printk("src ins end is %u\n", wr_mas->offset_end);
- printk("\n");
} else {
- printk("store left\n");
sd->space = sd->split;
sd->offset = 0;
left->min = src->min;
}
do {
- printk("cp from %p starting at %u\n", src->node, src->offset);
split_state_setup(src, dst, part, sd);
- printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node,
- sd->states[sd->len].start,
- sd->states[sd->len].size, dst == left ? "left" : "right");
sd->len++;
} while (src->offset <= src->end);
- printk("\n\nend of loop\n");
if (left_store) {
char len;
- if (sd->offset >= sd->insert && sd->offset <= sd->insert_end)
- printk("BING\n");
-
state = &sd->states[sd->len];
sd->split = (sd->new_end + 1) / 2;
- printk("sd is at offset %u splut %u\n", sd->offset, sd->split);
len = sd->split - sd->offset;
state->info = src2;
- printk("cp from %p to right %u + %u to left\n", src2->node, 0, len);
mns_mni_init(state, left, 0, len);
if (ma_is_leaf(src->type) && mns_ends_in_null(state)) {
- printk("ends in null\n");
sd->split--;
sd->offset--;
sd->space++;
len--;
}
- printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node,
- sd->states[sd->len].start,
- sd->states[sd->len].size, dst == left ? "left" : "right");
- printk("cp the right->to right->%u + %u\n", len, src2->end + 1);
sd->len++;
/* Stored to the left, copy the last of the right->in src2 */
sd->states[sd->len].info = src2;
mns_mni_init(&sd->states[sd->len], right, len, src2->end + 1 - len);
- printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node,
- sd->states[sd->len].start,
- sd->states[sd->len].size, dst == left ? "left" : "right");
sd->len++;
}
struct split_data *sd,
bool left_store)
{
- printk("\t\t%s\n", __func__);
sd->insert_end = sd->insert + part->size - 1;
if (!left_store) {
- printk("store right\n");
left->min = src2->min;
left->max = src->max;
sd->offset = src2->end + 1;
mns_mni_init(&sd->states[sd->len], left, 0, src2->end + 1);
sd->len++;
} else {
- printk("store left\n");
sd->space = sd->split;
sd->offset = 0;
left->min = src->min;
do {
- printk("cp from %p starting at %u\n", src->node, src->offset);
split_state_setup(src, left, part, sd);
- printk("state %d: cp %p[%u] + %u to %s\n", sd->len, src->node,
- sd->states[sd->len].start,
- sd->states[sd->len].size, "always left");
sd->len++;
} while (src->offset <= src->end);
if (left_store) {
sd->states[sd->len].info = src2;
- printk("cp right->%u + %u to left\n", 0, src2->end + 1);
mns_mni_init(&sd->states[sd->len], left, 0, src2->end + 1);
sd->len++;
}
* Rebalancing will pull data from the right first, keeping the tree
* compact to the left side.
*/
- mt_dump(mas->tree, mt_dump_dec);
- printk("Rebalance %p offset %u - %u\n", mas->node, mas->offset, wr_mas->offset_end);
- printk("Store %p %lu - %lu\n", wr_mas->entry, mas->index, mas->last);
-
height = mas_mt_height(mas);
-
mni_mas_init(&src, mas);
src.end = mas->end;
- printk("HERE\n");
mns_node_part_leaf_init(&part, wr_mas, &src);
sd.new_end = mas->end + part.size - part.skip + 1;
sd.src_ins_end = wr_mas->offset_end;
sd.len = 0;
mni_node_init(&left, mas_pop_node(mas), wr_mas->type);
- printk("left is %p\n", left.node);
if (mt_is_alloc(mas->tree))
sd.is_alloc = true;
else
sd.is_alloc = false;
do {
- printk("\tloop\n");
tmp_mas = *mas;
mas_wr_ascend_init(&tmp_mas, &parent);
if (can_rebalance_right(&tmp_mas, &parent, &src2, &sd)) {
- printk("rebalance right, split is %u\n", sd.split);
- printk("rebalance with %p\n", src2.node);
/* Left will be src, right will be src2 */
sd.insert = mas->offset;
- printk("insert is at %u\n", sd.insert);
left_store = true;
} else {
/* Won't fail here */
MAS_BUG_ON(mas, can_rebalance_left(&tmp_mas, &parent, &src2, &sd) == false);
- printk("rebalance left, split is %u\n", sd.split);
- printk("rebalance with %p\n", src2.node);
/* Left will be src2, right will be src */
sd.insert = mas->offset + src2.end + 1;
}
- printk("rebalance %p %p\n", src.node, src2.node);
sd.new_end += src2.end + 1;
- printk("new end %u\n", sd.new_end);
- if (sd.new_end < mt_min_slots[left.type]) {
- printk("Not enough tdata\n");
- exit(0);
- }
- printk("Total data is %u\n", sd.new_end);
- printk("sd insert is %u\n", sd.insert);
if (sd.new_end >= mt_slots[left.type]) {
- if (sd.new_end - sd.split < mt_min_slots[left.type]) {
- printk("Too big split\n");
- exit(0);
- }
mni_node_init(&right, mas_pop_node(mas), mte_node_type(mas->node));
- printk("right is %p\n", right.node);
- printk("%s end with %lu - %lu\n", __func__, mas->index, mas->last);
mas_wr_rebalance_two(wr_mas, &left, &right, &src, &src2, &part, &sd, left_store);
mas_ascend(mas);
mas->end = parent.end;
mas->offset = parent.insert_off;
- printk("Replacing 2 nodes (%d), break\n", sd.new_end);
- printk("mas is %p\n", mas->node);
break;
}
- printk("REDUCE %p %p\n", src.node, src2.node);
mas_wr_rebalance_reduce(wr_mas, &left, &src, &src2, &part, &sd, left_store);
-
- /* Must go again */
mas_ascend(mas);
mas->end = parent.end;
mas->offset = parent.insert_off;
- printk("\tmas is now at %p[%u]\n", mas->node, mas->offset);
- sd.len = 0;
- sd.new_end = mas->end + part.size - part.skip + 1;
- sd.offset = mas->offset;
- sd.src_ins_end = mas->offset + 1;
if (ma_is_root(parent.node)) {
- printk("Parent IS root, so abort rest\n");
if (parent.end != 1)
break; /* Converged */
- printk("left needs to be new root\n");
src.enode = mas->node;
left.node->parent = mas_mn(mas)->parent;
mas->node = left.enode;
mas->depth = mas_mt_height(mas) - 1;
if (mas->depth == 1)
- mas_set_height(mas);
+ mas_set_height(mas);
goto new_root;
}
- if (mas->end > mt_min_slots[parent.type]) {
- printk("Decrease %p to %u\n", parent.node, parent.end - 1);
-
+ if (mas->end > mt_min_slots[parent.type])
break; /* Converged */
- }
+ /* Must go again */
+ sd.len = 0;
+ sd.new_end = mas->end + part.size - part.skip + 1;
+ sd.offset = mas->offset;
+ sd.src_ins_end = mas->offset + 1;
mni_mas_init(&src, mas);
src.end = mas->end;
mni_node_init(&left, mas_pop_node(mas), mte_node_type(mas->node));
- printk("\nAGAIN, parent %p[%u] src %p\n", parent.node, parent.insert_off, src.node);
- printk("height is %u\n", height);
} while (height--);
mas_wr_converged(&parent, &new_parent, &part, mas, &sd);
src.enode = parent.enode;
- printk("Replace %p with %p\n", parent.node, mte_to_node(new_parent.enode));
mas->node = new_parent.enode;
new_root:
mas_wmb_replace(mas, src.enode);
mtree_range_walk(mas);
- mt_dump(mas->tree, mt_dump_dec);
mt_validate(mas->tree);
}