Hacker News new | ask | show | jobs
by staticassertion 1374 days ago
I believe that when a file is mmap'd a page table is created for it in the . As you perform read/write on the file a fault loads the actual entries into that page table. As pages can be mapped they so too can be unmapped under pressure, without that falling back to swap (since it is already a file backed map, you wouldn't swap a file backed map to a different file after all).

There are a few relevant bits to this. You can MAP_POPULATE the file to prepopulate the entries and you can MAP_LOCKED to MAP_POPULATE + lock the pages in (unreliably). As mentioned in the man page for mmap MAP_LOCKED has some failure modes that you don't get with mlock.

https://www.man7.org/linux/man-pages/man2/mmap.2.html

I also found this page: https://eklitzke.org/mlock-and-mlockall

Oh, and this: https://access.redhat.com/documentation/en-us/red_hat_enterp...