Skip to content

Commit

Permalink
maple_tree: use cached node end in mas_next()
Browse files Browse the repository at this point in the history
When looking for the next entry, don't recalculate the node end as it is
now tracked in the maple state.

Link: https://lkml.kernel.org/r/20231101171629.3612299-6-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Peng Zhang <zhangpeng.00@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Liam R. Howlett authored and Andrew Morton committed Dec 12, 2023
1 parent 31c532a commit e9c52d8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/maple_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,7 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node,
unsigned long min;
unsigned long *pivots;
struct maple_enode *enode;
struct maple_node *tmp;
int level = 0;
unsigned char node_end;
enum maple_type mt;
Expand Down Expand Up @@ -4591,6 +4592,10 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node,
pivots = ma_pivots(node, mt);

mas->max = mas_safe_pivot(mas, pivots, mas->offset, mt);
tmp = mte_to_node(enode);
mt = mte_node_type(enode);
pivots = ma_pivots(tmp, mt);
mas->end = ma_data_end(tmp, mt, pivots, mas->max);
if (unlikely(ma_dead_node(node)))
return 1;

Expand Down Expand Up @@ -4625,20 +4630,18 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty,
unsigned long pivot;
enum maple_type type;
struct maple_node *node;
unsigned char data_end;
unsigned long save_point = mas->last;
void *entry;

retry:
node = mas_mn(mas);
type = mte_node_type(mas->node);
pivots = ma_pivots(node, type);
data_end = ma_data_end(node, type, pivots, mas->max);
if (unlikely(mas_rewalk_if_dead(mas, node, save_point)))
goto retry;

if (mas->max >= max) {
if (likely(mas->offset < data_end))
if (likely(mas->offset < mas->end))
pivot = pivots[mas->offset];
else
goto overflow;
Expand All @@ -4650,11 +4653,11 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty,
goto overflow;
}

if (likely(mas->offset < data_end)) {
if (likely(mas->offset < mas->end)) {
mas->index = pivots[mas->offset] + 1;
again:
mas->offset++;
if (likely(mas->offset < data_end))
if (likely(mas->offset < mas->end))
mas->last = pivots[mas->offset];
else
mas->last = mas->max;
Expand Down Expand Up @@ -4691,7 +4694,6 @@ static void *mas_next_slot(struct ma_state *mas, unsigned long max, bool empty,
goto overflow;

mas->index = mas->last + 1;
/* Node cannot end on NULL, so it's safe to short-cut here */
goto again;
}

Expand Down

0 comments on commit e9c52d8

Please sign in to comment.