简体   繁体   English

mmap澄清:进程重新启动后会发生什么

[英]mmap clarification: what happens after process restarts

My understanding of mmap is very limited, let me know which of the following are correct. 我对mmap的理解非常有限,请让我知道以下哪个是正确的。 For the following scenario in a piece of program: 对于一段程序中的以下情形:

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

Is my understanding correct? 我的理解正确吗? I am especially confused about the part after the process is killed and restarted. 对于进程被终止并重新启动后的部分,我尤其感到困惑。 Thanks! 谢谢!

mmap "creates a new mapping in the virtual address space of the calling process". mmap “在调用进程的虚拟地址空间中创建一个新的映射”。 Unless you use MAP_POPULATE nothing is read from the file backing the mapping. 除非您使用MAP_POPULATE否则不会从支持映射的文件中读取任何内容。 ( man page ) 手册页

Accessing the file-backed mapping needs to bring in the data obviously. 访问文件支持的映射显然需要引入数据。 Whether physical I/O happens at this point depends on whether the OS has the page you're trying to access in its cache. 此时是否发生物理I / O取决于操作系统是否在其缓存中尝试访问的页面。

So I'd say your statements 1, 2, and 4 are true, while 5 might be not. 因此,我想说您的陈述1、2和4是正确的,而5可能不是。

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

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