All of lore.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: LKML <linux-kernel@vger.kernel.org>
Subject: how many memset(,0,) calls in kernel ?
Date: Sat, 11 Sep 2021 23:36:07 -0400	[thread overview]
Message-ID: <1c4a94df-fc2f-1bb2-8bce-2d71f9f1f5df@interlog.com> (raw)

Here is a pretty rough estimate:
$ find . -name '*.c' -exec fgrep "memset(" {} \; > memset_in_kern.txt

$ cat memset_in_kern.txt | wc -l
     20159

Some of those are in comments, EXPORTs, etc, but the vast majority are
in code. Plus there will be memset()s in header files not counted by
that find. Checking in that output file I see:

$ grep ", 0," memset_in_kern.txt | wc -l
     18107
$ grep ", 0" memset_in_kern.txt | wc -l
     19349
$ grep ", 0x" memset_in_kern.txt | wc -l
     1210
$ grep ", 0x01" memset_in_kern.txt | wc -l
     3
$ grep ", 0x0," memset_in_kern.txt | wc -l
     199
$ grep ",0," memset_in_kern.txt | wc -l
     72

$ grep "= memset" memset_in_kern.txt | wc -l
      11

It seems only 11 invocations use the return value of memset() .

If the BSD flavours of Unix had not given us:
    void bzero(void *s, size_t n);
would the Linux kernel have something similar in common usage (e.g.
memzero() or mem0() ), that was less wasteful than the standard:
    void *memset(void *s, int c, size_t n);
in the extremely common case where c=0 and the return value is
not used?

Doug Gilbert



             reply	other threads:[~2021-09-12  3:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12  3:36 Douglas Gilbert [this message]
2021-09-12  4:56 ` how many memset(,0,) calls in kernel ? Willy Tarreau
2021-09-13 16:03   ` David Laight
2021-09-13 16:09     ` Willy Tarreau
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=1c4a94df-fc2f-1bb2-8bce-2d71f9f1f5df@interlog.com \
    --to=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.