CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 1 of 7 · 1 min read

Why this page comes fourth

In this module you will

  • Map a file into memory with mmap, read and change it through a pointer, and unmap it.
  • Tell a shared mapping from a private mapping, and say which changes reach the file.
  • Explain what the page cache is, and how a first access to a mapped page leads to a page fault.
  • Predict what happens when a mapped file ends in the middle of a page, and when it is shorter than the mapping.
  • Compare mmap with read on sequential and random access, using measured numbers.

Pages 1 and 3 covered the two regions that a program fills for itself, the heap and the stack. This page covers the third source of memory: a file. The mechanism is the one of Level 6, page 7: a page that is not in memory is fetched at the first access, and the file is its backing store. Page 5 then uses the same call to share memory between processes. The sources are TLPI chapter 49, OSTEP chapter 21 and OSC chapter 10. The test programs were compiled with gcc -O2 -Wall -Wextra and run on a Linux machine, on files of 5,000 bytes to 256 MiB.

About this example About this example

Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).

Scripted: The worked traces use small numbers chosen so they can be followed by hand.

Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.