News for hackers. Stuff that matters.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by Animats on Friday December 09, 2016 @05:10PM (#13142297)
This may be over-optimization. Allocating all-zero pages as copy-on-write doesn't reduce zeroing overhead. It just postpones it until the page is used, at which time zeroing takes place. Possibly at a higher cost, because you now have to take a page fault, allocate a page, mess with the MMU, and only then zero the page. Only for programs which allocate vast amounts of memory which they then never write is this a win.

Is that common?

Re:Debugging Your Operating System: A Lesson in Memory Alloc... by brigade on Friday December 09, 2016 @05:27PM (#13142414)
If you zero upfront, you have to do all of that save the page fault anyway, but for large allocations you also thrash the cache zeroing stuff that's immediately evicted to memory. It really is faster in general to zero a page when the program actually touches it, since that's when the program wants it in cache (for certain thresholds of "large allocation")
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by haimez on Friday December 09, 2016 @07:32PM (#13143165)
"Thrashing to memory". Man, we must have different SLOs.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by loeg on Friday December 09, 2016 @05:41PM (#13142498)
The operating system can perform page zeroing during low load times and give out zero pages "for free" during higher load times. (So this can serve to smooth out CPU usage in spiky loads.) Or the OS may use special hardware that is inaccessible to userspace (e.g., Intel I/OAT) to zero pages in a way that doesn't consume CPU cycles.
Re:Debugging Your Operating System: A Lesson in Memory Alloc... by Achshar on Friday December 09, 2016 @05:49PM (#13142557)
Wouldn't it also help that the program would most certainly not write the entire large chunk of memory all at once. So the cost of copy-on-write zeroing is postponed and divided to individual write operations performed by the program instead of all of it happening up front at once.