I want to use POSIX Shared Memory and my question is about the usage of msync() and munmap() after calling mmap(MAP_SHARED).
msync()?msync()?msync()?I have the impression msync() is only useful to apply the changes to underlying file and not to the shared memory.
POSIX
See msync(2):
msync() is called with MS_ASYNC or MS_SYNC.msync() was not called before close()/munmap().This allows old implementations to use separate caches for memory mappings (a.k.a page cache) and file I/O (a.k.a buffer cache).
Modern implementations
Modern implementations (e.g. modern Linux) usually implement "unified virtual memory model" which uses the same cache for memory mappings and I/O. It's not required by POSIX or SUSv3.
In such implementations:
msync() was not called before close()/munmap().MS_ASYNC is a no-op.MS_SYNC is just like fsync().In Linux, msync() is just another interface to fsync() and nothing more. See msync(2) manual page and this thread.
Reference
See "The Linux Programming Interface", section "49.4.4 Memory Protection and File Access Mode Interactions".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With