3 ms·
> I’ve always wondered how much CPU time and memory bandwidth is taken up by the OS zeroing out pages before handing them out Not much, since on any modern sys
by _Nax 7y ago
> I’ve always wondered how much CPU time and memory bandwidth is taken up by the OS zeroing out pages before handing them out
Not much, since on any modern system (that supports basic memory management in hardware), the OS have a single, special page full of zeroes and configured to trap on write that it maps every time a new page is requested. Only when a write occurs (and is trapped) does the OS substitute an actual page.
It's also why on some of these systems, calloc is faster than malloc + memset : calloc may be special-cased not to zero anything on the userland side if it allocates a brand new set of pages, while the memset will always trigger the CoW (and write useless zeroes as well).
Granted, the OS still needs to write zeroes a lot to implement the actual CoW operation, but it occurs less often than you would think.