3 ms·
The cost of the second kernel trip (on the first page fault) is often mitigated by speculative read-ahead, or the fact that a given page is often in the UBC alr
by gok 8y ago
The cost of the second kernel trip (on the first page fault) is often mitigated by speculative read-ahead, or the fact that a given page is often in the UBC already. And file-backed memory doesn't contribute to dirty memory. And mmap() makes it easy to use read-only memory, which catches memory corruption bugs. Plus it's easier to use huge pages, which reduces TLB pressure.
I <3 mmap
- jzwinck 8y agoMemory mapped I/O actually prevents the use of huge pages if the backing storage is an actual disk. See https://lwn.net/Articles/718102/ https://lwn.net/Articles/718102/ Do you know of a way around that, aside from building your own patched kernel?
- gok 8y agoYeah you need to move your files to tmpfs, but I still consider that easier than dealing with making it happen with malloc+read
- nemo1618 8y ago>mmap() makes it easy to use read-only memory, which catches memory corruption bugs You might appreciate this toy Go package I hacked together: https://github.com/lukechampine/freeze https://github.com/lukechampine/freeze It uses mmap and mprotect to "freeze" Go objects; if you try to modify a frozen object, the program crashes.
- gok 8y agoNice!