KERNELFRAME 5pg 0FRAME 6pg 1SLOT 0pg 2SLOT 1pg 3SLOT 2—PAGE 0F5PAGE 1F6PAGE 2S0PAGE 3S1CPUPAGEFRAME1mem[0x0008] = 72x = mem[0x2010]3y = mem[0x9000]PROCESS Prunning0x00080x50080x20100x50100x9000S0pg 0pg 2SIGSEGV
Back: the kernel, RAM (2 frames) and swap space on disk (3 slots)Middle: P's page table and the CPU with its MMU; front: the program and process PTokens: addresses, pages moving between RAM and disk, the fault and the signalAt the back, the kernel, RAM (frames 5 and 6) and swap space on a disk (slots 0 to 2). In the middle, process P's page table and the CPU with its MMU. In front, the program card and process P. Address 0x0008 is in RAM and goes straight through. Address 0x2010 is on disk: the kernel evicts dirty page 0, reads page 2 in, fixes the entry and re-runs the line. Address 0x9000 is not P's at all, and P gets SIGSEGV. The card is pseudo-code: mem[a] means the bytes at virtual address a. Addresses are in hexadecimal; 0x1000 is 4096, one page.

Pages in RAM and on disk

  1. Process P has four 4 KB pages, but only two RAM frames, 5 and 6. Pages 2 and 3 wait on disk, in swap space. Each page table entry says where: F5 means present in frame 5; S0 means not present, in swap slot 0.

Handling a page fault

Limits and cost

What happens

;; step 1/10 · pages
page table of P (one entry per 4 KB page)
  page 0   F5   present bit 1, frame 5
  page 1   F6   present bit 1, frame 6
  page 2   S0   present bit 0, swap slot 0
  page 3   S1   present bit 0, swap slot 1

RAM (P may use 2 frames)   frame 5: page 0   frame 6: page 1
swap space on disk         slot 0: page 2    slot 1: page 3
                           slot 2: free

The machine is a toy: four 4 KB pages, two frames and three swap slots. Real processes have many thousands of pages, and the kernel shares all of RAM between them. F5 and S0 are this figure's shorthand for a page table entry. A real entry packs a present bit, a dirty bit, permission bits and either a frame number or a disk address into one 64-bit word.