Skip to content

Commit 177fdba

Browse files
mjguzikbrauner
authored andcommitted
fs: inline step_into() and walk_component()
The primary consumer is link_path_walk(), calling walk_component() every time which in turn calls step_into(). Inlining these saves overhead of 2 function calls per path component, along with allowing the compiler to do better job optimizing them in place. step_into() had absolutely atrocious assembly to facilitate the slowpath. In order to lessen the burden at the callsite all the hard work is moved into step_into_slowpath() and instead an inline-able fastpath is implemented for rcu-walk. The new fastpath is a stripped down step_into() RCU handling with a d_managed() check from handle_mounts(). Benchmarked as follows on Sapphire Rapids: 1. the "before" was a kernel with not-yet-merged optimizations (notably elision of calls to security_inode_permission() and marking ext4 inodes as not having acls as applicable) 2. "after" is the same + the prep patch + this patch 3. benchmark consists of issuing 205 calls to access(2) in a loop with pathnames lifted out of gcc and the linker building real code, most of which have several path components and 118 of which fail with -ENOENT. Result in terms of ops/s: before: 21619 after: 22536 (+4%) profile before: 20.25% [kernel] [k] __d_lookup_rcu 10.54% [kernel] [k] link_path_walk 10.22% [kernel] [k] entry_SYSCALL_64 6.50% libc.so.6 [.] __GI___access 6.35% [kernel] [k] strncpy_from_user 4.87% [kernel] [k] step_into 3.68% [kernel] [k] kmem_cache_alloc_noprof 2.88% [kernel] [k] walk_component 2.86% [kernel] [k] kmem_cache_free 2.14% [kernel] [k] set_root 2.08% [kernel] [k] lookup_fast after: 23.38% [kernel] [k] __d_lookup_rcu 11.27% [kernel] [k] entry_SYSCALL_64 10.89% [kernel] [k] link_path_walk 7.00% libc.so.6 [.] __GI___access 6.88% [kernel] [k] strncpy_from_user 3.50% [kernel] [k] kmem_cache_alloc_noprof 2.01% [kernel] [k] kmem_cache_free 2.00% [kernel] [k] set_root 1.99% [kernel] [k] lookup_fast 1.81% [kernel] [k] do_syscall_64 1.69% [kernel] [k] entry_SYSCALL_64_safe_stack While walk_component() and step_into() of course disappear from the profile, the link_path_walk() barely gets more overhead despite the inlining thanks to the fast path added and while completing more walks per second. I did not investigate why overhead grew a lot on __d_lookup_rcu(). Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20251120003803.2979978-2-mjguzik@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 9d2a621 commit 177fdba

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

fs/namei.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
19511951
int error;
19521952

19531953
if (nd->flags & LOOKUP_RCU) {
1954-
/* make sure that d_is_symlink from step_into() matches the inode */
1954+
/* make sure that d_is_symlink from step_into_slowpath() matches the inode */
19551955
if (read_seqcount_retry(&link->dentry->d_seq, nd->next_seq))
19561956
return ERR_PTR(-ECHILD);
19571957
} else {
@@ -2033,7 +2033,7 @@ static noinline const char *pick_link(struct nameidata *nd, struct path *link,
20332033
*
20342034
* NOTE: dentry must be what nd->next_seq had been sampled from.
20352035
*/
2036-
static const char *step_into(struct nameidata *nd, int flags,
2036+
static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,
20372037
struct dentry *dentry)
20382038
{
20392039
struct path path;
@@ -2066,6 +2066,31 @@ static const char *step_into(struct nameidata *nd, int flags,
20662066
return pick_link(nd, &path, inode, flags);
20672067
}
20682068

2069+
static __always_inline const char *step_into(struct nameidata *nd, int flags,
2070+
struct dentry *dentry)
2071+
{
2072+
/*
2073+
* In the common case we are in rcu-walk and traversing over a non-mounted on
2074+
* directory (as opposed to e.g., a symlink).
2075+
*
2076+
* We can handle that and negative entries with the checks below.
2077+
*/
2078+
if (likely((nd->flags & LOOKUP_RCU) &&
2079+
!d_managed(dentry) && !d_is_symlink(dentry))) {
2080+
struct inode *inode = dentry->d_inode;
2081+
if (read_seqcount_retry(&dentry->d_seq, nd->next_seq))
2082+
return ERR_PTR(-ECHILD);
2083+
if (unlikely(!inode))
2084+
return ERR_PTR(-ENOENT);
2085+
nd->path.dentry = dentry;
2086+
/* nd->path.mnt is retained on purpose */
2087+
nd->inode = inode;
2088+
nd->seq = nd->next_seq;
2089+
return NULL;
2090+
}
2091+
return step_into_slowpath(nd, flags, dentry);
2092+
}
2093+
20692094
static struct dentry *follow_dotdot_rcu(struct nameidata *nd)
20702095
{
20712096
struct dentry *parent, *old;
@@ -2176,7 +2201,7 @@ static const char *handle_dots(struct nameidata *nd, int type)
21762201
return NULL;
21772202
}
21782203

2179-
static const char *walk_component(struct nameidata *nd, int flags)
2204+
static __always_inline const char *walk_component(struct nameidata *nd, int flags)
21802205
{
21812206
struct dentry *dentry;
21822207
/*

0 commit comments

Comments
 (0)