Skip to content

Commit 432af5c

Browse files
howlettakpm00
authored andcommitted
maple_tree: clean up mas_wr_append()
Avoid setting the variables until necessary, and actually use the variables where applicable. Introducing a variable for the slots array avoids spanning multiple lines. Add the missing argument to the documentation. Use the node type when setting the metadata instead of blindly assuming the type. Finally, add a trace point to the function for successful store. Link: https://lkml.kernel.org/r/20230819004356.1454718-3-Liam.Howlett@oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8f9ff2d commit 432af5c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/maple_tree.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,7 @@ static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas)
41064106
/*
41074107
* mas_wr_append: Attempt to append
41084108
* @wr_mas: the maple write state
4109+
* @new_end: The end of the node after the modification
41094110
*
41104111
* This is currently unsafe in rcu mode since the end of the node may be cached
41114112
* by readers while the node contents may be updated which could result in
@@ -4114,49 +4115,54 @@ static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas)
41144115
* Return: True if appended, false otherwise
41154116
*/
41164117
static inline bool mas_wr_append(struct ma_wr_state *wr_mas,
4117-
unsigned char new_end)
4118+
unsigned char new_end)
41184119
{
4119-
unsigned char end = wr_mas->node_end;
4120-
struct ma_state *mas = wr_mas->mas;
4121-
unsigned char node_pivots = mt_pivots[wr_mas->type];
4120+
struct ma_state *mas;
4121+
void __rcu **slots;
4122+
unsigned char end;
41224123

4124+
mas = wr_mas->mas;
41234125
if (mt_in_rcu(mas->tree))
41244126
return false;
41254127

41264128
if (mas->offset != wr_mas->node_end)
41274129
return false;
41284130

4129-
if (new_end < node_pivots) {
4131+
end = wr_mas->node_end;
4132+
if (mas->offset != end)
4133+
return false;
4134+
4135+
if (new_end < mt_pivots[wr_mas->type]) {
41304136
wr_mas->pivots[new_end] = wr_mas->pivots[end];
4131-
ma_set_meta(wr_mas->node, maple_leaf_64, 0, new_end);
4137+
ma_set_meta(wr_mas->node, wr_mas->type, 0, new_end);
41324138
}
41334139

4134-
if (new_end == wr_mas->node_end + 1) {
4140+
slots = wr_mas->slots;
4141+
if (new_end == end + 1) {
41354142
if (mas->last == wr_mas->r_max) {
41364143
/* Append to end of range */
4137-
rcu_assign_pointer(wr_mas->slots[new_end],
4138-
wr_mas->entry);
4144+
rcu_assign_pointer(slots[new_end], wr_mas->entry);
41394145
wr_mas->pivots[end] = mas->index - 1;
41404146
mas->offset = new_end;
41414147
} else {
41424148
/* Append to start of range */
4143-
rcu_assign_pointer(wr_mas->slots[new_end],
4144-
wr_mas->content);
4149+
rcu_assign_pointer(slots[new_end], wr_mas->content);
41454150
wr_mas->pivots[end] = mas->last;
4146-
rcu_assign_pointer(wr_mas->slots[end], wr_mas->entry);
4151+
rcu_assign_pointer(slots[end], wr_mas->entry);
41474152
}
41484153
} else {
41494154
/* Append to the range without touching any boundaries. */
4150-
rcu_assign_pointer(wr_mas->slots[new_end], wr_mas->content);
4155+
rcu_assign_pointer(slots[new_end], wr_mas->content);
41514156
wr_mas->pivots[end + 1] = mas->last;
4152-
rcu_assign_pointer(wr_mas->slots[end + 1], wr_mas->entry);
4157+
rcu_assign_pointer(slots[end + 1], wr_mas->entry);
41534158
wr_mas->pivots[end] = mas->index - 1;
41544159
mas->offset = end + 1;
41554160
}
41564161

41574162
if (!wr_mas->content || !wr_mas->entry)
41584163
mas_update_gap(mas);
41594164

4165+
trace_ma_write(__func__, mas, new_end, wr_mas->entry);
41604166
return true;
41614167
}
41624168

0 commit comments

Comments
 (0)