← back to hub

page faults & swapping

1. The Page Fault Trap

What happens when the CPU asks for data that isn't in RAM?

  • If the MMU checks the Page Table and finds the "Valid Bit" is 0, it triggers a Page Fault.
  • The CPU instantly freezes. The OS Kernel takes over, finds the missing data on the slow Hard Drive, and loads it into a RAM frame.

2. Eviction & LRU

How do we make room if RAM is 100% full?

  • The OS must evict (kick out) an existing page. To minimize future slowdowns, it uses the LRU (Least Recently Used) algorithm.
  • It looks for the page that hasn't been touched for the longest time and "swaps" it out to the Disk.

3. Thrashing (The Death Spiral)

Why do old computers get so slow?

  • If your apps need more RAM than you physically have, the OS spends 99% of its time moving data back and forth from the Disk.
  • Because the Disk is 1000x slower than RAM, the CPU sits idle waiting for memory. This is called Thrashing.
Request Page:
Physical RAM (4 Frames)
⚠️ PAGE FAULT!
Hard Drive (Swap Space)
Total Requests: 0
RAM Hits: 0
Page Faults: 0

System Speed: 100%
Kernel Memory Log