mlock2() allows a third argument MLOCK_ONFAULT, which allow to
lock the pages in a range before touching them, so mlock2()
can be called before touching all pages instead of after.
"vmtouch -t -l" some_file would not keep the pages in cache
after touching them, so at the lock() step they needed to
be read again from disk. After this patch files are cached
twice as fast on this system.
Use mlockall(MCL_FUTURE) instead of mlockall(MCL_CURRENT):
Set mlockall(MCL_FUTURE) before touching pages to have similar
behaviour as the mlock2() approach above.
Use mlock2() instead of mlock() on Linux:
Use mlockall(MCL_FUTURE) instead of mlockall(MCL_CURRENT):