[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251110100503.1434167-1-mjguzik@gmail.com>
Date: Mon, 10 Nov 2025 11:05:03 +0100
From: Mateusz Guzik <mjguzik@...il.com>
To: viro@...iv.linux.org.uk
Cc: brauner@...nel.org,
jack@...e.cz,
linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
Mateusz Guzik <mjguzik@...il.com>
Subject: [PATCH v2] 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
Signed-off-by: Mateusz Guzik <mjguzik@...il.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
Powered by blists - more mailing lists