KERNELBABAfreefreeframe 0frame 1frame 2frame 3frame 4frame 502–page 0page 1page 231–page 0page 1page 2framePR/WU/SAD–01010101011p = mmap(0, pg, RW, ANON, -1, 0);2p[0] = 'x';3mprotect(p, pg, PROT_READ);4munmap(p, pg);MMUCR3Ax40B
Back: the kernel and physical memory (frames and their owners)Middle: the page tables and one entry's bits · Front: the program and the CPU's table registerTokens: system calls, a page fault, a frame number moving in and out of the entryAt the back, the kernel and six frames of physical memory. In the middle, B's and A's page tables and a close-up of the entry for A's page 2. In front, process A's code and the CPU's MMU with its table register. mmap only makes a note; the first store faults and the kernel moves free frame 4 into the entry; the MMU sets A and D; mprotect clears R/W; munmap frees frame 4; a context switch points the table register at B's table. The drawing shows three pages per process and six frames, numbered from 0. On a real 64-bit system mmap returns a large address, and the table has several levels; the lesson Multi-level page tables shows how.

The table

  1. The kernel keeps one page table for each process, in the kernel's own memory. Entry n says which physical frame holds that process's page n. The CPU's MMU reads the table on every access; only the kernel writes it.

Building an entry

Changing and switching

What happens

;; step 1/10 · per-process
page table   one per process, in kernel memory
             entry n  ->  the frame holding page n

A's table    page 0 -> frame 3   page 1 -> frame 1
             page 2 -> (none)
B's table    page 0 -> frame 0   page 1 -> frame 2
             page 2 -> (none)
free frames  4, 5

MMU (hardware)   reads entries on every access
kernel           writes them

The drawing shows three pages per process and six frames, numbered from 0. On a real 64-bit system mmap returns a large address, and the table has several levels; the lesson Multi-level page tables shows how. Real x86 entries have more bits (PWT, PCD, PAT and G for caching, and on x86-64 an execute-disable bit). RISC-V, used by MIT 6.1810, names its flags V, R, W, X and U, with A and D besides.