Skip to main content
Definition Website Computer and Technology

Memory-Mapped File

Subject: Computer and Technology noun /ˈmɛm.ə.ri ˌmæpt ˈfaɪl/ 1 definition

  1. Definition (noun)

    Entry #203 · Updated

    A Memory-Mapped File is a segment of a process's virtual address space mapped byte-for-byte by the operating system to a file in storage. Instead of copying data through explicit read and write system calls, applications access file contents directly via memory addresses, relying on demand paging and the kernel's page cache to load blocks on page faults and flush modified pages back to storage. This eliminates redundant user-space buffer copies and lets multiple processes share physical memory pages, though it is constrained by virtual address space limits, page-aligned file boundaries, unpredictable page-fault latency, and the need for explicit synchronization on concurrent writes.

    Common Types

    • Shared File Mapping: Maps a file on disk with shared visibility (such as POSIX MAP_SHARED), propagating writes to other processes mapping the same region and flushing modified pages back to storage for databases and durable logs.

    • Private (Copy-on-Write) Mapping: Shares clean read-only pages from the page cache (such as POSIX MAP_PRIVATE) while duplicating any modified page into process-private memory without altering the underlying file, commonly used by OS loaders for executables and shared libraries.

    • Non-Persisted (Page-File) Mapping: Allocates a shared or private region backed by the system paging file or anonymous swap space rather than a named disk file, enabling fast inter-process communication and large memory allocations without persistent storage I/O.

    • Partial (Windowed) Mapping: Maps a bounded byte-offset slice of a file instead of its entire length, allowing applications to slide a fixed-size view over multi-gigabyte files without exhausting virtual address space.

    Example

    A search engine daemon maps a 40 GB read-only inverted index using POSIX mmap() with PROT_READ and MAP_SHARED so worker processes can perform binary searches directly against mapped virtual memory addresses without allocating heap buffers. The operating system kernel loads only the 4 KB index pages touched by active queries into the page cache and evicts cold pages automatically under memory pressure, keeping startup instantaneous and physical RAM usage low.