Part 1 of 7 · 1 min read
Why this page comes fifth
In this module you will
- Explain how two page tables can map the same frames, and why that is faster than copying.
- Share memory between a parent and a child with an anonymous shared mapping.
- Create, use and remove a named POSIX shared memory object between unrelated processes.
- Show a race on shared memory, and fix it with an atomic operation or a process-shared lock.
- Build a producer and consumer over a shared ring with semaphores, and compare it with a pipe.
Level 1 gave processes private address spaces, and connected them with pipes, which copy data through the kernel. Page 4 showed that a mapping can be shared. This page joins the two ideas: if two processes map the same pages, the data needs no copy at all. The price is that the processes now have the problems of Level 4, a race on shared data, and they must solve them with locks that work across processes. The sources are TLPI chapters 48 to 54, OSTEP chapter 27 and OSC chapter 3. The test programs were compiled with gcc -O2 -Wall -Wextra -pthread and run on a two-processor Linux machine.
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.