maple_tree: remove conditionals to detect wr_node_store
Subsystems (3)
PATCH 1/1 maple_tree: remove conditionals to detect wr_node_store
From: Sidhartha <[email protected]>
In mas_wr_store_type(), we check if new_end < mt_slots[wr_mas->type]. If this check fails, we know that ,after this, new_end is >= mt_min_slots. Checking this again when we detect a wr_node_store later in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it.
Suggested-by; Wei Yang <[email protected]>
--- lib/maple_tree.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
lib/maple_tree.c +1 -8
@@ -4252,14 +4252,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas)return ; } -if (mte_is_root (mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags &MA_STATE_BULK )) { - mas->store_type = wr_node_store; -return ; - } - - mas->store_type = wr_invalid; -MAS_WARN_ON (mas,1 ); + mas->store_type = wr_node_store; }/**
Signature · 1 line
2.43.0
Quoted 19 lines · Sidhartha Kumar
From: Sidhartha <[email protected]>
In
mas_wr_store_type(), we check ifnew_end< mt_slots[wr_mas->type]. If this check fails, we know that ,after this,new_endis >=mt_min_slots. Checking this again when we detect awr_node_storelater in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it.Suggested-by; Wei Yang <[email protected]>
Signed-off-by Sidhartha Kumar <[email protected]>--- lib/maple_tree.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)lib/maple_tree.c +0
-0
lib/maple_tree.c static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) · line 4256
Quoted 5 lines
lib/maple_tree.c +0
-2@@ -4252,14 +4252,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas)return ; } -if (mte_is_root (mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags &MA_STATE_BULK )) {
Although this will be evaluated as true due to the new_end having at least the minimum data, it points out that MA_STATE_BULK is not being evaluated correctly in the new_end < min case.
That is, we will rebalance if we are in MA_STATE_BULK mode without meeting the sufficient data mark - which is not correct.
Quoted 13 lines
lib/maple_tree.c +1
-6- mas->store_type = wr_node_store; -return ; - } - - mas->store_type = wr_invalid; -MAS_WARN_ON (mas,1 ); + mas->store_type = wr_node_store; }/** Signature · 1 line
2.43.0
Quoted 30 lines · Liam R. Howlett
Quoted 19 lines · Sidhartha Kumar
From: Sidhartha <[email protected]>
In
mas_wr_store_type(), we check ifnew_end< mt_slots[wr_mas->type]. If this check fails, we know that ,after this,new_endis >=mt_min_slots. Checking this again when we detect awr_node_storelater in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it.Suggested-by; Wei Yang <[email protected]>
Signed-off-by Sidhartha Kumar <[email protected]>--- lib/maple_tree.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)lib/maple_tree.c +0
-0lib/maple_tree.c static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) · line 4256
Quoted 5 lines
lib/maple_tree.c +0
-2@@ -4252,14 +4252,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas)return ; } -if (mte_is_root (mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags &MA_STATE_BULK )) {Although this will be evaluated as true due to the
new_endhaving at least the minimum data, it points out thatMA_STATE_BULKis not being evaluated correctly in thenew_end< min case.
Quoted 2 lines
That is, we will rebalance if we are in
MA_STATE_BULKmode without meeting the sufficient data mark - which is not correct.
Reading through this function, it would be much cleaner to return the enum from the function and assign it in the caller.
Quoted 19 lines
Quoted 14 lines
lib/maple_tree.c +1
-6- mas->store_type = wr_node_store; -return ; - } - - mas->store_type = wr_invalid; -MAS_WARN_ON (mas,1 ); + mas->store_type = wr_node_store; }/** Signature · 1 line
2.43.0Signature · 3 lines
maple-tree mailing list [email protected] https://lists.infradead.org/mailman/listinfo/maple-tree
Quoted 20 lines · Sidhartha Kumar
From: Sidhartha <[email protected]>
In
mas_wr_store_type(), we check ifnew_end< mt_slots[wr_mas->type]. If this check fails, we know that ,after this,new_endis >=mt_min_slots. Checking this again when we detect awr_node_storelater in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it.Suggested-by; Wei Yang <[email protected]>
Signed-off-by Sidhartha Kumar <[email protected]>---
lib/maple_tree.c| 9 +--------1 file changed, 1 insertion(+), 8 deletions(-)lib/maple_tree.c +0
-0@@ -4252,14 +4252,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas)return ;
lib/maple_tree.c static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) · line 4262
Quoted 10 lines
lib/maple_tree.c +0
-8} -if (mte_is_root (mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags &MA_STATE_BULK )) { - mas->store_type = wr_node_store; -return ; - } - - mas->store_type = wr_invalid; -MAS_WARN_ON (mas,1 );
If my understanding is correct, here is the only place we assign wr_invalid.
So maybe we can remove this definition?
Quoted 6 lines
lib/maple_tree.c +1
-0+ mas->store_type = wr_node_store; }/** Signature · 1 line
2.43.0
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 34 lines · Wei Yang
Quoted 20 lines · Sidhartha Kumar
From: Sidhartha <[email protected]>
In
mas_wr_store_type(), we check ifnew_end< mt_slots[wr_mas->type]. If this check fails, we know that ,after this,new_endis >=mt_min_slots. Checking this again when we detect awr_node_storelater in the function is reduntant. Because this check is part of an OR statement, the statement will always evaluate to true, therefore we can just get rid of it.Suggested-by; Wei Yang <[email protected]>
Signed-off-by Sidhartha Kumar <[email protected]>---
lib/maple_tree.c| 9 +--------1 file changed, 1 insertion(+), 8 deletions(-)lib/maple_tree.c +0
-0@@ -4252,14 +4252,7 @@ static inline void mas_wr_store_type(struct ma_wr_state *wr_mas)return ;lib/maple_tree.c static inline void mas_wr_store_type(struct ma_wr_state *wr_mas) · line 4262
Quoted 10 lines
lib/maple_tree.c +0
-8} -if (mte_is_root (mas->node) || (new_end >= mt_min_slots[wr_mas->type]) || - (mas->mas_flags &MA_STATE_BULK )) { - mas->store_type = wr_node_store; -return ; - } - - mas->store_type = wr_invalid; -MAS_WARN_ON (mas,1 );If my understanding is correct, here is the only place we assign
wr_invalid.
Quoted 1 line
So maybe we can remove this definition?
No. This needs to exist to catch incorrect uses of the API, at the very least. I am not pleased that we aren't able to fall through to setting this to catch missed settings with this code today.
We are now just assuming we got things right. Any mistakes will show up as an out-of-memory issues with writes to the tree. It will be much harder to track down what went wrong.
Currently it is set in the header as the default store type and should remain for that use, at the very least.
Quoted 11 lines
Quoted 7 lines
lib/maple_tree.c +1
-0+ mas->store_type = wr_node_store; }/** Signature · 1 line
2.43.0Signature · 2 lines
Wei Yang Help you, Help me