diff mbox series

[v4,09/10] maple_tree: Preserve the tree attributes when destroying maple tree

Message ID 20231009090320.64565-10-zhangpeng.00@bytedance.com (mailing list archive)
State New
Headers show
Series Introduce __mt_dup() to improve the performance of fork() | expand

Commit Message

Peng Zhang Oct. 9, 2023, 9:03 a.m. UTC
When destroying maple tree, preserve its attributes and then turn it
into an empty tree. This allows it to be reused without needing to be
reinitialized.

Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peng Zhang Oct. 11, 2023, 3:42 p.m. UTC | #1
在 2023/10/9 17:03, Peng Zhang 写道:
> When destroying maple tree, preserve its attributes and then turn it
> into an empty tree. This allows it to be reused without needing to be
> reinitialized.
> 
> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
> ---
>   lib/maple_tree.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index d5544382ff15..1745242092fb 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -6775,7 +6775,7 @@ void __mt_destroy(struct maple_tree *mt)
>   	if (xa_is_node(root))
>   		mte_destroy_walk(root, mt);
>   
> -	mt->ma_flags = 0;
> +	mt->ma_flags = mt_attr(mt)If I put everything into exit_mmap() for handling, this patch would
not be necessary. But I think this patch is reasonable as it simply
deletes all elements without requiring us to reinitialize the tree.
What do you think?
>   }
>   EXPORT_SYMBOL_GPL(__mt_destroy);
>
Liam R. Howlett Oct. 11, 2023, 3:48 p.m. UTC | #2
* Peng Zhang <zhangpeng.00@bytedance.com> [231011 11:42]:
> 
> 
> 在 2023/10/9 17:03, Peng Zhang 写道:
> > When destroying maple tree, preserve its attributes and then turn it
> > into an empty tree. This allows it to be reused without needing to be
> > reinitialized.
> > 
> > Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
> > ---
> >   lib/maple_tree.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> > index d5544382ff15..1745242092fb 100644
> > --- a/lib/maple_tree.c
> > +++ b/lib/maple_tree.c
> > @@ -6775,7 +6775,7 @@ void __mt_destroy(struct maple_tree *mt)
> >   	if (xa_is_node(root))
> >   		mte_destroy_walk(root, mt);
> > -	mt->ma_flags = 0;
> > +	mt->ma_flags = mt_attr(mt)If I put everything into exit_mmap() for handling, this patch would
> not be necessary. But I think this patch is reasonable as it simply
> deletes all elements without requiring us to reinitialize the tree.
> What do you think?

Willy and I had debated if we should do what you have here a long time
ago.  There was an issue with the next exit_mmap() that would not have
arose with this change, which I was going to make before it was made
unnecessary due to other changes in the caller.

In the strict thinking of a destroy() call, I would expect the flags to
not be spared, but doing this allows for an easy way to clear out a tree
and resuse it as you have said.  I'm happy to keep this patch.


> >   }
> >   EXPORT_SYMBOL_GPL(__mt_destroy);
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index d5544382ff15..1745242092fb 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -6775,7 +6775,7 @@  void __mt_destroy(struct maple_tree *mt)
 	if (xa_is_node(root))
 		mte_destroy_walk(root, mt);
 
-	mt->ma_flags = 0;
+	mt->ma_flags = mt_attr(mt);
 }
 EXPORT_SYMBOL_GPL(__mt_destroy);