1. The Need for Page Replacement
When a page fault occurs and all physical memory frames are occupied, the operating system kernel must choose an existing page to evict from physical RAM. If the evicted page was modified while in memory (M = 1), it must be written back to disk; if unmodified, the incoming page overwrites the frame directly.
While the Least Recently Used (LRU) policy is theoretically optimal among practical algorithms, recording an exact LRU sequence in hardware requires updating a counter or moving a linked-list node on every single memory reference, introducing severe memory bus latency.
2. Second-Chance and the Clock Optimization
A practical approximation of LRU is the Second-Chance replacement policy. The OS examines the Referenced (R) bit in the hardware page table entry:
- If R = 0: The page is old and has not been referenced recently. It is evicted immediately.
- If R = 1: The page was recently referenced. The OS clears R o 0, grants it a second chance, and inspects the next candidate.
Second-chance requires moving unreferenced pages to the tail of a linked list, which is unnecessarily slow. The Clock Algorithm eliminates this list-shuffling overhead by arranging all page frames into a circular buffer governed by a single rotating clock hand.
Part 3: Interactive Clock Algorithm Sandbox
Issue page references, inspect the circular pointer sweep, and toggle referenced bits on the live canvas.
H) in the input box and click Access Page. If resident → Hit (R o 1, hand stays put). If absent → Fault (hand sweeps to find and evict an R=0 victim).
0 simultaneously.
I and click Access Page. Watch the animated sweep step through Frame 0 (giving a second chance: R=1 o 0) and evict Frame 1 (where R=0).
| Frame | Page | R Bit | Pointer | Action |
|---|