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

Enhanced Second-Chance Algorithm

Using both reference and modify bits to prioritize pages for replacement based on usage.

Enhanced Second-Chance Algorithm

What you'll learn: How the enhanced second-chance page replacement algorithm uses both reference and modify bits to make smarter decisions about which pages to evict from memory.

Why Two Bits Are Better Than One

The basic second-chance algorithm only looked at the reference bit (whether a page was recently accessed). The enhanced version adds the modify bit (whether a page was written to) into the decision-making process. This creates four possible combinations for each page, allowing the OS to be more selective about which pages to replace.

The Four Classes of Pages

The algorithm categorizes pages into four classes based on their (reference, modify) bits:

  1. (0, 0) - Not recently used, not modified — best candidate
  2. (0, 1) - Not recently used, but modified — needs writing to disk
  3. (1, 0) - Recently used, not modified — somewhat valuable
  4. (1, 1) - Recently used and modified — worst candidate to replace

How It Works

The algorithm scans pages in circular order (like a clock hand), searching for the lowest class:

  • First sweep: Look for a (0, 0) page — clean and unused
  • If not found, second sweep: Look for a (0, 1) page — at least not recently used
  • Continue until finding a replacement candidate
  • Clear reference bits during scanning to give pages a "second chance"

The Key Advantage

Think of it like this: A clean shirt you haven't worn recently (0, 0) is easy to give away. A dirty shirt you wore yesterday (1, 1) requires washing first and you might wear it again soon — better to keep it!

By avoiding modified pages when possible, the system saves disk writes, which are expensive operations.

Key Takeaway: The enhanced second-chance algorithm prioritizes evicting clean, unreferenced pages first, minimizing both memory pressure and disk I/O by considering both usage patterns and modification status.