linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Kaitao Cheng <pilgrimtao@gmail.com>,
	christian@brauner.io, akpm@linux-foundation.org,
	gladkov.alexey@gmail.com, guro@fb.com, walken@google.com,
	avagin@gmail.com, khlebnikov@yandex-team.ru,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] proc/base: Skip assignment to len when there is no error on d_path in do_proc_readlink.
Date: Wed, 27 May 2020 18:23:40 +0300	[thread overview]
Message-ID: <20200527152340.GA19985@localhost.localdomain> (raw)
In-Reply-To: <87k10x5tji.fsf@x220.int.ebiederm.org>

On Wed, May 27, 2020 at 09:41:53AM -0500, Eric W. Biederman wrote:
> Kaitao Cheng <pilgrimtao@gmail.com> writes:
> 
> > we don't need {len = PTR_ERR(pathname)} when IS_ERR(pathname) is false,
> > it's better to move it into if(IS_ERR(pathname)){}.
> 
> Please look at the generated code.
> 
> I believe you will find that your change will generate worse assembly.

I think patch is good.

Super duper CPUs which speculate thousands instructions forward won't
care but more embedded ones do. Or in other words 1 unnecessary instruction
on common path is more important for slow CPUs than for fast CPUs.

This style separates common path from error path more cleanly.

And finally "len" here is local, so the issue barely deserves mention
but if target is in memory code like this happens:

	static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
	{
	        struct fd f = fdget(fd);
	        struct socket *sock;
	
	        *err = -EBADF;
	        if (f.file) {
	
			// unconditionally write to *err as well.

	                sock = sock_from_file(f.file, err);
	                if (likely(sock)) {
	                        *fput_needed = f.flags;
	                        return sock;
	                }
	                fdput(f);
	        }
	        return NULL;
	}

so current style promotes more memory dirtying than necessary.

There is another place like this in sk_buff.c (search for ENOBUFS).

> >  	pathname = d_path(path, tmp, PAGE_SIZE);
> > -	len = PTR_ERR(pathname);
> > -	if (IS_ERR(pathname))
> > +	if (IS_ERR(pathname)) {
> > +		len = PTR_ERR(pathname);
> >  		goto out;
> > +	}

  reply	other threads:[~2020-05-27 15:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27 14:11 [PATCH] proc/base: Skip assignment to len when there is no error on d_path in do_proc_readlink Kaitao Cheng
2020-05-27 14:41 ` Eric W. Biederman
2020-05-27 15:23   ` Alexey Dobriyan [this message]
2020-05-27 16:36     ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200527152340.GA19985@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=avagin@gmail.com \
    --cc=christian@brauner.io \
    --cc=ebiederm@xmission.com \
    --cc=gladkov.alexey@gmail.com \
    --cc=guro@fb.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pilgrimtao@gmail.com \
    --cc=walken@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).