Skip to contentSkip to conversation

maple_tree-use-vacant-nodes-to-reduce-worst-case-allocations.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message May 12, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: maple_tree: use vacant nodes to reduce worst case allocations
has been removed from the -mm tree. Its filename was
maple_tree-use-vacant-nodes-to-reduce-worst-case-allocations.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Sidhartha Kumar <[email protected]>
Subject: maple_tree: use vacant nodes to reduce worst case allocations
Date: Thu, 10 Apr 2025 19:14:43 +0000

In order to determine the store type for a maple tree operation, a walk of the tree is done through mas_wr_walk(). This function descends the tree until a spanning write is detected or we reach a leaf node. While descending, keep track of the height at which we encounter a node with available space. This is done by checking if mas->end is less than the number of slots a given node type can fit.

Now that the height of the vacant node is tracked, we can use the difference between the height of the tree and the height of the vacant node to know how many levels we will have to propagate creating new nodes. Update mas_prealloc_calc() to consider the vacant height and reduce the number of worst-case allocations.

Rebalancing and spanning stores are not supported and fall back to using the full height of the tree for allocations.

Update preallocation testing assertions to take into account vacant height.

---

 include/linux/maple_tree.h       |    2 
 lib/maple_tree.c                 |   13 +++-
 tools/testing/radix-tree/maple.c |   79 ++++++++++++++++++++++++++---
 3 files changed, 82 insertions(+), 12 deletions(-)
include/linux/maple_tree.h renamed from include/linux/maple_tree.h~maple_tree-use-vacant-nodes-to-reduce-worst-case-allocations +2 -0
@@ -463,6 +463,7 @@ struct ma_wr_state {
 	void __rcu **slots;		/* mas->node->slots pointer */
 	void *entry;			/* The entry to write */
 	void *content;			/* The existing entry that is being overwritten */
+	unsigned char vacant_height;	/* Height of lowest node with free space */
 };
 
 #define mas_lock(mas)           spin_lock(&((mas)->tree->ma_lock))
@@ -498,6 +499,7 @@ struct ma_wr_state {
 		.mas = ma_state,					\
 		.content = NULL,					\
 		.entry = wr_entry,					\
+		.vacant_height = 0					\
 	}
 
 #define MA_TOPIARY(name, tree)						\
lib/maple_tree.c renamed from lib/maple_tree.c~maple_tree-use-vacant-nodes-to-reduce-worst-case-allocations +9 -4
@@ -3537,6 +3537,9 @@ static bool mas_wr_walk(struct ma_wr_sta
 		if (ma_is_leaf(wr_mas->type))
 			return true;
 
+		if (mas->end < mt_slots[wr_mas->type] - 1)
+			wr_mas->vacant_height = mas->depth + 1;
+
 		mas_wr_walk_traverse(wr_mas);
 	}
 
@@ -4152,7 +4155,9 @@ set_content:
 static inline int mas_prealloc_calc(struct ma_wr_state *wr_mas, void *entry)
 {
 	struct ma_state *mas = wr_mas->mas;
-	int ret = mas_mt_height(mas) * 3 + 1;
+	unsigned char height = mas_mt_height(mas);
+	int ret = height * 3 + 1;
+	unsigned char delta = height - wr_mas->vacant_height;
 
 	switch (mas->store_type) {
 	case wr_invalid:
@@ -4170,13 +4175,13 @@ static inline int mas_prealloc_calc(stru
 			ret = 0;
 		break;
 	case wr_spanning_store:
-		ret =  mas_mt_height(mas) * 3 + 1;
+		WARN_ON_ONCE(ret != height * 3 + 1);
 		break;
 	case wr_split_store:
-		ret =  mas_mt_height(mas) * 2 + 1;
+		ret = delta * 2 + 1;
 		break;
 	case wr_rebalance:
-		ret =  mas_mt_height(mas) * 2 - 1;
+		ret = height * 2 + 1;
 		break;
 	case wr_node_store:
 		ret = mt_in_rcu(mas->tree) ? 1 : 0;
tools/testing/radix-tree/maple.c renamed from tools/testing/radix-tree/maple.c~maple_tree-use-vacant-nodes-to-reduce-worst-case-allocations +71 -8

145 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are