Linux mmap(2)
says:
MAP_PRIVATE
Create a private copy-on-write mapping. Updates to the mapping are not visible to other processes mapping the same file, and are not carried through to the underlying file. It is unspecified whether changes made to the file after themmap()
call are visible in the mapped region.
I'm specifically asking about this part: "not visible to other processes mapping the same file"
But what about other mappings of the same file in this process?
I understand that "changes ... are not carried through to the underlying file", but that doesn't clearly indicate whether or not those changes affect other mappings of the same file.
The following related questions do not answer this:
- Query on MAP_PRIVATE
- Writing to MAP_PRIVATE mmaped file
- difference between MAP_PRIVATE and MAP_SHARED in mmap for threads
Nate Eldredge pointed out that the POSIX mmap spec also does not specify this behavior, stating only:
If
MAP_PRIVATE
is specified, modifications to the mapped data by the calling process shall be visible only to the calling process and shall not change the underlying object.
open()
(two separate file descriptions), or whether one was fromopen()
and the other fromdup()
(one file description, two file descriptors). – EsMAP_PRIVATE
always makes a 100% private mapping, regardless of process, file, or fd) makes sense. However, empirically testing against one kernel isn't exactly a safe way to write software. This seems to be a huge gap in the documentation. – Cope