* [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing
@ 2025-08-12 16:21 Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 2/3] maple_tree: Use kfree_rcu in ma_free_rcu Pedro Falcato
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Pedro Falcato @ 2025-08-12 16:21 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Matthew Wilcox
Cc: maple-tree, linux-mm, linux-kernel, Sidhartha Kumar,
Pedro Falcato
liburcu doesn't have kfree_rcu (or anything similar). Despite that, we
can hack around it in a trivial fashion, by adding a wrapper.
This wrapper only works for maple_nodes, and not anything else (due to
us not being able to know rcu_head offsets in any way), and thus we take
advantage of the type checking to avoid future silent breakage.
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
v2:
- Move kfree_rcu hack to maple-shared.h, to fix userland VMA tests, per
Lorenzo
tools/testing/shared/maple-shared.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/shared/maple-shared.h b/tools/testing/shared/maple-shared.h
index dc4d30f3860b..572cd2580123 100644
--- a/tools/testing/shared/maple-shared.h
+++ b/tools/testing/shared/maple-shared.h
@@ -9,5 +9,20 @@
#include <stdlib.h>
#include <time.h>
#include "linux/init.h"
+#include <linux/maple_tree.h>
+
+static inline void free_node(struct rcu_head *head)
+{
+ struct maple_node *node = container_of(head, struct maple_node, rcu);
+
+ free(node);
+}
+
+static inline void kfree_rcu_node(struct maple_node *node)
+{
+ call_rcu(&node->rcu, free_node);
+}
+
+#define kfree_rcu(ptr, memb) kfree_rcu_node(ptr)
#endif /* __MAPLE_SHARED_H__ */
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] maple_tree: Use kfree_rcu in ma_free_rcu
2025-08-12 16:21 [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Pedro Falcato
@ 2025-08-12 16:21 ` Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 3/3] maple_tree: Replace mt_free_one() with kfree() Pedro Falcato
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Pedro Falcato @ 2025-08-12 16:21 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Matthew Wilcox
Cc: maple-tree, linux-mm, linux-kernel, Sidhartha Kumar,
Pedro Falcato
kfree_rcu is an optimized version of call_rcu + kfree. It used to not be
possible to call it on non-kmalloc objects, but this restriction was
lifted ever since SLOB was dropped from the kernel, and since commit
6c6c47b063b5 ("mm, slab: call kvfree_rcu_barrier() from kmem_cache_destroy()").
Thus, replace call_rcu + mt_free_rcu with kfree_rcu.
Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
lib/maple_tree.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index b4ee2d29d7a9..91da2d9d00c3 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -191,13 +191,6 @@ static inline void mt_free_bulk(size_t size, void __rcu **nodes)
kmem_cache_free_bulk(maple_node_cache, size, (void **)nodes);
}
-static void mt_free_rcu(struct rcu_head *head)
-{
- struct maple_node *node = container_of(head, struct maple_node, rcu);
-
- kmem_cache_free(maple_node_cache, node);
-}
-
/*
* ma_free_rcu() - Use rcu callback to free a maple node
* @node: The node to free
@@ -208,7 +201,7 @@ static void mt_free_rcu(struct rcu_head *head)
static void ma_free_rcu(struct maple_node *node)
{
WARN_ON(node->parent != ma_parent_ptr(node));
- call_rcu(&node->rcu, mt_free_rcu);
+ kfree_rcu(node, rcu);
}
static void mt_set_height(struct maple_tree *mt, unsigned char height)
@@ -5281,7 +5274,7 @@ static void mt_free_walk(struct rcu_head *head)
mt_free_bulk(node->slot_len, slots);
free_leaf:
- mt_free_rcu(&node->rcu);
+ mt_free_one(node);
}
static inline void __rcu **mte_destroy_descend(struct maple_enode **enode,
@@ -5365,7 +5358,7 @@ static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt,
free_leaf:
if (free)
- mt_free_rcu(&node->rcu);
+ mt_free_one(node);
else
mt_clear_meta(mt, node, node->type);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] maple_tree: Replace mt_free_one() with kfree()
2025-08-12 16:21 [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 2/3] maple_tree: Use kfree_rcu in ma_free_rcu Pedro Falcato
@ 2025-08-12 16:21 ` Pedro Falcato
2025-08-12 19:41 ` [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Liam R. Howlett
2025-08-15 15:11 ` Liam R. Howlett
3 siblings, 0 replies; 6+ messages in thread
From: Pedro Falcato @ 2025-08-12 16:21 UTC (permalink / raw)
To: Andrew Morton, Liam R. Howlett, Matthew Wilcox
Cc: maple-tree, linux-mm, linux-kernel, Sidhartha Kumar,
Pedro Falcato
kfree() is a little shorter and works with kmem_cache_alloc'd pointers
too. Also lets us remove one more helper.
Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
lib/maple_tree.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 91da2d9d00c3..3b756f1b67fd 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -181,11 +181,6 @@ static inline int mt_alloc_bulk(gfp_t gfp, size_t size, void **nodes)
return kmem_cache_alloc_bulk(maple_node_cache, gfp, size, nodes);
}
-static inline void mt_free_one(struct maple_node *node)
-{
- kmem_cache_free(maple_node_cache, node);
-}
-
static inline void mt_free_bulk(size_t size, void __rcu **nodes)
{
kmem_cache_free_bulk(maple_node_cache, size, (void **)nodes);
@@ -5274,7 +5269,7 @@ static void mt_free_walk(struct rcu_head *head)
mt_free_bulk(node->slot_len, slots);
free_leaf:
- mt_free_one(node);
+ kfree(node);
}
static inline void __rcu **mte_destroy_descend(struct maple_enode **enode,
@@ -5358,7 +5353,7 @@ static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt,
free_leaf:
if (free)
- mt_free_one(node);
+ kfree(node);
else
mt_clear_meta(mt, node, node->type);
}
@@ -5585,7 +5580,7 @@ void mas_destroy(struct ma_state *mas)
mt_free_bulk(count, (void __rcu **)&node->slot[1]);
total -= count;
}
- mt_free_one(ma_mnode_ptr(node));
+ kfree(ma_mnode_ptr(node));
total--;
}
@@ -6630,7 +6625,7 @@ static void mas_dup_free(struct ma_state *mas)
}
node = mte_to_node(mas->node);
- mt_free_one(node);
+ kfree(node);
}
/*
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing
2025-08-12 16:21 [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 2/3] maple_tree: Use kfree_rcu in ma_free_rcu Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 3/3] maple_tree: Replace mt_free_one() with kfree() Pedro Falcato
@ 2025-08-12 19:41 ` Liam R. Howlett
2025-08-15 15:11 ` Liam R. Howlett
3 siblings, 0 replies; 6+ messages in thread
From: Liam R. Howlett @ 2025-08-12 19:41 UTC (permalink / raw)
To: Pedro Falcato
Cc: Andrew Morton, Matthew Wilcox, maple-tree, linux-mm, linux-kernel,
Sidhartha Kumar, Vlastimil Babka
* Pedro Falcato <pfalcato@suse.de> [250812 12:21]:
> liburcu doesn't have kfree_rcu (or anything similar). Despite that, we
> can hack around it in a trivial fashion, by adding a wrapper.
>
> This wrapper only works for maple_nodes, and not anything else (due to
> us not being able to know rcu_head offsets in any way), and thus we take
> advantage of the type checking to avoid future silent breakage.
>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
> ---
> v2:
> - Move kfree_rcu hack to maple-shared.h, to fix userland VMA tests, per
> Lorenzo
This is going to cause issues with sheaves that's probably going to go
through vlastimil's branch.
We're going to either get this to go through there with some
modification to avoid conflict, or we're going to hold off for now.
>
> tools/testing/shared/maple-shared.h | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/tools/testing/shared/maple-shared.h b/tools/testing/shared/maple-shared.h
> index dc4d30f3860b..572cd2580123 100644
> --- a/tools/testing/shared/maple-shared.h
> +++ b/tools/testing/shared/maple-shared.h
> @@ -9,5 +9,20 @@
> #include <stdlib.h>
> #include <time.h>
> #include "linux/init.h"
> +#include <linux/maple_tree.h>
> +
> +static inline void free_node(struct rcu_head *head)
> +{
> + struct maple_node *node = container_of(head, struct maple_node, rcu);
> +
> + free(node);
> +}
> +
> +static inline void kfree_rcu_node(struct maple_node *node)
> +{
> + call_rcu(&node->rcu, free_node);
> +}
> +
> +#define kfree_rcu(ptr, memb) kfree_rcu_node(ptr)
>
> #endif /* __MAPLE_SHARED_H__ */
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing
2025-08-12 16:21 [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Pedro Falcato
` (2 preceding siblings ...)
2025-08-12 19:41 ` [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Liam R. Howlett
@ 2025-08-15 15:11 ` Liam R. Howlett
2025-08-15 17:06 ` Pedro Falcato
3 siblings, 1 reply; 6+ messages in thread
From: Liam R. Howlett @ 2025-08-15 15:11 UTC (permalink / raw)
To: Andrew Morton, Vlastimil Babka
Cc: Pedro Falcato, Matthew Wilcox, maple-tree, linux-mm, linux-kernel,
Sidhartha Kumar
* Pedro Falcato <pfalcato@suse.de> [250812 12:21]:
> liburcu doesn't have kfree_rcu (or anything similar). Despite that, we
> can hack around it in a trivial fashion, by adding a wrapper.
>
> This wrapper only works for maple_nodes, and not anything else (due to
> us not being able to know rcu_head offsets in any way), and thus we take
> advantage of the type checking to avoid future silent breakage.
>
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
Andrew,
Please drop this patch set. We will have it go through Vlastimil's tree
to avoid conflicts with other work and to maintain the userspace testing
in mm-new while that happens.
Thanks,
Liam
> ---
> v2:
> - Move kfree_rcu hack to maple-shared.h, to fix userland VMA tests, per
> Lorenzo
>
> tools/testing/shared/maple-shared.h | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/tools/testing/shared/maple-shared.h b/tools/testing/shared/maple-shared.h
> index dc4d30f3860b..572cd2580123 100644
> --- a/tools/testing/shared/maple-shared.h
> +++ b/tools/testing/shared/maple-shared.h
> @@ -9,5 +9,20 @@
> #include <stdlib.h>
> #include <time.h>
> #include "linux/init.h"
> +#include <linux/maple_tree.h>
> +
> +static inline void free_node(struct rcu_head *head)
> +{
> + struct maple_node *node = container_of(head, struct maple_node, rcu);
> +
> + free(node);
> +}
> +
> +static inline void kfree_rcu_node(struct maple_node *node)
> +{
> + call_rcu(&node->rcu, free_node);
> +}
> +
> +#define kfree_rcu(ptr, memb) kfree_rcu_node(ptr)
>
> #endif /* __MAPLE_SHARED_H__ */
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing
2025-08-15 15:11 ` Liam R. Howlett
@ 2025-08-15 17:06 ` Pedro Falcato
0 siblings, 0 replies; 6+ messages in thread
From: Pedro Falcato @ 2025-08-15 17:06 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton, Vlastimil Babka, Matthew Wilcox,
maple-tree, linux-mm, linux-kernel, Sidhartha Kumar
On Fri, Aug 15, 2025 at 11:11:30AM -0400, Liam R. Howlett wrote:
> * Pedro Falcato <pfalcato@suse.de> [250812 12:21]:
> > liburcu doesn't have kfree_rcu (or anything similar). Despite that, we
> > can hack around it in a trivial fashion, by adding a wrapper.
> >
> > This wrapper only works for maple_nodes, and not anything else (due to
> > us not being able to know rcu_head offsets in any way), and thus we take
> > advantage of the type checking to avoid future silent breakage.
> >
> > Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> > Signed-off-by: Pedro Falcato <pfalcato@suse.de>
>
>
> Andrew,
>
> Please drop this patch set. We will have it go through Vlastimil's tree
> to avoid conflicts with other work and to maintain the userspace testing
> in mm-new while that happens.
In case this helps, Andrew, it's maple_tree-use-kfree_rcu-in-ma_free_rcu.patch
and testing-radix-tree-maple-hack-around-kfree_rcu-not-existing.patch in your series file.
(Yes, I should have used a cover letter here, it would've made it easier to
manage, my mistake)
--
Pedro
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-15 17:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 16:21 [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 2/3] maple_tree: Use kfree_rcu in ma_free_rcu Pedro Falcato
2025-08-12 16:21 ` [PATCH v2 3/3] maple_tree: Replace mt_free_one() with kfree() Pedro Falcato
2025-08-12 19:41 ` [PATCH v2 1/3] testing/radix-tree/maple: Hack around kfree_rcu not existing Liam R. Howlett
2025-08-15 15:11 ` Liam R. Howlett
2025-08-15 17:06 ` Pedro Falcato
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).