mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* how many memset(,0,) calls in kernel ?
@ 2021-09-12  3:36 Douglas Gilbert
  2021-09-12  4:56 ` Willy Tarreau
  0 siblings, 1 reply; 6+ messages in thread
From: Douglas Gilbert @ 2021-09-12  3:36 UTC (permalink / raw)
  To: LKML

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



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

end of thread, other threads:[~2021-09-14 16:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-09-14  8:23       ` David Laight
2021-09-14 16:46         ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®