Course contentsShow
← Computer Science
Lesson 1366 of 2,87231. Memory ManagementFree lesson

Page Replacement Problem

Understanding why page replacement is needed when physical memory is full and a page fault occurs.

Page Replacement Problem

You'll learn why operating systems must decide which page to evict when physical memory is full and a new page is needed.

The Core Challenge

Imagine you have a bookshelf with limited space (physical memory) but hundreds of books to reference (virtual memory pages). When you need a book that's not on the shelf, you experience a page fault and must retrieve it from storage. But what if the shelf is completely full?

This is the page replacement problem: when physical memory (RAM) contains no free frames and a page fault occurs, the OS must choose an existing page to evict (swap out to disk) to make room for the incoming page. This decision dramatically impacts performance.

Why It Matters

You've learned that demand paging brings pages into memory only when needed, and that page faults trigger disk I/O—an expensive operation. When memory is full, every page fault requires two disk operations: writing the victim page out (if modified) and reading the new page in.

Choosing poorly means evicting a page you'll need again soon, causing another fault. Choosing wisely means evicting a page that won't be needed for a long time, minimizing future faults.

The Real-World Impact

Consider a system running multiple programs with limited RAM:

  • Good replacement: Evict a page from an idle background process → few subsequent faults
  • Bad replacement: Evict a page your active program needs immediately → thrashing (constant paging)

The page replacement algorithm determines which victim page to select, balancing performance, simplicity, and overhead.

Key Takeaway: The page replacement problem arises when physical memory is full and a page fault occurs; the OS must strategically choose which existing page to evict to make room, as poor choices lead to excessive paging and severe performance degradation.