A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Page Replacement Algorithms

College Depth 98 in the knowledge graph ☐ I know this ☆ Set as goal
3topics build on this
363prerequisites beneath it
See this on the map →
Virtual Memory and Demand PagingCache Replacement Policies→→Demand Paging and Page FaultsThrashing and the Working Set Model
page-replacement FIFO LRU optimal clock-algorithm Belady-anomaly

Core Idea

When a page fault occurs and no free frames exist, the OS must evict a page — the page replacement algorithm chooses which one. The Optimal algorithm (OPT) evicts the page that will be used furthest in the future, minimizing page faults, but requires future knowledge so it serves only as a theoretical benchmark. FIFO evicts the oldest page but exhibits Belady's Anomaly (more frames can cause more faults). LRU (Least Recently Used) approximates OPT by evicting the page unused longest and is well-supported by the principle of temporal locality. The Clock (Second-Chance) algorithm approximates LRU efficiently using a reference bit and a circular scan, and is widely used in practice.

How It's Best Learned

Apply each algorithm to the same reference string (e.g., 1,2,3,4,1,2,5,1,2,3,4,5) with 3 frames, counting page faults. Then verify Belady's anomaly by running FIFO with 4 frames on the same string.

Common Misconceptions

Explainer

From virtual memory management, you know that a process's address space can be larger than physical memory. The OS maps virtual pages to physical frames, and when a process accesses a page that is not currently in memory, a page fault occurs and the OS must load that page from disk. If all physical frames are already occupied, the OS must evict one page to make room. The page replacement algorithm decides which page gets evicted — and this choice has a dramatic effect on performance, because a bad choice means the evicted page will be needed again soon, causing another expensive page fault.

The Optimal algorithm (OPT, also called Belady's algorithm) provides the theoretical best answer: evict the page that will not be used for the longest time in the future. If page A will next be accessed in 100 instructions and page B will next be accessed in 5 instructions, evict A. This minimizes total page faults, but it requires knowing the future access pattern — impossible in a real system. OPT serves as a benchmark: you can run it on a recorded trace to see how close your real algorithm comes to the theoretical minimum.

FIFO (First-In, First-Out) is the simplest practical algorithm: evict the page that has been in memory the longest. It requires only a queue — load a page, push it to the back; evict from the front. FIFO is easy to implement but performs poorly because "oldest" does not mean "least useful." A page loaded long ago might be accessed constantly (think: a loop's code page). FIFO's most surprising property is Belady's Anomaly: increasing the number of available frames can actually *increase* page faults for certain reference strings. This is counterintuitive — more memory should help — and it reveals that FIFO's eviction criterion is fundamentally misaligned with what matters (recency of use, not age of loading).

LRU (Least Recently Used) fixes this by evicting the page that has gone the longest *without being accessed*. The reasoning comes from temporal locality, a principle you know from cache replacement: if a page was used recently, it is likely to be used again soon. LRU never exhibits Belady's Anomaly and closely approximates OPT in practice. However, exact LRU is expensive — tracking the precise access order of all pages requires either a timestamp on every memory access or maintaining a stack of page numbers, both of which are prohibitively costly in hardware. This is why real systems use approximations. The Clock algorithm (Second-Chance) is the most common: each page has a reference bit set by hardware whenever the page is accessed. The algorithm sweeps through pages in a circle. If a page's reference bit is 1, it gets a "second chance" — the bit is cleared and the algorithm moves on. If the bit is 0, that page has not been accessed since the last sweep and is evicted. Clock approximates LRU with minimal overhead — just one bit per page and a circular pointer — making it the algorithm most widely deployed in real operating systems.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy → Cache Memory Design → Cache Replacement Policies → Virtual Memory and Paging → Virtual Memory and Demand Paging → Page Replacement Algorithms

Longest path: 99 steps · 363 total prerequisite topics

Prerequisites (2)

Leads To (2)