mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] fs: avoid calls to legitimize_links() if possible
@ 2025-11-10 10:05 Mateusz Guzik
  2025-11-10 11:30 ` Jan Kara
  2025-11-11  9:47 ` Christian Brauner
  0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-10 10:05 UTC (permalink / raw)
  To: viro; +Cc: brauner, jack, linux-kernel, linux-fsdevel, Mateusz Guzik

The routine is always called towards the end of lookup.

According to bpftrace on my boxen and boxen of people I asked, the depth
count is almost always 0, thus the call can be avoided in the common case.

one-liner:
bpftrace -e 'kprobe:legitimize_links { @[((struct nameidata *)arg0)->depth] = count(); }'

sample results from few minutes of tracing:
@[1]: 59
@[0]: 147236

@[2]: 1
@[1]: 12087
@[0]: 5926235

And of course the venerable kernel build:
@[1]: 3563
@[0]: 6625425

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---

v2:
- drop 'noinline'
- spell out the check at call sites

verified no change in asm

 fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 2a112b2c0951..0de0344a2ab2 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -882,7 +882,7 @@ static bool try_to_unlazy(struct nameidata *nd)
 
 	BUG_ON(!(nd->flags & LOOKUP_RCU));
 
-	if (unlikely(!legitimize_links(nd)))
+	if (unlikely(nd->depth && !legitimize_links(nd)))
 		goto out1;
 	if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
 		goto out;
@@ -917,7 +917,7 @@ static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry)
 	int res;
 	BUG_ON(!(nd->flags & LOOKUP_RCU));
 
-	if (unlikely(!legitimize_links(nd)))
+	if (unlikely(nd->depth && !legitimize_links(nd)))
 		goto out2;
 	res = __legitimize_mnt(nd->path.mnt, nd->m_seq);
 	if (unlikely(res)) {
-- 
2.48.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] fs: avoid calls to legitimize_links() if possible
  2025-11-10 10:05 [PATCH v2] fs: avoid calls to legitimize_links() if possible Mateusz Guzik
@ 2025-11-10 11:30 ` Jan Kara
  2025-11-11  9:47 ` Christian Brauner
  1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2025-11-10 11:30 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: viro, brauner, jack, linux-kernel, linux-fsdevel

On Mon 10-11-25 11:05:03, Mateusz Guzik wrote:
> The routine is always called towards the end of lookup.
> 
> According to bpftrace on my boxen and boxen of people I asked, the depth
> count is almost always 0, thus the call can be avoided in the common case.
> 
> one-liner:
> bpftrace -e 'kprobe:legitimize_links { @[((struct nameidata *)arg0)->depth] = count(); }'
> 
> sample results from few minutes of tracing:
> @[1]: 59
> @[0]: 147236
> 
> @[2]: 1
> @[1]: 12087
> @[0]: 5926235
> 
> And of course the venerable kernel build:
> @[1]: 3563
> @[0]: 6625425
> 
> Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> 
> v2:
> - drop 'noinline'
> - spell out the check at call sites
> 
> verified no change in asm
> 
>  fs/namei.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 2a112b2c0951..0de0344a2ab2 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -882,7 +882,7 @@ static bool try_to_unlazy(struct nameidata *nd)
>  
>  	BUG_ON(!(nd->flags & LOOKUP_RCU));
>  
> -	if (unlikely(!legitimize_links(nd)))
> +	if (unlikely(nd->depth && !legitimize_links(nd)))
>  		goto out1;
>  	if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
>  		goto out;
> @@ -917,7 +917,7 @@ static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry)
>  	int res;
>  	BUG_ON(!(nd->flags & LOOKUP_RCU));
>  
> -	if (unlikely(!legitimize_links(nd)))
> +	if (unlikely(nd->depth && !legitimize_links(nd)))
>  		goto out2;
>  	res = __legitimize_mnt(nd->path.mnt, nd->m_seq);
>  	if (unlikely(res)) {
> -- 
> 2.48.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] fs: avoid calls to legitimize_links() if possible
  2025-11-10 10:05 [PATCH v2] fs: avoid calls to legitimize_links() if possible Mateusz Guzik
  2025-11-10 11:30 ` Jan Kara
@ 2025-11-11  9:47 ` Christian Brauner
  2025-11-11 11:13   ` Mateusz Guzik
  1 sibling, 1 reply; 4+ messages in thread
From: Christian Brauner @ 2025-11-11  9:47 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: Christian Brauner, jack, linux-kernel, linux-fsdevel, viro

On Mon, 10 Nov 2025 11:05:03 +0100, Mateusz Guzik wrote:
> The routine is always called towards the end of lookup.
> 
> According to bpftrace on my boxen and boxen of people I asked, the depth
> count is almost always 0, thus the call can be avoided in the common case.
> 
> one-liner:
> bpftrace -e 'kprobe:legitimize_links { @[((struct nameidata *)arg0)->depth] = count(); }'
> 
> [...]

Applied to the vfs-6.19.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.19.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.19.misc

[1/1] fs: avoid calls to legitimize_links() if possible
      https://git.kernel.org/vfs/vfs/c/ab328bc1eb61

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] fs: avoid calls to legitimize_links() if possible
  2025-11-11  9:47 ` Christian Brauner
@ 2025-11-11 11:13   ` Mateusz Guzik
  0 siblings, 0 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-11 11:13 UTC (permalink / raw)
  To: Christian Brauner; +Cc: jack, linux-kernel, linux-fsdevel, viro

this patch is obsolete, I posted a v3 (and later v4) with more
predicts in the area:
https://lore.kernel.org/linux-fsdevel/20251110165901.1491476-1-mjguzik@gmail.com/

but that will require at least a v5 later

tl;dr please drop this patch

On Tue, Nov 11, 2025 at 10:47 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Mon, 10 Nov 2025 11:05:03 +0100, Mateusz Guzik wrote:
> > The routine is always called towards the end of lookup.
> >
> > According to bpftrace on my boxen and boxen of people I asked, the depth
> > count is almost always 0, thus the call can be avoided in the common case.
> >
> > one-liner:
> > bpftrace -e 'kprobe:legitimize_links { @[((struct nameidata *)arg0)->depth] = count(); }'
> >
> > [...]
>
> Applied to the vfs-6.19.misc branch of the vfs/vfs.git tree.
> Patches in the vfs-6.19.misc branch should appear in linux-next soon.
>
> Please report any outstanding bugs that were missed during review in a
> new review to the original patch series allowing us to drop it.
>
> It's encouraged to provide Acked-bys and Reviewed-bys even though the
> patch has now been applied. If possible patch trailers will be updated.
>
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. If in doubt, please check the listed branch.
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
> branch: vfs-6.19.misc
>
> [1/1] fs: avoid calls to legitimize_links() if possible
>       https://git.kernel.org/vfs/vfs/c/ab328bc1eb61

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-11 11:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-10 10:05 [PATCH v2] fs: avoid calls to legitimize_links() if possible Mateusz Guzik
2025-11-10 11:30 ` Jan Kara
2025-11-11  9:47 ` Christian Brauner
2025-11-11 11:13   ` Mateusz Guzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®