8. Page replacement
One-liner. You cannot beat OPT; you can approximate it cheaply.
Memorize
- OPT/Belady: evict the page used farthest in the future — optimal, unimplementable, a benchmark.
- FIFO: simple; can suffer Belady's anomaly (more frames, more faults).
- LRU: stack algorithm, never suffers Belady's anomaly, needs per-access bookkeeping.
- CLOCK / second chance: approximates LRU with a reference bit — the practical default.
- LFU: frequency-based, stale-heavy pages linger.
- Working set (Denning): keep the pages used in the last Δ; WSClock combines it with CLOCK.
- Thrashing: fault rate rises, CPU utilization falls, the OS adds more processes and makes it worse.
- Local vs global replacement changes whether one process can evict another's working set.
Trap. Adding more processes when the system thrashes — that lowers CPU utilization further. Do this. Watch page-fault rate and PSI memory; reduce the working set or add RAM.
Check
Which property does LRU have that FIFO lacks?
Why
Stack algorithms have the inclusion property: more frames never cause more faults.