Skip to contentSkip to conversation

Reduce the space to be cleared for maple_big_node

PATCH In review Wei Yang 2 participants 6 messages Sep 8, 2024 – Sep 25, 2024

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

v2 cover Reduce the space to be cleared for maple_big_node

Found current code may clear maple_big_node redundantly.

First we define a filed parent, which is never used. After removing this, we reduce the size of memory to be clear on memset.

Then mast_fill_bnode clear part of the structure twice, since slot and gap shares some space. By clearing the whole structure, we can avoid it.

Wei Yang (2):
maple_tree: remove maple_big_node.parent
maple_tree: memset maple_big_node as a whole

 lib/maple_tree.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 maple_tree: remove maple_big_node.parent

The member parent of maple_big_node is never used.

Let's remove it which could reduce the number of space to be cleared on memset.

CC Liam R. Howlett <[email protected]>
---
 lib/maple_tree.c | 1 -
 1 file changed, 1 deletion(-)
lib/maple_tree.c +0 -1
index 4e08dd5e391b..c3370c7449c2 100644
@@ -120,7 +120,6 @@ static const unsigned char mt_min_slots[] = {
 #define MAPLE_BIG_NODE_GAPS	(MAPLE_ARANGE64_SLOTS * 2 + 1)
 
 struct maple_big_node {
-	struct maple_pnode *parent;
 	unsigned long pivot[MAPLE_BIG_NODE_SLOTS - 1];
 	union {
 		struct maple_enode *slot[MAPLE_BIG_NODE_SLOTS];
Signature · 1 line
2.34.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] maple_tree: remove maple_big_node.parent

Quoted 7 lines · Wei Yang

The member parent of maple_big_node is never used.

Let's remove it which could reduce the number of space to be cleared on memset.

CC Liam R. Howlett <[email protected]>
Quoted 19 lines
---
 lib/maple_tree.c | 1 -
 1 file changed, 1 deletion(-)
lib/maple_tree.c +0 -1
index 4e08dd5e391b..c3370c7449c2 100644
@@ -120,7 +120,6 @@ static const unsigned char mt_min_slots[] = {
 #define MAPLE_BIG_NODE_GAPS	(MAPLE_ARANGE64_SLOTS * 2 + 1)
 
 struct maple_big_node {
-	struct maple_pnode *parent;
 	unsigned long pivot[MAPLE_BIG_NODE_SLOTS - 1];
 	union {
 		struct maple_enode *slot[MAPLE_BIG_NODE_SLOTS];
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 2/2 maple_tree: memset maple_big_node as a whole

In reply to Wei Yang

In function mast_fill_bnode(), we first clear some fields of maple_big_node and set the 'type' unconditionally before return. This means we won't leverage any information in maple_big_node and it is safe to clear the whole structure.

In maple_big_node, we define slot and padding/gap in a union. And based on current definition of MAPLE_BIG_NODE_SLOTS/GAPS, padding is always less than slot and part of the gap is overlapped by slot.

For example on 64bit system:

MAPLE_BIG_NODE_SLOT is 34
MAPLE_BIG_NODE_GAP is 21

With this knowledge, current code may clear some space by twice. And this could be avoid by clearing the structure as a whole.

CC Liam R. Howlett <[email protected]>

---
v2: correct the change log on clearing all maple_big_node currently

---
 lib/maple_tree.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
lib/maple_tree.c +1 -4
index c3370c7449c2..b459fe1a3ebe 100644
@@ -3134,10 +3134,7 @@ static inline void mast_fill_bnode(struct maple_subtree_state *mast,
 	bool cp = true;
 	unsigned char split;
 
-	memset(mast->bn->gap, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->gap));
-	memset(mast->bn->slot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->slot));
-	memset(mast->bn->pivot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->pivot));
-	mast->bn->b_end = 0;
+	memset(mast->bn, 0, sizeof(struct maple_big_node));
 
 	if (mte_is_root(mas->node)) {
 		cp = false;
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] maple_tree: memset maple_big_node as a whole

Quoted 11 lines · Wei Yang

In function mast_fill_bnode(), we first clear some fields of maple_big_node and set the 'type' unconditionally before return. This means we won't leverage any information in maple_big_node and it is safe to clear the whole structure.

In maple_big_node, we define slot and padding/gap in a union. And based on current definition of MAPLE_BIG_NODE_SLOTS/GAPS, padding is always less than slot and part of the gap is overlapped by slot.

For example on 64bit system:

Quoted 8 lines

MAPLE_BIG_NODE_SLOT is 34
MAPLE_BIG_NODE_GAP is 21

With this knowledge, current code may clear some space by twice. And this could be avoid by clearing the structure as a whole.

CC Liam R. Howlett <[email protected]>
Quoted 3 lines

---
v2: correct the change log on clearing all maple_big_node currently

Thanks!

Quoted 23 lines
---
 lib/maple_tree.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
lib/maple_tree.c +1 -4
index c3370c7449c2..b459fe1a3ebe 100644
@@ -3134,10 +3134,7 @@ static inline void mast_fill_bnode(struct maple_subtree_state *mast,
 	bool cp = true;
 	unsigned char split;
 
-	memset(mast->bn->gap, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->gap));
-	memset(mast->bn->slot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->slot));
-	memset(mast->bn->pivot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->pivot));
-	mast->bn->b_end = 0;
+	memset(mast->bn, 0, sizeof(struct maple_big_node));
 
 	if (mte_is_root(mas->node)) {
 		cp = false;
Signature · 1 line
2.34.1
author
#5 lore raw
In reply to Wei Yang

Hi, Andrew,

I don't see the notification on picking this in unstable/stable.

May I ask would it be picked up?

Quoted 17 lines · Wei Yang

Found current code may clear maple_big_node redundantly.

First we define a filed parent, which is never used. After removing this, we reduce the size of memory to be clear on memset.

Then mast_fill_bnode clear part of the structure twice, since slot and gap shares some space. By clearing the whole structure, we can avoid it.

Wei Yang (2):
maple_tree: remove maple_big_node.parent
maple_tree: memset maple_big_node as a whole

lib/maple_tree.c | 6 +-----

1 file changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
2.34.1
Signature · 2 lines
Wei Yang
Help you, Help me