3 ms·
> The kernel doesn't really have any tricks that userspace doesn't have to zero arrays quickly. The kernel does have some tricks available --- it can't clean p
by toast0 7y ago
> The kernel doesn't really have any tricks that userspace doesn't have to zero arrays quickly.
The kernel does have some tricks available --- it can't clean pages any faster than userspace, but it can keep a cache of clean pages, and keep the cache filled by cleaning free pages during idle, including before your program was launched. I'm sure that the kernel was able to do the work before your program was launched will look great in microbenchmarks, if used right, but if you need to do it repeatedly, mmunap/mmap syscall processing time is going to be a lot bigger than rep stosb, unless you have a giant block to zero out and the block is nicely aligned.
Another comment in this general thread suggests that Linux doesn't do idle zeroing, but it's not the only kernel; FreeBSD has idle zeroing [1].
[1] https://www.freebsd.org/doc/en/articles/vm-design/prefault-optimizations.html https://www.freebsd.org/doc/en/articles/vm-design/prefault-o...