mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fs: touch up predicts in path lookup
@ 2025-11-05 15:06 Mateusz Guzik
  2025-11-12 11:20 ` Mateusz Guzik
  2025-11-13 13:23 ` Christian Brauner
  0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-05 15:06 UTC (permalink / raw)
  To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel, Mateusz Guzik

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@gmail.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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: touch up predicts in path lookup
  2025-11-05 15:06 [PATCH] fs: touch up predicts in path lookup Mateusz Guzik
@ 2025-11-12 11:20 ` Mateusz Guzik
  2025-11-13 13:23   ` Christian Brauner
  2025-11-13 13:23 ` Christian Brauner
  1 sibling, 1 reply; 4+ messages in thread
From: Mateusz Guzik @ 2025-11-12 11:20 UTC (permalink / raw)
  To: brauner; +Cc: viro, jack, linux-kernel, linux-fsdevel

any opinions on this one

On Wed, Nov 5, 2025 at 4:06 PM Mateusz Guzik <mjguzik@gmail.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@gmail.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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: touch up predicts in path lookup
  2025-11-12 11:20 ` Mateusz Guzik
@ 2025-11-13 13:23   ` Christian Brauner
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2025-11-13 13:23 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: viro, jack, linux-kernel, linux-fsdevel

On Wed, Nov 12, 2025 at 12:20:09PM +0100, Mateusz Guzik wrote:
> any opinions on this one

Yes, looks all sensible to me.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: touch up predicts in path lookup
  2025-11-05 15:06 [PATCH] fs: touch up predicts in path lookup Mateusz Guzik
  2025-11-12 11:20 ` Mateusz Guzik
@ 2025-11-13 13:23 ` Christian Brauner
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2025-11-13 13:23 UTC (permalink / raw)
  To: Mateusz Guzik; +Cc: Christian Brauner, viro, jack, linux-kernel, linux-fsdevel

On Wed, 05 Nov 2025 16:06:30 +0100, Mateusz Guzik 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
> 
> [...]

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: touch up predicts in path lookup
      https://git.kernel.org/vfs/vfs/c/030e86dfdaa7

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-13 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05 15:06 [PATCH] fs: touch up predicts in path lookup Mateusz Guzik
2025-11-12 11:20 ` Mateusz Guzik
2025-11-13 13:23   ` Christian Brauner
2025-11-13 13:23 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®