msync
msync is an operation that synchronizes a range of a shared file-backed memory mapping with its underlying file, with MS_SYNC waiting for completion.
Completion: MS_SYNC waits for synchronization of the mapped range. Linux MS_ASYNC is a no-op since 2.6.19, not a persistence acknowledgement. The starting address must be page-aligned; an unaligned address yields EINVAL, which does not by itself diagnose a storage failure. [1]
Transaction boundary: ordinary activity may write shared dirty pages before msync. The call supplies neither isolation from other readers nor an all-or-nothing multi-page commit. A successful call on a MAP_PRIVATE mapping does not copy private changes into its file. [4]
Distinct flag: MS_SYNC is not the DAX-oriented MAP_SYNC option to mmap. [2]
Partial-page tail: Linux documents that stores beyond EOF within the final mapped page can remain visible in later mappings after close and unmap; msync does not clear this cached tail on tmpfs. [2] Hesela's separate fresh-process probe observed that boundary on Linux 6.8 with ext4 and tmpfs controls; the in-file payload and file length stayed unchanged. This is not evidence of persistence after reboot or a portable tail-clearing contract. [5]
Relations
- related
- Failure-atomic msync, fsync, fdatasync, sync_file_range, Memory-mapped file, File truncation, Memory locking (mlock), FlushViewOfFile
Advantages
- Provides explicit synchronization for a selected mapped range.
Limitations
- Portable callers select exactly one of MS_SYNC and MS_ASYNC.
- A cached reread is not independent evidence of recovery after a power failure.
Citations
- Linux man-pages 6.19: msync(2), flags and Linux behavior
- Linux man-pages 6.19: mmap(2), shared/private mappings and MAP_SYNC
- POSIX.1-2017: msync(), completion and background writeback
- Hesela: Memory-mapped files: visibility, size and synchronization