Skip to contentSkip to conversation

maple_tree: Use metadata for mas_dead_leaves() walk

PATCH In review Liam Howlett 1 participant 2 messages Jul 12, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 maple_tree: Use metadata for mas_dead_leaves() walk

When walking the dead leaves, use the nodes metadata for the end of the node. This avoids needing to use tricks for BE/LE unions.

Fixes d0aac5e48048 (Maple Tree: add new data structure)
---
 lib/maple_tree.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/maple_tree.c +2 -5
index 14e9ab14c1da..c661fda37665 100644
@@ -5390,15 +5390,12 @@ unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots)
 	enum maple_type type;
 	void *entry;
 	int offset;
+	unsigned end = mas_data_end(mas);
 
-	for (offset = 0; offset < mt_slot_count(mas->node); offset++) {
+	for (offset = 0; offset <= end; offset++) {
 		entry = mas_slot_locked(mas, slots, offset);
 		type = mte_node_type(entry);
 		node = mte_to_node(entry);
-		/* Use both node and type to catch LE & BE metadata */
-		if (!node || !type)
-			break;
-
 		mte_set_node_dead(entry);
 		smp_wmb(); /* Needed for RCU */
 		node->type = type;
Signature · 1 line
2.35.1
#1 lore raw

Please do not apply this patch. More testing is needed. Again, sorry for the noise.

Quoted 33 lines · Liam R. Howlett

When walking the dead leaves, use the nodes metadata for the end of the node. This avoids needing to use tricks for BE/LE unions.

Fixes d0aac5e48048 (Maple Tree: add new data structure)
---
 lib/maple_tree.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/maple_tree.c +2 -5
index 14e9ab14c1da..c661fda37665 100644
@@ -5390,15 +5390,12 @@ unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots)
 	enum maple_type type;
 	void *entry;
 	int offset;
+	unsigned end = mas_data_end(mas);
 
-	for (offset = 0; offset < mt_slot_count(mas->node); offset++) {
+	for (offset = 0; offset <= end; offset++) {
 		entry = mas_slot_locked(mas, slots, offset);
 		type = mte_node_type(entry);
 		node = mte_to_node(entry);
-		/* Use both node and type to catch LE & BE metadata */
-		if (!node || !type)
-			break;
-
 		mte_set_node_dead(entry);
 		smp_wmb(); /* Needed for RCU */
 		node->type = type;
Signature · 1 line
2.35.1