Are multiple MAP_PRIVATE mappings of the same file, in the same process, still private?

Viewed 244

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 the mmap() 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:

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.

1 Answers

I think

shall not change the underlying object

makes the intent clear. When you mmap the same underlying object again in the same process, you're again making a map of the underlying object, the contents of which are determined by the content of that underlying object.

Admittedly it could/should be more clear.

Related