[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <iwsvdaw4u2o366ndbk2dzj2ehjbwpynpkcym435qvndoiwqg6a@mlbbmml23747>
Date: Mon, 10 Nov 2025 12:30:40 +0100
From: Jan Kara <jack@...e.cz>
To: Mateusz Guzik <mjguzik@...il.com>
Cc: viro@...iv.linux.org.uk, brauner@...nel.org, jack@...e.cz,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH v2] fs: avoid calls to legitimize_links() if possible
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@...il.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@...e.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@...e.com>
SUSE Labs, CR
Powered by blists - more mailing lists