The table
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.
Zoom into A's page 2. An x86 entry holds a frame number and flag bits: P (present), R/W (writes allowed), U/S (user mode allowed), A (accessed) and D (dirty: written). This one is all zeros: page 2 is not mapped.
Building an entry
mmap asks the kernel for one page of fresh memory. The kernel only writes a note in its own records: A may use page 2. It takes no frame yet and leaves the entry at P = 0.
Line 2 stores x in page 2. The MMU reads the entry, finds P = 0 and traps to the kernel: a page fault. The kernel checks its notes. Page 2 is valid, just not filled in yet.
The kernel takes free frame 4 and fills it with zeros. Then it writes the entry: frame 4, P = 1, R/W = 1, U/S = 1. It returns from the trap, and the CPU retries the store.
This time the MMU finds frame 4, and x lands there. The MMU itself sets A, because the page was used, and D, because it was written. Later the kernel reads these bits to choose which pages to keep.
Changing and switching
mprotect asks the kernel to make the page read only. The kernel clears R/W and makes the CPU drop any cached copy of the entry. Reads still work; a write would fault, and the kernel would stop the program with SIGSEGV, the segmentation-fault signal.
munmap gives the page back. The kernel clears the entry, so P = 0 again, flushes the cached copy and puts frame 4 back on its free list. Touching page 2 now would end the program with SIGSEGV.
When A's turn ends, the kernel switches to process B. Besides the registers, it writes the address of B's table into the CPU's table register (CR3 on x86-64). Only kernel mode may. Now page 1 means frame 2, not frame 1.
A process can only reach the frames its own table lists, and only the kernel can edit a table or point the CPU at one. Building entries, setting bits and switching tables is how the kernel gives every process its own memory.
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.