linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fs/namei.c: Remove unlikely of status being -ECHILD in lookup_fast()
@ 2020-12-09 22:09 Steven Rostedt
  2021-01-13 23:13 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2020-12-09 22:09 UTC (permalink / raw)
  To: LKML; +Cc: Al Viro, linux-fsdevel

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.

As it is dependent on what filesystem mix is configured in the running
kernel, simply remove the unlikely() from the if statement.

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

 - Remove unlikely() instead of making it a likely()

diff --git a/fs/namei.c b/fs/namei.c
index d4a6dd772303..c7b7e83853f3 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 (status == -ECHILD)
 			/* we'd been told to redo it in non-rcu mode */
 			status = d_revalidate(dentry, nd->flags);
 	} else {

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

* Re: [PATCH v2] fs/namei.c: Remove unlikely of status being -ECHILD in lookup_fast()
  2020-12-09 22:09 [PATCH v2] fs/namei.c: Remove unlikely of status being -ECHILD in lookup_fast() Steven Rostedt
@ 2021-01-13 23:13 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2021-01-13 23:13 UTC (permalink / raw)
  To: Al Viro; +Cc: LKML, linux-fsdevel

Ping?

-- Steve


On Wed, 9 Dec 2020 17:09:28 -0500
Steven Rostedt <rostedt@goodmis.org> 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;
> 
> It appears that that is the only case that this if statement is triggered
> on two of my machines, running in production.
> 
> As it is dependent on what filesystem mix is configured in the running
> kernel, simply remove the unlikely() from the if statement.
> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> Changes since v1:
> 
>  - Remove unlikely() instead of making it a likely()
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index d4a6dd772303..c7b7e83853f3 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 (status == -ECHILD)
>  			/* we'd been told to redo it in non-rcu mode */
>  			status = d_revalidate(dentry, nd->flags);
>  	} else {


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

end of thread, other threads:[~2021-01-14  2:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 22:09 [PATCH v2] fs/namei.c: Remove unlikely of status being -ECHILD in lookup_fast() Steven Rostedt
2021-01-13 23:13 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).