I am curious to know the details of how the kernel deals with concurrent writes / access to a shared mapping created through mmap
. Looking in the man pages, all that I see for MAP_SHARED
is the following:
Share this mapping. Updates to the mapping are visible to other processes mapping the same region, and (in the case of file-backed mappings) are carried through to the underlying file. (To precisely control when updates are carried through to the underlying file requires the use of msync(2).)
However, from my understanding, msync
is dealing with synchronization from the page cache to the underlying storage device. However, it doesn't seem to deal with the case that two processes have mmap
ed a file. What happens when two processes write to the mapped region at the same time? If I create a shared mapping, how can I be sure that an unrelated process that happens to map the same file isn't doing concurrent writes?