Skip to contentSkip to conversation

cleanup maple_alloc related functions

PATCH Applied Wei Yang 1 participant 4 messages Oct 15, 2024

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

v2 cover cleanup maple_alloc related functions

Patch 1/2: some fields of the maple_alloc is not necessary to change, so we
can skip some operations
Patch 3: a valid alloc check could be hide in current code, so we don't need
to do a separate check

v2: refine the change log of patch 3.

Wei Yang (3):
maple_tree: clear request_count for new allocated one
maple_tree: total is not changed for nomem_one case
maple_tree: simplify mas_push_node()

 lib/maple_tree.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/3 maple_tree: clear request_count for new allocated one

If this is not a new allocated one, the request_count has already been cleared in mas_set_alloc_req().

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/maple_tree.c +1 -1
index 6047c74c5a31..31899e853c1e 100644
@@ -1250,11 +1250,11 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp)
 
 		mas->alloc = node;
 		node->total = ++allocated;
+		node->request_count = 0;
 		requested--;
 	}
 
 	node = mas->alloc;
-	node->request_count = 0;
 	while (requested) {
 		max_req = MAPLE_ALLOC_SLOTS - node->node_count;
 		slots = (void **)&node->slot[node->node_count];
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/3 maple_tree: total is not changed for nomem_one case

In reply to Wei Yang

If it jumps to nomem_one, the total allocated number is not changed. So we don't need to adjust it.

For the nomem_bulk case, we know there is a valid mas->alloc. So we don't need to do the check.

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>
---
 lib/maple_tree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/maple_tree.c +1 -2
index 31899e853c1e..ab398461754b 100644
@@ -1279,10 +1279,9 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp)
 nomem_bulk:
 	/* Clean up potential freed allocations on bulk failure */
 	memset(slots, 0, max_req * sizeof(unsigned long));
+	mas->alloc->total = allocated;
 nomem_one:
 	mas_set_alloc_req(mas, requested);
-	if (mas->alloc && !(((unsigned long)mas->alloc & 0x1)))
-		mas->alloc->total = allocated;
 	mas_set_err(mas, -ENOMEM);
 }
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 3/3 maple_tree: simplify mas_push_node()

In reply to Wei Yang

When count is not 0, we know head is valid. So we can put the assignment in if (count) instead of checking the head pointer again.

Also count represents current total, we can assign the new total by increasing the count by one.

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

---
v2: refine the change log

---
 lib/maple_tree.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
lib/maple_tree.c +7 -9
index ab398461754b..afb59bb6a641 100644
@@ -1192,19 +1192,17 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_node *used)
 
 	reuse->request_count = 0;
 	reuse->node_count = 0;
-	if (count && (head->node_count < MAPLE_ALLOC_SLOTS)) {
-		head->slot[head->node_count++] = reuse;
-		head->total++;
-		goto done;
-	}
-
-	reuse->total = 1;
-	if ((head) && !((unsigned long)head & 0x1)) {
+	if (count) {
+		if (head->node_count < MAPLE_ALLOC_SLOTS) {
+			head->slot[head->node_count++] = reuse;
+			head->total++;
+			goto done;
+		}
 		reuse->slot[0] = head;
 		reuse->node_count = 1;
-		reuse->total += head->total;
 	}
 
+	reuse->total = count + 1;
 	mas->alloc = reuse;
 done:
 	if (requested > 1)
Signature · 1 line
2.34.1