Memory-Mapped Files and Shared Changes

Connect file offsets to virtual pages and distinguish a private view, shared visibility, and durable storage.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. A mapping lets accesses name file contents by address
  2. Changing memory does not by itself finish I/O

A mapping lets accesses name file contents by address

A mapped file associates a virtual interval with part of a file. Access can fault in pages as needed. With a private mapping, writes affect the private view rather than being propagated as modifications to the underlying shared object through that mapping. A shared mapping has a different visibility contract. Code still needs synchronization when different threads or processes read and modify shared bytes.

Changing memory does not by itself finish I/O

A dirty mapped page can be visible to another mapping before it reaches persistent storage. Robust programs use the documented synchronization operation for the platform and account for file size and lifetime changes. An offset beyond usable backing memory can have different behavior from an ordinary valid page. Demand paging describes the fault path. Page-cache writeback separates dirty visibility and completed storage writes.[1][2]

References

  1. The Open Group, POSIX mmap ↩
  2. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩