{
  "slug": "memory-mapped-file",
  "term": "Memory-mapped file",
  "aliases": [
    "file-backed mmap",
    "mmap file mapping"
  ],
  "definition": "A memory-mapped file exposes a file region through a process's virtual address space so its contents can be accessed with memory loads and stores.",
  "note": "Mapping mode: MAP_SHARED permits file-backed updates, whereas MAP_PRIVATE keeps modifications private through copy-on-write. Private mapping does not promise a snapshot of later external file changes. Closing the original descriptor leaves the mapping valid. [mmap-api]\n\nFile extent: mapping length is not file length. A larger mapping does not grow the file, and accesses to whole pages beyond the object can raise SIGBUS. The unused tail of a partial final page is different: stores there do not extend the file, and Linux warns that cached tail bytes may remain visible to later mappings. [posix-mmap] [mmap-api]\n\nPersistence: synchronization of a shared mapping is distinct from an atomic transaction. Background writeback may occur before an explicit msync call. [posix-msync]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-10-17",
  "advantages": [
    "Allows a file region to be addressed without an explicit read call for each access."
  ],
  "limitations": [
    "Concurrent access and file resizing require an application-level coordination protocol."
  ],
  "related": [
    "msync",
    "file-truncation",
    "page-cache",
    "copy-on-write",
    "lmdb"
  ],
  "citations": [
    {
      "id": "mmap-api",
      "title": "Linux man-pages: mmap(2), mapping modes and lifetime",
      "url": "https://man7.org/linux/man-pages/man2/mmap.2.html",
      "accessed": "2026-10-17"
    },
    {
      "id": "posix-mmap",
      "title": "POSIX.1-2017: mmap(), object size and mapping boundaries",
      "url": "https://man7.org/linux/man-pages/man3/mmap.3p.html",
      "accessed": "2026-10-17"
    },
    {
      "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/",
      "accessed": "2026-10-17"
    }
  ],
  "provenance": [
    "The POSIX citations refer to the 2017 edition; Linux-specific details are identified separately.",
    "The companion experiment checks API behavior on one host, not power-loss survival."
  ]
}
