News for hackers. Stuff that matters.
Re:Why does calloc exist? by caf on Monday December 05, 2016 @08:22PM (#13111489)
CPUs are pretty great at running nonmagical for loops, so you'd have be zeroing a pretty giant block of memory before it made sense to get the OS involved at all.
Re:Why does calloc exist? by Manishearth on Monday December 05, 2016 @08:49PM (#13111618)
Of course :) But the OS could get involved for larger blocks of memory.

Also, I wonder if zeroing large chunks of memory would be faster to do in kernel space using real addresses. You can avoid the multiple real memory lookups involved in a single virtual write.

(Of course, we already avoid those often, but it could be useful to avoid entirely. Not sure what the tradeoffs are here)

Re:Why does calloc exist? by caf on Monday December 05, 2016 @08:57PM (#13111647)
Paging is still enabled in kernel mode, the kernel uses virtual addresses.

(The kernel's linear mapping of physical memory can take advantage of huge pages though, which means that there might be one or two less levels of page tables involved with those addresses). TLB misses aren't significant if you're bulk-writing to a block of memory anyway, you'll max out the bandwidth of the memory without that being an issue.

Re:Why does calloc exist? by adrianN on Tuesday December 06, 2016 @02:29AM (#13112857)
For linear access patterns the TLB does its job perfectly. The overhead is negligible.