{
int slot = 0;
unsigned long piv = mas->min, prev_piv = mas->min;
- //printk("starting %lu %lu\n", piv, prev_piv);
- //printk(" min %lu max %lu\n", mas->min, mas->max);
for (; slot < mt_slot_count(mas->node); slot++) {
piv = _mas_get_safe_pivot(mas, slot, type);
- //printk(" %u %lu\n", slot, piv);
if (piv >= mas->max)
break;
prev_piv = piv;
}
-// printk("%s: %u\n", __func__, slot);
*last_piv = piv;
return slot;
}
pstart = mas->min;
for (i = 0; i < mt_slots[mt]; i++) {
- //printk("Checking %u\n", i);
pend = mas_get_safe_pivot(mas, i);
if (!pend && i)
pend = mas->max;
if (!mt_is_empty(entry) || xa_is_retry(entry))
goto next;
- //printk("gap %lu in %u\n", gap, i);
- //printk("%lu - %lu + 1\n", pend, pstart);
-
if (gap > max_gap)
max_gap = gap;
pstart = pend + 1;
}
done:
- //printk("max gap is %lu\n", max_gap);
return max_gap;
}
unsigned char slot_cnt = mt_slot_count(mn);
int i;
- printk("%s: %p type %u\n", __func__, mn, type);
switch (type) {
case maple_range_16:
case maple_range_32:
case maple_range_64:
case maple_arange_64:
for (i = 0; i < slot_cnt; i++) {
- printk("%s: get slot %u\n", __func__, i);
node = mte_get_rcu_slot(mn, i, mtree);
- printk("%s: destroy %p\n", __func__, mte_to_node(mn));
if (node)
mte_destroy_walk(node, mtree);
}
default:
break;
}
- printk("%s: Free %p (%p)\n", __func__, mte_to_node(mn), mn);
mte_free(mn);
}
break;
child = _mte_get_rcu_slot(parent, slot, type, mas->tree);
- if (!mt_is_empty(child)) {
- printk("set %p[%u] to parent of %p\n", parent, slot, child);
+ if (!mt_is_empty(child))
mte_set_parent(child, parent, slot);
- }
}
}
/* Private
unsigned char slot = 0;
if (mte_is_root(mas->node)) {
- printk("It's root\n");
- printk("New height will be %d\n", mas->depth);
prev = mas->tree->ma_root;
} else {
enum maple_type ptype = mas_parent_enum(mas, mas->node);
parent = mt_mk_node(mte_parent(mas->node), ptype);
slot = mte_parent_slot(mas->node);
- printk("Get slot %u of %p\n", slot, parent);
prev = mte_get_rcu_slot(parent, slot, mas->tree);
}
}
if (free) {
- printk("Free %p\n", mte_to_node(prev));
mte_free(prev);
return;
}
if (!entry)
return NULL;
-// printk("parent of %p[%u] is %p\n", mas_mn(mas), slot, mte_parent(entry));
if (mte_parent(entry) == entry) {
printk("%s: Dead node %p", __func__, entry);
MT_BUG_ON(mas->tree, 1);
static inline struct maple_enode *mas_find_l_split(struct ma_state *mas)
{
unsigned char i, end = mas_data_end(mas);
-// printk("data end of %p was %u\n", mas_mn(mas), end);
struct maple_enode *en = NULL;
for (i = 0; i <= end; i++) {
-// printk("%s: Checking %p[%i]\n", __func__, mas_mn(mas), i);
if ((en = mas_check_split_parent(mas, i)))
break;
}
unsigned char shift, bool alloc)
{
do {
-// printk("move %u to %u\n", b_end, b_end + shift);
b_node->pivot[b_end + shift] = b_node->pivot[b_end];
b_node->slot[b_end + shift] = b_node->slot[b_end];
-// printk("piv %u is %lu\n", b_end + shift, b_node->pivot[b_end + shift]);
if (alloc)
b_node->gap[b_end + shift] = b_node->gap[b_end];
} while (b_end--);
/* Avoid ending a node on a NULL entry */
if (!b_node->slot[split]) {
- printk("%u is null\n", split);
if (split < slot_cnt - 1)
split++;
else
unsigned char mab_start)
{
int i, j;
- printk("%s: cp %u - %u\n", __func__, mas_start, mas_end);
for (i = mas_start, j = mab_start; i <= mas_end; i++, j++) {
- //printk("cp mas %u\n", i);
b_node->slot[j] = mas_get_rcu_slot(mas, i);
if (!mte_is_leaf(mas->node) && mt_is_alloc(mas->tree)) {
b_node->gap[j] = mte_get_gap(mas->node, i);
- printk("gap %d is %lu\n", j, b_node->gap[j]);
}
if (i < mt_pivot_count(mas->node)) {
- printk("get safe pivot for %u\n", i);
b_node->pivot[j] = mas_get_safe_pivot(mas, i);
- printk("Set b_node %u slot %p => piv %lu\n", j,
- b_node->slot[j], b_node->pivot[j]);
} else {
b_node->pivot[j] = mas->max;
- printk("Set b_node %u slot %p => piv %lu\n", j,
- b_node->slot[j], b_node->pivot[j]);
j++;
break;
}
break;
}
}
- printk("%s: return %u\n", __func__, j);
return j;
}
struct ma_state *mas, unsigned char mas_start)
{
int i, j;
- printk("%s: cp %u - %u to mas %p\n", __func__, mab_start, mab_end, mas_mn(mas));
for (i = mab_start, j = mas_start; i <= mab_end; i++, j++) {
- //printk("i %d end %u\n", i, mab_end);
if(j && !b_node->pivot[i]) {
- printk("no pivot at %u\n", i);
break;
}
mas->max = b_node->pivot[i];
mte_set_rcu_slot(mas->node, j, b_node->slot[i]);
- printk("Set %u %lu %p\n", j, b_node->pivot[i], b_node->slot[i]);
if (j < mt_pivot_count(mas->node))
mte_set_pivot(mas->node, j, b_node->pivot[i]);
* then set the correct parent in all of of the parent's children.
*/
while (!mte_is_leaf(l_mas.node)) {
- printk("start of l %p is %p\n", mas_mn(&l_mas), l_mas.node);
- printk("start of r %p is %p\n", mas_mn(&r_mas), r_mas.node);
if (!(l_enode = mas_find_l_split(&l_mas))) {
- printk("\tChecking right\n");
mas_adopt_children(&l_mas, l_mas.node);
mas_dup_state(&l_mas, &r_mas);
if (!(l_enode = mas_find_l_split(&l_mas))) {
}
}
- printk("%d New node is %p\n", __LINE__, mte_to_node(l_enode));
-
if (!(r_enode = mas_find_r_split(&r_mas))) {
- printk("\tChecking left\n");
mas_adopt_children(&r_mas, r_mas.node);
mas_dup_state(&r_mas, &l_mas);
r_enode = mas_find_r_split(&r_mas);
}
- printk("%d New node is %p\n", __LINE__, mte_to_node(r_enode));
- printk("Adopt children of l %p\n", mas_mn(&l_mas));
mas_adopt_children(&l_mas, l_mas.node);
- if (r_mas.node != l_mas.node) {
- printk("Adopt children of r %p\n", mas_mn(&r_mas));
+ if (r_mas.node != l_mas.node)
mas_adopt_children(&r_mas, r_mas.node);
- }
+
mas_descend(&l_mas);
mas_descend(&r_mas);
-
- printk("%d New node is %p\n", __LINE__, mas_mn(&l_mas));
- printk("%d New node is %p\n", __LINE__, mas_mn(&r_mas));
- printk("\n");
}
}
b_node->pivot[b_end++] = mas->index - 1;
}
- printk("Store value at %u piv %lu\n", b_end, mas->last);
b_node->slot[b_end] = entry;
b_node->pivot[b_end] = mas->last;
if (piv >= mas->max)
return b_end;
- printk("slot %u piv %lu\n", slot, piv);
do {
piv = mas_get_safe_pivot(mas, ++slot);
} while ((piv <= mas->last) && (slot <= end));
- printk("slot %u piv %lu\n", slot, piv);
-
if (piv > mas->last) {
- printk("Cp %u to %u\n", slot, end);
if (slot > end) {
b_node->slot[++b_end] = NULL;
b_node->pivot[b_end] = piv;
mas_ascend(mas);
mas_set_slot(mas, p_slot - 1);
- printk("%s: going to go to %p[%u]\n", __func__, mas_mn(mas), p_slot - 1);
mas_descend(mas);
return true;
}
unsigned char l_slot, r_slot, slot, end;
unsigned long l_min, range_min, range_max;
- printk("%s: l %p (%lu) r %p (%lu)\n", __func__, mas_mn(l_mas),
- l_mas->index, mas_mn(r_mas), r_mas->last);
// The left node is consumed, so add to the free list.
free[(*f)++] = l_mas->node;
- printk("free %u -> %p (%p)\n", (*f)-1, mte_to_node(free[(*f)-1]),
- free[(*f)-1]);
-
l_min = l_mas->index;
l_mas->index = l_mas->last;
- printk("OVERWRITE index with %lu for search?\n", l_mas->last);
mas_node_walk(l_mas, mte_node_type(l_mas->node), &range_min, &range_max);
l_mas->index = l_min;
l_slot = mas_get_slot(l_mas);
r_slot = mas_get_slot(r_mas);
- printk("l_slot %u r_slot %u\n", l_slot, r_slot);
if (l_mas->node == r_mas->node) {
/* If the contents up to l_slot and from r_slot to end are
* still valid and it's the same node, then the rest may need to
* from the parent in the previous iteration which is still in
* use.
*/
- printk("Add %p[%u-%u] to discard\n", mas_mn(l_mas), l_slot + 1, r_slot - 1);
- for (slot = l_slot + 1; slot < r_slot; slot++) {
+ for (slot = l_slot + 1; slot < r_slot; slot++)
discard[(*d)++] = mas_get_rcu_slot(l_mas, slot);
- printk("discard %u -> %p\n", (*d)-1, discard[(*d)-1]);
- }
return;
}
/* r_mas is different and consumed. */
free[(*f)++] = r_mas->node;
- printk("free %u -> %p\n", (*f)-1, free[(*f)-1]);
if (mte_is_leaf(r_mas->node))
return;
/* Now free l_slot + 1 -> end and 0 -> r_slot - 1 */
end = mas_data_end(l_mas);
- for (slot = l_slot + 1; slot <= end; slot++) {
+ for (slot = l_slot + 1; slot <= end; slot++)
discard[(*d)++] = mas_get_rcu_slot(l_mas, slot);
- printk("l discard %u -> %p\n", (*d)-1, discard[(*d)-1]);
- }
- for (slot = 0; slot < r_slot; slot++) {
+ for (slot = 0; slot < r_slot; slot++)
discard[(*d)++] = mas_get_rcu_slot(r_mas, slot);
- printk("r discard %u -> %p (%u of %u)\n", (*d)-1, discard[(*d)-1], slot, r_slot);
- }
}
/* Private
l_mas.node = r_mas.node = m_mas.node = NULL;
left = right = middle = NULL;
- mt_dump(mas->tree);
- printk("Starting with orig of %p and %p\n", mas_mn(orig_l_mas),
- mas_mn(orig_r_mas));
- printk("\t\t%d %u\n", __LINE__, b_end);
mas_consume(orig_l_mas, orig_r_mas, free, &i, destroy, &d);
while(count--) {
- printk("Iteration %u\n", count);
b_end--;
slot_cnt = mt_slot_count(orig_l_mas->node);
right = NULL;
if (mab_middle_node(b_node, b_end, slot_cnt))
middle = mt_mk_node(ma_mnode_ptr(mas_next_alloc(mas)),
mte_node_type(orig_l_mas->node));
- printk("Splitting %u at %u\n", b_end, split);
/* Set parents from previous run */
if (l_mas.node) {
l_mas.min = orig_l_mas->min;
mab_mas_cp(b_node, 0, split, &l_mas, 0);
l_mas.max = b_node->pivot[split];
- printk("set from split l_mas.max %lu and %lu\n", l_mas.max, l_mas.min);
r_mas.max = l_mas.max;
m_mas.max = b_node->pivot[split];
}
if (right) {
- printk("there is a r\n");
mab_mas_cp(b_node, 1 + split, b_end, &r_mas, 0);
r_mas.min = b_node->pivot[split] + 1;
r_mas.max = b_node->pivot[b_end];
- printk("r_mas.max from %u\n", b_end);
}
-///
/* Copy data from next level in the tree to b_node from next iteration */
memset(b_node, 0, sizeof(struct maple_big_node));
orig_l_mas->depth++;
if (!l_mas.min && l_mas.max == ULONG_MAX) {
- printk("New root detected by range\n");
-
mas_mn(&l_mas)->parent = ma_parent_ptr(
((unsigned long)mas->tree | MA_ROOT_PARENT));
mas->depth = orig_l_mas->depth;
b_end = 0;
- printk("orig_l_mas is %p\n", orig_l_mas->node);
if (mte_is_root(orig_l_mas->node)) {
- printk("Already at root, skipping consumption\n");
if ((orig_l_mas->node != mas->node) &&
(l_mas.depth > mas->tree->ma_height)) {
- printk("Adding %p to free list %u\n", mas->node, i);
free[i++] = mas->node;
}
} else {
- // mas_set_slot(orig_l_mas, 0);
do {
mas_ascend(orig_l_mas);
mas_ascend(orig_r_mas);
- mas_set_slot(orig_l_mas, 0);
- mas_set_slot(orig_r_mas, 0);
- mas_node_walk(orig_l_mas, mte_node_type(orig_l_mas->node),
- &range_min, &range_max);
- mas_node_walk(orig_r_mas, mte_node_type(orig_r_mas->node),
- &range_min, &range_max);
- // mas_set_slot(orig_r_mas,
- // mas_data_end(orig_r_mas));
+ mas_set_slot(orig_l_mas, 0);
+ mas_set_slot(orig_r_mas, 0);
+ mas_node_walk(orig_l_mas,
+ mte_node_type(orig_l_mas->node),
+ &range_min, &range_max);
+ mas_node_walk(orig_r_mas,
+ mte_node_type(orig_r_mas->node),
+ &range_min, &range_max);
mas_consume(orig_l_mas, orig_r_mas,
free, &i, destroy, &d);
} while (!mte_is_root(orig_l_mas->node));
mas_ascend(orig_r_mas);
r_end = mas_data_end(orig_r_mas);
- printk("orig_l_mas min is %lu\n", orig_l_mas->min);
mas_set_slot(orig_r_mas, 0);
orig_r_mas->index = r_mas.max;
if (orig_r_mas->last < orig_r_mas->index)
orig_r_mas->last = orig_r_mas->index;
- printk("Update r_mas.max to %lu\n", r_mas.max);
- printk("R walk %p for %lu\n", mas_mn(orig_r_mas), orig_r_mas->index);
if (!mas_node_walk(orig_r_mas,
mte_node_type(orig_r_mas->node),
&range_min, &range_max)) {
mas_set_slot(orig_r_mas, r_end + 1);
}
r_slot = mas_get_slot(orig_r_mas);
- printk("r_slot is %u\n", r_slot);
mas_set_slot(orig_l_mas, 0);
orig_l_mas->index = l_mas.min;
- printk("L walk %p for %lu\n", mas_mn(orig_l_mas), orig_l_mas->index);
mas_node_walk(orig_l_mas, mte_node_type(orig_l_mas->node),
&range_min, &range_max);
l_slot = mas_get_slot(orig_l_mas);
b_end = 0;
- if (l_slot) {
- printk("Copy in orig_l_mas %p\n", mas_mn(orig_l_mas));
+ if (l_slot)
b_end = mas_mab_cp(orig_l_mas, 0, l_slot - 1, b_node, 0);
- }
- printk("Put L %p at %u %lu\n", l_mas.node, b_end, l_mas.max);
+
child = b_end;
// Track dead nodes here.
b_node->slot[b_end] = l_mas.node;
- if(mt_is_alloc(mas->tree)) {
+ if(mt_is_alloc(mas->tree))
b_node->gap[b_end] = mas_find_gap(&l_mas);
- printk("gap %u is %lu\n", b_end, b_node->gap[b_end]);
- }
+
b_node->pivot[b_end++] = l_mas.max;
- printk("l_mas max is %lu\n", b_node->pivot[b_end - 1]);
if (middle) {
- printk("Put M! %p at %u %lu\n", m_mas.node, b_end, m_mas.max);
b_node->slot[b_end] = middle;
- if(mt_is_alloc(mas->tree)) {
- b_node->gap[b_end] =
- mas_find_gap(&m_mas);
- printk("gap %u is %lu\n", b_end, b_node->gap[b_end]);
- }
+ if(mt_is_alloc(mas->tree))
+ b_node->gap[b_end] = mas_find_gap(&m_mas);
+
b_node->pivot[b_end++] = m_mas.max;
}
if (right) {
- printk("Put R %p at %u %lu\n", r_mas.node, b_end, r_mas.max);
b_node->slot[b_end] = right;
- if(mt_is_alloc(mas->tree)) {
- b_node->gap[b_end] =
- mas_find_gap(&r_mas);
- printk("gap %u is %lu\n", b_end, b_node->gap[b_end]);
- }
+ if(mt_is_alloc(mas->tree))
+ b_node->gap[b_end] = mas_find_gap(&r_mas);
+
b_node->pivot[b_end++] = r_mas.max;
- printk("r_mas max is %lu\n", b_node->pivot[b_end - 1]);
}
// Copy anything necessary out of the right node.
if (b_node->pivot[b_end - 1] < orig_r_mas->max) {
- printk("Copy in orig_r_mas %p %u-%u\n", mas_mn(orig_r_mas),
- r_slot + 1, r_end);
- b_end = mas_mab_cp(orig_r_mas, r_slot + 1, r_end, b_node,
- b_end);
+ b_end = mas_mab_cp(orig_r_mas, r_slot + 1, r_end,
+ b_node, b_end);
orig_r_mas->last = orig_r_mas->max;
}
mas_consume(orig_l_mas, orig_r_mas, free, &i, destroy, &d);
// Attempt to balance from this parent
if (b_end - 1 < mt_min_slot_cnt(orig_l_mas->node)) {
unsigned char end;
- printk("\t merge with other node l is %p r is %p\n",
- mas_mn(orig_l_mas), mas_mn(orig_r_mas));
if (mas_next_sibling(orig_r_mas)) {
- printk("r sibling merger\n");
end = mas_data_end(orig_r_mas);
b_end = mas_mab_cp(orig_r_mas, 0, end, b_node,
b_end);
- printk("Add free r %p (%p)\n", mas_mn(orig_r_mas),
- orig_r_mas->node);
free[i++] = orig_r_mas->node;
orig_r_mas->last = orig_r_mas->max;
if (!count)
count++;
} else if (mas_prev_sibling(orig_l_mas)) {
- printk("l sibling merger %p\n", mas_mn(orig_l_mas));
end = mas_data_end(orig_l_mas);
// shift b_node by prev size
mab_shift_right(b_node, b_end - 1, end + 1,
(mt_is_alloc(mas->tree) ? true : false));
// copy in prev.
mas_mab_cp(orig_l_mas, 0, end, b_node, 0);
- printk("Add free l %p (%p)\n", mas_mn(orig_l_mas),
- orig_l_mas->node);
free[i++] = orig_l_mas->node;
l_mas.min = orig_l_mas->min;
orig_l_mas->index = orig_l_mas->min;
// Ensure there is enough data for the next iteration.
if (b_end - 1 < mt_min_slot_cnt(orig_l_mas->node)) {
unsigned char end;
- printk("\tSteal some data b_end = %u\n", b_end);
mas_set_slot(orig_r_mas,
mte_parent_slot(orig_r_mas->node));
mas_next_node(orig_r_mas, ULONG_MAX);
if (!mas_is_none(orig_r_mas)) {
// Add r_mas.node to clean_list.
// r_mas is now at the next node..
- printk("Taking from right\n");
end = mas_data_end(orig_r_mas);
b_end = mas_mab_cp(orig_r_mas, 0, end,
b_node, b_end);
orig_r_mas->last = orig_r_mas->max;
free[i++] = orig_r_mas->node;
} else {
- printk("Trying left\n");
// Put left into right.
mas_dup_state(orig_r_mas, orig_l_mas);
mas_dup_state(&r_mas, &l_mas);
if (mas_is_none(orig_l_mas)) {
// This is going to be a new root of
// only what is in b_node
- printk("%s: %d New root? %u\n",
- __func__, __LINE__, b_end);
mas_dup_state(orig_l_mas, orig_r_mas);
b_end--;
break;
free[i++] = orig_l_mas->node;
child += end + 1;
b_end += end + 1;
- printk("b_end is %u\n", b_end);
}
if (!count)
count++;
}
- printk("\t\t%d %u\n", __LINE__, b_end);
- printk("Next\n");
}
l_mas.node = mt_mk_node(ma_mnode_ptr(mas_next_alloc(mas)),
mte_node_type(orig_l_mas->node));
orig_l_mas->depth++;
- printk("All done making replacement at %p\n", mas_mn(&l_mas));
- printk("orig is %p\n", mas_mn(orig_l_mas));
- printk("orig r is %p\n", mas_mn(orig_r_mas));
//mas_consume(orig_l_mas, orig_r_mas, free, &i, destroy, &d);
mab_mas_cp(b_node, 0, b_end, &l_mas, 0);
- printk("\t\t==>Setting parent of %p to %p[%u]\n", left, mas_mn(&l_mas),
- child);
-
mte_set_parent(left, l_mas.node, child);
if (middle)
mte_set_parent(middle, l_mas.node, ++child);
mas->depth = orig_l_mas->depth;
done:
- printk("Going to insert %p\n", mas_mn(&l_mas));
// Set up mas for insertion.
- printk("Killing %p (%p)\n", mas_mn(mas), mas->node);
mas_set_node_dead(mas);
mas_dup_state(mas, orig_l_mas);
smp_wmb();
- mt_dump(mas->tree);
if (!mte_is_leaf(mas->node))
mas_descend_adopt(mas);
do {
- printk("%s: Free %u %p (%p)\n", __func__, i - 1,
- mte_to_node(free[i - 1]), free[i - 1]);
mte_free(free[--i]);
} while (i);
if (d) {
do {
- printk("%s: destroy %u %p (%p)\n", __func__, d - 1,
- mte_to_node(destroy[d - 1]), destroy[d-1]);
mte_destroy_walk(destroy[--d], mas->tree);
} while (d);
}
- mt_dump(mas->tree);
if (mte_is_leaf(mas->node))
- return b_end;
+ return b_end;
if (mt_is_alloc(mas->tree))
mas_update_gap(mas, false);
char empty = mas->full_cnt * -1;
unsigned char b_end = 0;
- printk("%s: rebalance %u levels\n", __func__, empty);
- mt_dump(mas->tree);
-
mas_node_cnt(mas, 1 + empty * 2);
if (mas_is_err(mas))
return 0;
(mt_is_alloc(mas->tree) ? true : false));
b_end = mas_mab_cp(&l_mas, 0, mas_data_end(&l_mas), b_node, 0);
b_end += new_end + 1;
- printk("b_end is %u\n", b_end);
l_mas.index = l_mas.last = l_mas.min;
}
int j, i = 0, height = 0;
struct maple_enode *list[100];
- printk("%s\n", __func__);
- mt_dump(mas->tree);
MA_STATE(l_mas, mas->tree, mas->index, mas->last);
MA_STATE(r_mas, mas->tree, mas->index, mas->last);
MA_STATE(orig_l_mas, mas->tree, mas->index, mas->last);
* into the highest common ancestor necessary to be modified (which may
* be a new root).
*/
- printk("list %u -> %p\n", i, mas_mn(mas));
list[i++] = mas->node;
- printk("full cnt = %u\n", mas->full_cnt);
while (height++ <= mas->full_cnt) {
struct maple_node *l, *r;
enum maple_type type = mte_node_type(mas->node);
unsigned char slot_cnt = mt_slot_count(mas->node); /* should be full. */
bool cp = true;
- printk("height %d\n", height);
-
if (height > mas->full_cnt) {
// The last node to be created.
if (mte_is_root(mas->node)) {
mte_set_pivot(ancestor, j,
b_node->pivot[j]);
if (mt_is_alloc(mas->tree)) {
- printk("Set gap %i to %lu\n", j, b_node->gap[j]);
mte_set_gap(ancestor, j,
b_node->gap[j]);
}
}
// Set the parent for the children.
- printk("Placing left %u and right %u in %p\n",
- mas_get_slot(&l_mas), mas_get_slot(&r_mas), ancestor);
- printk("l %p and r %p\n", mas_mn(&l_mas), mas_mn(&r_mas));
mte_set_parent(l_mas.node, ancestor,
mas_get_slot(&l_mas));
mte_set_parent(r_mas.node, ancestor,
l = ma_mnode_ptr(mas_next_alloc(mas));
r = ma_mnode_ptr(mas_next_alloc(mas));
- printk("l = %p\n", l);
- printk("r - %p\n", r);
mas_dup_state(&l_mas, mas);
mas_dup_state(&r_mas, mas);
l_mas.node = mt_mk_node(l, type);
r_mas.node = mt_mk_node(r, type);
if (mte_is_leaf(mas->node)) {
- printk("Splitting leaf %p\n", mas_mn(mas));
split = mab_calc_split(b_node, new_end, slot_cnt,
mas->min, type);
- printk("Splitting at %u\n", split);
if (split < slot_cnt)
j = mab_mas_cp(b_node, 0, split, &l_mas, 0);
else
mte_set_pivot(r_mas.node, 0, r_mas.max);
mab_mas_cp(b_node, j, new_end, &r_mas, 0);
- printk("l_max is %lu\n", l_mas.max);
mas_set_slot(&l_mas, mte_parent_slot(mas->node));
- printk("l parent slot %u\n", mas_get_slot(&l_mas));
r_mas.min = l_mas.max + 1;
- printk("r_min is %lu\n", r_mas.min);
// In the case of empty.
- printk("We are missing one here.. end %u split %u\n",
- new_end, split);
mas_set_slot(&r_mas, mas_get_slot(&l_mas) + 1);
} else {
unsigned char p_slot;
/* internal node split - cut in half for now. */
split = slot_cnt / 2;
- printk("split is %u %u %u\n", split, mas_get_slot(&l_mas),
- mas_get_slot(&r_mas));
j = mab_mas_cp(b_node, 0, split, &l_mas, 0);
l_mas.max = b_node->pivot[j - 1];
- printk("l_mas.max %lu\n", l_mas.max);
r_mas.min = l_mas.max + 1;
mab_mas_cp(b_node, j, slot_cnt, &r_mas, 0);
p_slot = mas_get_slot(&orig_l_mas);
- printk("setting parents of %p and %p to %p and %p\n",
- mas_mn(&orig_l_mas), mas_mn(&orig_r_mas),
- mas_mn(&l_mas), mas_mn(&r_mas));
if (p_slot <= split) { // prev left side is on left.
mte_set_parent(orig_l_mas.node, l_mas.node,
p_slot);
- printk("p_slot of %p is %u\n", orig_l_mas.node, p_slot);
}
else {
mte_set_parent(orig_l_mas.node, r_mas.node,
p_slot - split - 1);
- printk("p_slot of %p is %u\n", orig_l_mas.node, p_slot - split - 1);
}
p_slot = mas_get_slot(&orig_r_mas);
if (p_slot <= split) {// prev right side is on left.
mte_set_parent(orig_r_mas.node, l_mas.node,
p_slot);
- printk("p_slot of %p is %u\n", orig_r_mas.node, p_slot);
} else {
mte_set_parent(orig_r_mas.node, r_mas.node,
p_slot - split - 1);
- printk("p_slot of %p is %u\n", orig_r_mas.node, p_slot - split - 1);
}
}
else {
mas_ascend(mas);
mas_set_slot(mas, mte_parent_slot(mas->node));
- printk("list %u -> %p\n", i, mas_mn(mas));
list[i++] = mas->node;
}
b_node, 0);
split = j;
- printk("Split is %u\n", split);
b_node->slot[j] = l_mas.node;
- printk("l_mas %p[%u] piv %lu\n", mas_mn(&l_mas), j, l_mas.max);
b_node->pivot[j] = l_mas.max;
mas_set_slot(&l_mas, j);
if (mt_is_alloc(mas->tree)) {
b_node->gap[j] = mas_find_gap(&l_mas);
b_node->gap[j + 1] = mas_find_gap(&r_mas);
- printk("Setting %p gap to %lu\n",
- mas_mn(&l_mas), b_node->gap[j]);
- printk("Setting %p gap to %lu\n",
- mas_mn(&r_mas), b_node->gap[j+1]);
}
b_node->slot[++j] = r_mas.node;
b_node->pivot[j] = r_mas.max;
mas_set_slot(&r_mas, j);
- printk("New right is in %u (%p)\n", j, b_node->slot[j]);
- printk("piv right is %lu\n", r_mas.max);
mas_dup_state(&orig_l_mas, &l_mas);
mas_dup_state(&orig_r_mas, &r_mas);
if (cp)
mas->node = ancestor;
- printk("Using %p (%p)\n", ancestor, mte_to_node(ancestor));
BUG_ON(mas_is_none(mas));
// Set the original node as dead
- printk("%s: Killing orig_mas %p\n", __func__, mte_to_node(list[0]));
mte_to_node(list[0])->parent = ma_parent_ptr(mte_to_node(list[0]));
smp_wmb();
mas_descend_adopt(mas);
do {
- printk("%s: Free %u %p (%p)\n", __func__, i - 1,
- mte_to_node(list[i - 1]), list[i-1]);
mte_free(list[--i]);
- rcu_barrier();
} while (i);
if (mt_is_alloc(mas->tree))
mas_update_gap(mas, false);
- //mt_dump(mas->tree);
- printk("Start at %p\n", mas_mn(mas));
- mt_dump(mas->tree);
+
return 1;
}
{
struct maple_enode *new_node;
- printk("Commit\n");
if ((end < mt_min_slot_cnt(mas->node)) && !mte_is_root(mas->node) &&
(mas->tree->ma_height > 1) ) {
- printk("end %u min slot %u\n", end, mt_min_slot_cnt(mas->node));
return mas_rebalance(mas, b_node, end);
}
else if (end >= mt_slot_count(mas->node))
return 0;
new_node = mt_mk_node(mas_next_alloc(mas), mte_node_type(mas->node));
- printk("Set %p parent to %p\n", mte_to_node(new_node), mas_mn(mas)->parent);
mte_to_node(new_node)->parent = mas_mn(mas)->parent;
- printk("going to replace %p\n", mas_mn(mas));
mas->node = new_node;
- printk("Copy out 0-%u\n", end);
mab_mas_cp(b_node, 0, end, mas, 0);
_mas_replace(mas, true, false, true);
if (mt_is_alloc(mas->tree))
if (mas_is_err(mas))
return 0;
- printk("\tExpand\n");
mas->node = mt_mk_node(mas_next_alloc(mas), mt);
mas_mn(mas)->parent = ma_parent_ptr(
((unsigned long)mas->tree | MA_ROOT_PARENT));
{
unsigned long range_min, range_max;
unsigned char b_end = 0; // big_node end.
- unsigned char count = 0, left, right;
+ unsigned char count = 0;
struct maple_big_node b_node;
int node_cnt = 0;
MA_STATE(r_mas, mas->tree, mas->index, mas->index);
// Leaf nodes
- printk("%s: %d\n", __func__, __LINE__);
-
if (mas->full_cnt > 0)
node_cnt = 1 + mas->full_cnt * 2; // For split upwards.
else
* two for every level below the split location.
*/
node_cnt += 2 + (mas->tree->ma_height - mas->depth) * 2;
-
- printk("Node_cnt is %u (%u - %u) * 2 with full %d\n", node_cnt,
- mas->tree->ma_height, mas->depth, mas->full_cnt);
-
mas_node_cnt(mas, node_cnt);
if (mas_is_err(mas))
return 0;
- //mt_dump(mas->tree);
mas_dup_state(&l_mas, mas);
mas->last = mas->index;
mas_node_walk(mas, mte_node_type(mas->node), &range_min, &range_max);
- left = mas_get_slot(mas);
mas->index = mas->last = l_mas.last;
mas_node_walk(mas, mte_node_type(mas->node), &range_min, &range_max);
- right = mas_get_slot(mas);
- printk("-->Copy node %p and free %u-%u\n", mte_to_node(mas->node), left, right);
mas_dup_state(mas, &l_mas);
mas->last = l_mas.last = r_mas.index = r_mas.last;
mas_set_slot(mas, mas_get_slot(&l_mas));
}
- printk("%s: final range is %lu-%lu at slot %u\n", __func__,
- mas->index, mas->last, mas_get_slot(&l_mas));
// Copy l_mas and store the value in b_node.
count = mas_cnt_positive(mas) + mas->tree->ma_height - mas->depth + 1;
// Combine l_mas and r_mas and split them up evenly again.
- printk("b_end start is %u and count is %u\n", b_end, count);
l_mas.depth = 0;
b_end = mas_combine_separate(mas, &l_mas, &r_mas, &b_node, b_end,
count);
- //mt_dump(mas->tree);
- printk("%s: complete\n", __func__);
return b_end;
}
int ret = 0;
- printk("\nStart: %s %d store %lu-%lu %p\n", __func__, __LINE__,
- mas->index, mas->last, entry);
-
- //mt_dump(mas->tree);
if (mas_start(mas) || (mas_is_none(mas) || mas->node == MAS_ROOT))
ret = ma_root_ptr(mas, entry, content, overwrite);
!mas->span_enode) {
/* Not a leaf or spanning write. = broken tree. */
// FIXME, rebuild?
- printk("%s %d\n", __func__, __LINE__);
return NULL;
}
if (mas->span_enode) {
- printk("%s %d\n", __func__, __LINE__);
if (!overwrite) {
mas_set_err(mas, -EEXIST);
return NULL; // spanning writes always overwrite something.
if (!entry) {
mas_extend_null(mas, mas);
slot = mas_get_slot(mas);
- printk("store is now %lu-%lu at slot %u\n", mas->index,
- mas->last, mas_get_slot(mas));
}
memset(&b_node, 0, sizeof(struct maple_big_node));
- printk("Copy %p 0-%u\n", mas_mn(mas), slot);
mas_set_slot(mas, slot);
new_end = mas_store_b_node(mas, &b_node, entry);
- printk("new_end is %u\n", new_end);
// Check if this is an append operation.
end = mas_data_end(mas);
if ((new_end < slot_cnt) && ((slot > end) || !end)) {
// Appending
- printk("Appending to %p[%u] %lu\n", mas_mn(mas), slot, mas->index);
if (r_min < mas->index)
mte_set_pivot(mas->node, slot++, mas->index - 1);
else if (new_end < mt_min_slot_cnt(mas->node))
mas_cnt_empty(mas);
- printk("End %u new_end %u slot_cnt %u\n", end, new_end, slot_cnt);
-
mas_commit_b_node(mas, &b_node, new_end);
if (mas_is_err(mas))
ret = 3;
return NULL;
- //mt_dump(mas->tree);
return content;
}
void *mas_store(struct ma_state *mas, void *entry)
unsigned long start_piv;
restart_next_node:
- //printk("%s: %d %p\n", __func__, __LINE__, mas_mn(mas));
level = 0;
while (1) {
unsigned char count;
mn = mas->node;
slot = mas_get_slot(mas);
- //printk("slot is %u\n", slot);
start_piv = mas_get_safe_pivot(mas, slot);
level++;
mas_ascend(mas);
if (level == 1) {
mas_set_slot(mas, slot);
mas->node = mn;
- printk("Found node %p\n", mas_mn(mas));
if (mas_dead_node(mas, start_piv)) {
- printk("it's dead\n");
- MT_BUG_ON(mas->tree, 1);
goto restart_next_node;
}
return pivot;
prev_min = mas->min;
prev_max = mas->max;
while (range_start < limit) {
- printk("start %p\n", mas_mn(mas));
mas_set_slot(mas, slot);
if (!mas_next_nentry(mas, limit, &range_start)) {
- printk("no next.. slot %u\n", slot);
void *entry = mas_get_rcu_slot(mas, slot - 1);
if (mte_is_leaf(mas->node)) {
- printk("leaf at slot %u\n", slot);
mas->index = range_start - 1;
mas->index = mte_get_pivot(mas->node, slot - 1);
return entry;
unsigned char slot;
while (!mas_is_none(mas)) {
- if (mas_prev_nentry(mas, limit, &max)) {
- printk("prev_nentry is %p\n", mas_mn(mas));
+ if (mas_prev_nentry(mas, limit, &max))
break;
- }
mas_prev_node(mas, limit);
- printk("prev_node is %p\n", mas_mn(mas));
mas_set_slot(mas, mt_slot_count(mas->node));
}
if (!mas->node)
mas->node = MAS_START;
- printk("Prev of %p\n", mas_mn(mas));
if (mas_is_start(mas)) {
mas_start(mas);
- printk("Get last entry %p\n", mas_mn(mas));
return mas_last_entry(mas, ULONG_MAX);
}
type = mte_node_type(mas->node);
pivot_cnt = mt_pivots[type];
- printk("%d %p[%u]\n", __LINE__, mas_mn(mas), mas_get_slot(mas));
switch (type) {
case maple_leaf_64:
pivot = _mas_get_safe_pivot(mas, i, type);
- printk("%d %p[%u] %lu\n", __LINE__, mas_mn(mas), i, pivot);
/* End of data in this leaf */
if (i && !pivot) {
if (min > mas->max)
for (; i <= pivot_cnt; i++) {
unsigned long this_gap;
pivot = _mas_get_safe_pivot(mas, i, type);
- printk("%d %p[%u] %lu\n", __LINE__, mas_mn(mas), i, pivot);
if (i && !pivot)
goto ascend;
min = pivot + 1;
if (mas->last < min) {
- printk("%lu < %lu\n", mas->last, min);
mas_set_err(mas, -EBUSY);
return true;
}
if (!ma_is_leaf(type)) { //descend
struct maple_enode *next;
- printk("%d %p\n", __LINE__, mas_mn(mas));
next = mas_get_rcu_slot(mas, i);
mas->min = min;
found = true;
mas_set_slot(mas, i);
- printk("found %s\n", found ? "yes": "no");
return found;
}
* found the gap. (return, slot != MAPLE_NODE_SLOTS)
*/
while (!mas_is_err(mas) && !_mas_awalk(mas, size)) {
- printk("%d mas node is %p last %p\n", __LINE__, mas_mn(mas), last);
if (last == mas->node)
mas_skip_node(mas);
else
mas->index = min;
mas->last = max;
- printk("%d mas node is %p walk %lu-%lu for %lu\n", __LINE__,
- mas_mn(mas), mas->index, mas->last, size);
if (forward)
mas_awalk(mas, size);
else
mas_rev_awalk(mas, size);
- printk("%d mas node is %p\n", __LINE__, mas_mn(mas));
- if (mas_is_err(mas)) {
- printk("error is %u\n", xa_err(mas->node));
+ if (mas_is_err(mas))
return xa_err(mas->node);
- }
if (mas_get_slot(mas) == MAPLE_NODE_SLOTS)
return -EBUSY;
unsigned char slot;
do {
- printk("Skip node %p\n", mas_mn(mas));
if (mte_is_root(mas->node)) {
slot = mas_get_slot(mas);
if (slot > mt_slot_count(mas->node) - 1) {
}
} else {
slot = mte_parent_slot(mas->node);
- printk("skip parent slot %u\n", slot);
mas_ascend(mas);
- printk("%d mas node is %p\n", __LINE__, mas_mn(mas));
}
} while (slot > mt_slot_count(mas->node) - 1);
mas_set_slot(mas, ++slot);
mas_update_limits(mas, slot, mte_node_type(mas->node));
- printk("%d mas node is %p\n", __LINE__, mas_mn(mas));
return true;
}
/* Private
unsigned long r_max, r_min;
void *entry = NULL;
- printk("Start: erase %lu\n", mas->index);
entry = mas_range_load(mas, &r_min, &r_max, true);
retry:
- printk("Erase %lu-%lu\n", r_min, r_max);
mas->node = MAS_START;
mas->index = r_min;
mas->last = r_max;
unsigned long p_min, p_max;
mas_set_slot(mas, mte_parent_slot(mas->node));
- printk("next node from %p\n", mas_mn(mas));
mas_next_node(mas, max);
if (mas->node != MAS_NONE)
return;