All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: David Laight <David.Laight@aculab.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: how many memset(,0,) calls in kernel ?
Date: Mon, 13 Sep 2021 18:09:45 +0200	[thread overview]
Message-ID: <20210913160945.GA2456@1wt.eu> (raw)
In-Reply-To: <88976a40175c491fb5e3349f6686ad67@AcuMS.aculab.com>

On Mon, Sep 13, 2021 at 04:03:09PM +0000, David Laight wrote:
> >   36:   b9 06 00 00 00          mov    $0x6,%ecx
> >   3b:   4c 89 e7                mov    %r12,%rdi
> >   3e:   f3 ab                   rep stos %eax,%es:(%rdi)
> > 
> > The last line does exactly "memset(%rdi, %eax, %ecx)". Just two bytes
> > for some code that modern processors are even able to optimize.
> 
> Hmmm I'd bet that 6 stores will be faster on ~everything.
> 'modern' processors do better than some older ones [1], but 6
> writes isn't enough to get into the really fast paths.
> So you'll still take a few cycles of setup.

The exact point is, here it's up to the compiler to decide thanks to
its builtin what it considers best for the target CPU. It already
knows the fixed size and the code is emitted accordingly. It may
very well be a call to the memset() function when the size is large
and a power of two because it knows alternate variants are available
for example.

The compiler might even decide to shrink that area if other bytes
are written just after the memset(), leaving only holes touched by
memset().

Willy

  reply	other threads:[~2021-09-13 16:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12  3:36 how many memset(,0,) calls in kernel ? Douglas Gilbert
2021-09-12  4:56 ` Willy Tarreau
2021-09-13 16:03   ` David Laight
2021-09-13 16:09     ` Willy Tarreau [this message]
2021-09-14  8:23       ` David Laight
2021-09-14 16:46         ` Willy Tarreau

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=20210913160945.GA2456@1wt.eu \
    --to=w@1wt.eu \
    --cc=David.Laight@aculab.com \
    --cc=dgilbert@interlog.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.