memory-mapped-file · shipping · also file-backed mmap, mmap file mapping

Memory-mapped file

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.

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. [1]

File 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. [2] [1]

Persistence: synchronization of a shared mapping is distinct from an atomic transaction. Background writeback may occur before an explicit msync call. [3]

Relations

related
msync, file-truncation, page-cache, copy-on-write, lmdb

Advantages

Limitations

Citations

  1. Linux man-pages: mmap(2), mapping modes and lifetime (accessed 2026-10-17)
  2. POSIX.1-2017: mmap(), object size and mapping boundaries (accessed 2026-10-17)
  3. POSIX.1-2017: msync(), completion and background writeback (accessed 2026-10-17)

Further reading

  1. Hesela: Memory-mapped files: visibility, size and synchronization (accessed 2026-10-17)
Sources & caveats

JSON: /data/terms/memory-mapped-file.json