diff mbox series

fs/namei.c: Make status likely to be ECHILD in lookup_fast()

Message ID 20201209152403.6d6cf9ba@gandalf.local.home (mailing list archive)
State New, archived
Headers show
Series fs/namei.c: Make status likely to be ECHILD in lookup_fast() | expand

Commit Message

Steven Rostedt Dec. 9, 2020, 8:24 p.m. UTC
From:  Steven Rostedt (VMware) <rostedt@goodmis.org>

Running my yearly branch profiling code, it detected a 100% wrong branch
condition in name.c for lookup_fast(). The code in question has:

		status = d_revalidate(dentry, nd->flags);
		if (likely(status > 0))
			return dentry;
		if (unlazy_child(nd, dentry, seq))
			return ERR_PTR(-ECHILD);
		if (unlikely(status == -ECHILD))
			/* we'd been told to redo it in non-rcu mode */
			status = d_revalidate(dentry, nd->flags);

If the status of the d_revalidate() is greater than zero, then the function
finishes. Otherwise, if it is an "unlazy_child" it returns with -ECHILD.
After the above two checks, the status is compared to -ECHILD, as that is
what is returned if the original d_revalidate() needed to be done in a
non-rcu mode.

Especially this path is called in a condition of:

	if (nd->flags & LOOKUP_RCU) {

And most of the d_revalidate() functions have:

	if (flags & LOOKUP_RCU)
		return -ECHILD;

It appears that that is the only case that this if statement is triggered
on two of my machines, running in production.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---

Comments

Al Viro Dec. 9, 2020, 8:35 p.m. UTC | #1
On Wed, Dec 09, 2020 at 03:24:03PM -0500, Steven Rostedt wrote:
> From:  Steven Rostedt (VMware) <rostedt@goodmis.org>
> 
> Running my yearly branch profiling code, it detected a 100% wrong branch
> condition in name.c for lookup_fast(). The code in question has:
> 
> 		status = d_revalidate(dentry, nd->flags);
> 		if (likely(status > 0))
> 			return dentry;
> 		if (unlazy_child(nd, dentry, seq))
> 			return ERR_PTR(-ECHILD);
> 		if (unlikely(status == -ECHILD))
> 			/* we'd been told to redo it in non-rcu mode */
> 			status = d_revalidate(dentry, nd->flags);
> 
> If the status of the d_revalidate() is greater than zero, then the function
> finishes. Otherwise, if it is an "unlazy_child" it returns with -ECHILD.
> After the above two checks, the status is compared to -ECHILD, as that is
> what is returned if the original d_revalidate() needed to be done in a
> non-rcu mode.
> 
> Especially this path is called in a condition of:
> 
> 	if (nd->flags & LOOKUP_RCU) {
> 
> And most of the d_revalidate() functions have:
> 
> 	if (flags & LOOKUP_RCU)
> 		return -ECHILD;

Umm...  That depends upon the filesystem mix involved; said that, I'd rather
drop that "unlikely"...
Steven Rostedt Dec. 9, 2020, 8:58 p.m. UTC | #2
On Wed, 9 Dec 2020 20:35:00 +0000
Al Viro <viro@zeniv.linux.org.uk> wrote:

> > And most of the d_revalidate() functions have:
> > 
> > 	if (flags & LOOKUP_RCU)
> > 		return -ECHILD;  
> 
> Umm...  That depends upon the filesystem mix involved; said that, I'd rather
> drop that "unlikely"...

Sure enough. I'll send a v2.

Thanks,

-- Steve
diff mbox series

Patch

diff --git a/fs/namei.c b/fs/namei.c
index d4a6dd772303..8dd734efae9b 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1495,7 +1495,7 @@  static struct dentry *lookup_fast(struct nameidata *nd,
 			return dentry;
 		if (unlazy_child(nd, dentry, seq))
 			return ERR_PTR(-ECHILD);
-		if (unlikely(status == -ECHILD))
+		if (likely(status == -ECHILD))
 			/* we'd been told to redo it in non-rcu mode */
 			status = d_revalidate(dentry, nd->flags);
 	} else {