我对mmap的理解非常有限,请告诉我以下哪项是正确的。对于一个程序中的以下场景:
1. Process starts, call mmap() // this is not actually loading anything from disk,
// just allocates memory?
2. access data in the file // this actually triggers the load from disk so
// it takes longer?
3. at this point, the process is killed and restarted
4. Process starts, call mmap() // this is not loading but the memory pointer
// allocated is likely to be different?
5. access data in the file // it takes roughly the same amount of time
// as the first time
我的理解是否正确?在进程被终止并重新启动后,我对该部分特别感到困惑。谢谢!
答案 0 :(得分:2)
mmap
"在调用进程的虚拟地址空间中创建一个新映射"。除非您使用MAP_POPULATE
,否则不会从支持映射的文件中读取任何内容。 (man page)
访问文件支持的映射显然需要引入数据。此时是否发生物理I / O取决于操作系统是否具有您尝试在其缓存中访问的页面。
所以我说你的陈述1,2和4都是真的,而5则可能不是。