how many memset(,0,) calls in kernel ?

From: Douglas Gilbert
Date: Sat Sep 11 2021 - 23:44:30 EST


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