[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGudoHFNDC_5=T3XKLzNpsMkZYaf_KbjHrL36rc0YWDWaJMS_w@mail.gmail.com>
Date: Wed, 12 Nov 2025 12:20:09 +0100
From: Mateusz Guzik <mjguzik@...il.com>
To: brauner@...nel.org
Cc: viro@...iv.linux.org.uk, jack@...e.cz, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH] fs: touch up predicts in path lookup
any opinions on this one
On Wed, Nov 5, 2025 at 4:06 PM Mateusz Guzik <mjguzik@...il.com> wrote:
>
> Rationale:
> - ND_ROOT_PRESET is only set in a condition already marked unlikely
> - LOOKUP_IS_SCOPED already has unlikely on it, but inconsistently
> applied
> - set_root() only fails if there is a bug
> - most names are not empty (see !*s)
> - most of the time path_init() does not encounter LOOKUP_CACHED without
> LOOKUP_RCU
> - LOOKUP_IN_ROOT is a rarely seen flag
>
> Signed-off-by: Mateusz Guzik <mjguzik@...il.com>
> ---
> fs/namei.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 39c4d52f5b54..a9f9d0453425 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -951,8 +951,8 @@ static int complete_walk(struct nameidata *nd)
> * We don't want to zero nd->root for scoped-lookups or
> * externally-managed nd->root.
> */
> - if (!(nd->state & ND_ROOT_PRESET))
> - if (!(nd->flags & LOOKUP_IS_SCOPED))
> + if (likely(!(nd->state & ND_ROOT_PRESET)))
> + if (likely(!(nd->flags & LOOKUP_IS_SCOPED)))
> nd->root.mnt = NULL;
> nd->flags &= ~LOOKUP_CACHED;
> if (!try_to_unlazy(nd))
> @@ -1034,7 +1034,7 @@ static int nd_jump_root(struct nameidata *nd)
> }
> if (!nd->root.mnt) {
> int error = set_root(nd);
> - if (error)
> + if (unlikely(error))
> return error;
> }
> if (nd->flags & LOOKUP_RCU) {
> @@ -2101,7 +2101,7 @@ static const char *handle_dots(struct nameidata *nd, int type)
>
> if (!nd->root.mnt) {
> error = ERR_PTR(set_root(nd));
> - if (error)
> + if (unlikely(error))
> return error;
> }
> if (nd->flags & LOOKUP_RCU)
> @@ -2543,10 +2543,10 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> const char *s = nd->pathname;
>
> /* LOOKUP_CACHED requires RCU, ask caller to retry */
> - if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED)
> + if (unlikely((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED))
> return ERR_PTR(-EAGAIN);
>
> - if (!*s)
> + if (unlikely(!*s))
> flags &= ~LOOKUP_RCU;
> if (flags & LOOKUP_RCU)
> rcu_read_lock();
> @@ -2560,7 +2560,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
> smp_rmb();
>
> - if (nd->state & ND_ROOT_PRESET) {
> + if (unlikely(nd->state & ND_ROOT_PRESET)) {
> struct dentry *root = nd->root.dentry;
> struct inode *inode = root->d_inode;
> if (*s && unlikely(!d_can_lookup(root)))
> @@ -2579,7 +2579,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> nd->root.mnt = NULL;
>
> /* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */
> - if (*s == '/' && !(flags & LOOKUP_IN_ROOT)) {
> + if (*s == '/' && likely(!(flags & LOOKUP_IN_ROOT))) {
> error = nd_jump_root(nd);
> if (unlikely(error))
> return ERR_PTR(error);
> @@ -2632,7 +2632,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
> }
>
> /* For scoped-lookups we need to set the root to the dirfd as well. */
> - if (flags & LOOKUP_IS_SCOPED) {
> + if (unlikely(flags & LOOKUP_IS_SCOPED)) {
> nd->root = nd->path;
> if (flags & LOOKUP_RCU) {
> nd->root_seq = nd->seq;
> --
> 2.48.1
>
Powered by blists - more mailing lists