Reputation: 73
if I want to mmap
a 10 GB file and load the whole file into physical memory immediately, how can I do so?
I don't want to use function like mlock
because it needs root privileges.
Is there a system call which can satisfy my demand?
(I have more than enough memory.)
Upvotes: 6
Views: 820
Reputation: 45654
Read the man-page for mmap
:
MAP_POPULATE (since Linux 2.5.46)
Populate (prefault) page tables for a mapping. For a file mapping, this causes read-ahead on the file. Later accesses to the mapping will not be blocked by page faults.
MAP_POPULATE
is supported for private mappings only since Linux 2.6.23
Issue your request, and be prepared for a short wait (unless you exceed the processes limits) (depending on disk-bandwidth and cache).
Upvotes: 5