简体   繁体   中英

mmap clarification: what happens after process restarts

My understanding of mmap is very limited, let me know which of the following are correct. 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". Unless you use MAP_POPULATE nothing is read from the file backing the mapping. ( 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.

So I'd say your statements 1, 2, and 4 are true, while 5 might be not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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