Mmap file 10 GB and load it into memory

if I want mmap to create a 10 GB file and immediately load the whole file into physical memory, how can I do this?
I do not want to use a function like mlock because it needs root privileges.
Is there a system call that can satisfy my requirement?

(I have more than enough memory.)

+6
source share
1 answer

Read the man page for mmap :

MAP_POPULATE (since Linux 2.5.46)

Tables of prefault pages to map. For file mapping, this causes read-forward in the file. Late access mapping will not be blocked by page errors. MAP_POPULATE supported for private mappings only since Linux 2.6.23

Ask for your request and be prepared for a short wait (if you do not exceed the process limits) (depending on the bandwidth of the disk and cache).

+5
source

Source: https://habr.com/ru/post/977689/


All Articles