fs: avoid calls to legitimize_links() if possible
PATCH v2 1/1 fs: avoid calls to legitimize_links() if possible
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
---
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(-)
fs/namei.c +2 -2
@@ -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)) {
Signature · 1 line
2.48.1
Quoted 16 lines · 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
Quoted 5 lines
And of course the venerable kernel build:
@[1]: 3563
@[0]: 6625425Signed-off-by Mateusz Guzik <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 36 lines
---
v2:
- drop 'noinline'
- spell out the check at call sitesverified no change in asm
fs/namei.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/namei.c +2
-2@@ -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)) {Signature · 1 line
2.48.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 9 lines · 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(); }'[...]
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
this patch is obsolete, I posted a v3 (and later v4) with more predicts in the area:
https://lore.kernel.org/linux-fsdevel/[email protected]/
but that will require at least a v5 later
tl;dr please drop this patch
Quoted 29 lines · Christian Brauner
Quoted 9 lines · 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(); }'[...]
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 possiblehttps://git.kernel.org/vfs/vfs/c/ab328bc1eb61