> This old myth that mmap is the fast and efficient way to do IO just won't die.
Well... because it's not a myth in all cases?
$ time rg zqzqzqzq OpenSubtitles2016.raw.en --mmap
real 1.167
user 0.815
sys 0.349
maxmem 9473 MB
faults 0
$ time rg zqzqzqzq OpenSubtitles2016.raw.en --no-mmap
real 1.748
user 0.506
sys 1.239
maxmem 9 MB
faults 0
The OP's adventures with mmap mirror my own, which is why ripgrep includes this
in its man page:
> ripgrep may abort unexpectedly when using
> default settings if it searches a file that
> is simultaneously truncated. This behavior
> can be avoided by passing the --no-mmap flag
> which will forcefully disable the use of
> memory maps in all cases.
mmap has its problems. But
on Linux for a simple sequential read of a large
file, it generally does measurably better than standard `read` calls. ripgrep doesn't even bother with madvise.
Changing the workload can dramatically alter these conclusions. For example, on
a checkout of the Linux kernel:
$ time rg zqzqzqzq --mmap
real 1.661
user 1.603
sys 3.128
maxmem 41 MB
faults 0
$ time rg zqzqzqzq --no-mmap
real 0.126
user 0.702
sys 0.586
maxmem 20 MB
faults 0
Performance of mmap can also vary depending on platform as well.
FWIW, I do generally disagree with your broader point, but it's important
to understand that there's actually good reason to believe that using mmaps
can be faster in some circumstances.