Re:A 100LOC C impl of memset, that is faster than glibc's
by knome on Friday November 12, 2021 @01:17PM
(#29202698)
I wonder if someone was zeroing enough memory, where the memory is a private anonymous mapping, they might use madvise() with MADV_DONTNEED, which in linux will effectively zero the pages.
It returns the memory to the OS, and will pagefault on later accesses remapping them as zero-filled. It works in pages. Sizes smaller than a page result in whatever else is in the same page getting nuked.
If you don't immediately reuse the whole cache, it might spread out the zeroing/remapping over time, rather than in a single large go. Imagine some testing would be in order to see if a syscall + mapping changes ( require reloading with TLB for the process ? ) would be smaller than a straight run of writing zeros at some point.
IIRC, the zeroing is not something you can expect from non-linux madvise implementations.
Not hundreds but in one of my apps I do have 10th MB of continuous cache that has to be zeroed before use / reuse.