{
  "slug": "msync",
  "term": "msync",
  "aliases": [
    "msync()"
  ],
  "definition": "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.",
  "note": "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. [msync-api]\n\nTransaction 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. [posix-msync]\n\nDistinct flag: MS_SYNC is not the DAX-oriented MAP_SYNC option to mmap. [mmap-api]\n\nPartial-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. [mmap-api] 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. [hesela-mmap]\n\nUnmapped intervals: Linux v6.12 can synchronize shared file-backed regions on either side of a gap before returning ENOMEM. This is not a rollback or evidence that no I/O occurred; an earlier synchronization error can take precedence. Keep mapping lifetimes coordinated. [msync-source] A native eight-case probe records return codes and cached visibility, not crash durability. [msync-probe]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-12-04",
  "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."
  ],
  "related": [
    "failure-atomic-msync",
    "fsync",
    "fdatasync",
    "sync-file-range",
    "memory-mapped-file",
    "file-truncation",
    "mlock",
    "flush-view-of-file"
  ],
  "citations": [
    {
      "id": "msync-api",
      "title": "Linux man-pages 6.19: msync(2), flags and Linux behavior",
      "url": "https://man7.org/linux/man-pages/man2/msync.2.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "mmap-api",
      "title": "Linux man-pages 6.19: mmap(2), shared/private mappings and MAP_SYNC",
      "url": "https://man7.org/linux/man-pages/man2/mmap.2.html",
      "accessed": "2026-10-18"
    },
    {
      "id": "hesela-fsync",
      "title": "Hesela: File and mapped-range synchronization boundaries",
      "url": "https://hesela.com/analyses/fsync-failure-retry-durability/",
      "accessed": "2026-10-13"
    },
    {
      "id": "posix-msync",
      "title": "POSIX.1-2017: msync(), completion and background writeback",
      "url": "https://man7.org/linux/man-pages/man3/msync.3p.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "hesela-mmap",
      "title": "Hesela: Memory-mapped files: visibility, size and synchronization",
      "url": "https://hesela.com/analyses/mmap-visibility-size-durability/#tail-remapping",
      "accessed": "2026-10-18"
    },
    {
      "id": "msync-source",
      "title": "Linux v6.12: msync gap traversal and vfs_fsync_range ordering",
      "url": "https://github.com/torvalds/linux/blob/adc218676eef25575469234709c2d87185ca223a/mm/msync.c#L68",
      "accessed": "2026-12-04"
    },
    {
      "id": "msync-probe",
      "title": "Hesela: msync unmapped-interval probe, source and evidence boundaries",
      "url": "https://hesela.dev/research/msync-hole/README.md",
      "accessed": "2026-12-04"
    }
  ]
}
