unsigned long limit)
{
void **slots, *entry;
- int offset = 0;
unsigned long range_start = mas->min;
while (!mte_is_leaf(mas->node)) {
slots = ma_slots(mte_to_node(mas->node), mte_node_type(mas->node));
- while ((range_start < limit) && (offset < mt_slot_count(mas->node))) {
- entry = mas_slot(mas, slots, offset);
- if (entry) {
- mas->offset = offset;
+ mas->offset = 0;
+ while ((range_start < limit) && (mas->offset < mt_slot_count(mas->node))) {
+ entry = mas_slot(mas, slots, mas->offset);
+ if (entry)
return range_start;
- }
- range_start = mas_safe_pivot(mas, offset) + 1;
- offset++;
+ range_start = mas_safe_pivot(mas, mas->offset) + 1;
+ mas->offset++;
}
mas->node = MAS_NONE;
if (!mas_next_nentry(mas, limit, &range_start)) {
entry = mas_get_slot(mas, slot - 1);
if (mte_is_leaf(mas->node)) {
- mas->index = range_start - 1;
- mas->index = mte_pivot(mas->node, slot - 1);
+ mas->last = mte_pivot(mas->node, slot - 1);
+ mas->index = mte_pivot(mas->node, slot - 2) + 1;
return entry;
}
{
void *entry = NULL;
unsigned long index = mas->index;
- unsigned char slot = mas->offset;
-
- mas->offset = slot + 1;
+ unsigned char slot;
+ mas->offset++;
retry:
*range_start = mas->last + 1;
if (entry)
return true;
- if (mas_is_none(mas)) {
- mas->offset = MAPLE_NODE_SLOTS;
- return false;
- }
+ if (mas_is_none(mas))
+ goto not_found;
if (mas_is_ptr(mas)) {
*range_min = 0;
*range_max = 0;
if (!mas->index)
return true;
- mas->offset = MAPLE_NODE_SLOTS;
- return false;
+
+ goto not_found;
}
- mas->offset = 0;
return __mas_walk(mas, range_min, range_max);
+
+not_found:
+ mas->offset = MAPLE_NODE_SLOTS;
+ return false;
}
{
unsigned long range_min, range_max;
unsigned long index = mas->index;
- unsigned char offset;
_mas_walk(mas, &range_min, &range_max);
retry:
if (mas_dead_node(mas, index))
goto retry;
- offset = mas->offset;
- if (offset == MAPLE_NODE_SLOTS)
+ if (mas->offset == MAPLE_NODE_SLOTS)
return NULL; // Not found.
- return mas_get_slot(mas, offset);
+ return mas_get_slot(mas, mas->offset);
}
static inline bool mas_search_cont(struct ma_state *mas, unsigned long index,
static inline int mas_alloc(struct ma_state *mas, void *entry,
unsigned long size, unsigned long *index)
{
- unsigned char slot = MAPLE_NODE_SLOTS;
unsigned long min;
mas_start(mas);
if (mas_is_err(mas))
return xa_err(mas->node);
- slot = mas->offset;
- if (slot == MAPLE_NODE_SLOTS)
+ if (mas->offset == MAPLE_NODE_SLOTS)
goto no_gap;
- // At this point, mas->node points to the right node and we have a
- // slot that has a sufficient gap.
+ // At this point, mas->node points to the right node and we have an
+ // offset that has a sufficient gap.
min = mas->min;
- if (slot)
- min = mte_pivot(mas->node, slot - 1) + 1;
+ if (mas->offset)
+ min = mte_pivot(mas->node, mas->offset - 1) + 1;
if (mas->index < min)
mas->index = min;
- return mas_fill_gap(mas, entry, slot, size, index);
+ return mas_fill_gap(mas, entry, mas->offset, size, index);
no_gap:
return -EBUSY;
unsigned long max, void *entry,
unsigned long size, unsigned long *index)
{
- unsigned char slot = MAPLE_NODE_SLOTS;
int ret = 0;
ret = _mas_get_empty_area(mas, min, max, size, false);
if (mas_is_err(mas))
return xa_err(mas->node);
- slot = mas->offset;
- if (slot == MAPLE_NODE_SLOTS)
+ if (mas->offset == MAPLE_NODE_SLOTS)
goto no_gap;
- return mas_fill_gap(mas, entry, slot, size, index);
+ return mas_fill_gap(mas, entry, mas->offset, size, index);
no_gap:
return -EBUSY;
retry:
if (_mas_walk(mas, range_min, range_max)) {
- unsigned char offset = MAPLE_NODE_SLOTS;
-
if (mas_is_ptr(mas) && mas->last == 0)
return mte_safe_root(mas->tree->ma_root);
- offset = mas->offset;
- if (offset >= MAPLE_NODE_SLOTS)
+ if (mas->offset >= MAPLE_NODE_SLOTS)
return NULL;
- entry = mas_get_slot(mas, offset);
+ entry = mas_get_slot(mas, mas->offset);
if (mte_dead_node(mas->node))
goto retry;
}
unsigned long range_start = 0, range_end = 0;
void *entry = NULL;
bool leaf;
- unsigned char slot;
MA_STATE(mas, mt, *index, *index);
rcu_read_lock();
leaf = _mas_walk(&mas, &range_start, &range_end);
- slot = mas.offset;
- if (leaf == true && slot != MAPLE_NODE_SLOTS)
- entry = mas_get_slot(&mas, slot);
+ if (leaf == true && mas.offset != MAPLE_NODE_SLOTS)
+ entry = mas_get_slot(&mas, mas.offset);
mas.last = range_end;
if (!entry || xa_is_zero(entry))