简体   繁体   English

使用mmap读取非惰性文件?

[英]Non-lazy file read using mmap?

When you use mmap to read from a file, it performs lazy file read, that is it brings only the data that you use from the hard disk to RAM. 当您使用mmap读取文件时,它将执行延迟文件读取,即仅将您使用的数据从硬盘传送到RAM。 Now, is there any method with which we can force the whole file to be read into the RAM at once? 现在,有什么方法可以强制将整个文件立即读取到RAM中?

From the mmap(2) man page: mmap(2)手册页:

MAP_POPULATE (since Linux 2.5.46) MAP_POPULATE (从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. 仅从 Linux 2.6.23开始,专用映射才支持MAP_POPULATE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM