go may require prefaulting mmap

18 points by eBPF


geocar

The naive approach would be to walk the memory in another goroutine, to prime it. But that’s exactly the problem.

Erm. I think the naive approach would be to read the manual. And if not, it should be.

POSIX tells us to use posix_madvise() with POSIX_MADV_SEQUENTIAL. Linux also supports MAP_POPULATE which lets you do it at mmap-time. I recommend this.

Your write-trick works because the kernel copies the user pages into memory (which triggers the page fault bringing them into the page cache). I don’t think it is guaranteed to do this, because the kernel can absolutely recognise /dev/null (and even if Linux currently doesn’t, it could, and other unixen can), and it’s going to be slower than just calling madvise.