Viper Bailey
Viper Bailey

Reputation: 12027

How does a MAP_PRIVATE handle changes to the underlying file after mmap() is called

Let's say I have three separate processes (PV, PS, and PH), each of them call mmap() on the entirety of a file. PV calls mmap() with the MAP_PRIVATE flag while PS and PH call mmap() with the MAP_SHARED flag. I understand that changes made by PV to the memory block will NOT be propagated to PS nor PH. I also understand that changes made by PS will be propagated to PH, but will the changes be propagated to PV? Or is PV insulated from changes made by processes using MAP_SHARED?

Secondly, assuming none of them have written to the mmap() memory, will they all be using the same physical memory? Or do MAP_SHARED and MAP_PRIVATE lead to separate physical memory allocation?

Upvotes: 2

Views: 426

Answers (1)

Viper Bailey
Viper Bailey

Reputation: 12027

From the man page for mmap():

It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region.

tldr = Booooo!

Upvotes: 2

Related Questions