mmap a 10 GB file and load it into memory

你说的曾经没有我的故事 提交于 2019-12-12 10:47:17

问题


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.)


回答1:


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).



来源:https://stackoverflow.com/questions/26727209/mmap-a-10-gb-file-and-load-it-into-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!