8. Simulating LRU: The Aging Algorithm

Tanenbaum Section 3.4.5 (Fig. 3-17): Right-shift history registers, MSB insertion of R-bits, and multi-tick LRU approximation.

1. The Limitation of Simple Second-Chance

While the Clock algorithm (second-chance) avoids the heavy overhead of strict LRU, it is relatively coarse-grained. It only remembers whether a page was referenced during the current sweep cycle (R = 1 or R = 0). It cannot distinguish between a page referenced 10 instructions ago versus one referenced 10,000 instructions ago.

2. The Aging Algorithm Solution & The Referenced (R) Bit

To capture more precise access history without full LRU matrix overhead, operating systems use the Aging Algorithm. Each physical page frame is assigned a fixed-width binary history register (typically 8 bits wide, corresponding to 8 consecutive clock ticks).

The foundation of aging relies on the hardware Referenced (R) bit. Whenever the CPU accesses a virtual address, the memory management unit (MMU) automatically sets the page's R bit to $1$. Because the MMU never clears this bit on its own, the OS uses periodic clock ticks to read, shift, and reset it.

  • Clock Tick Interception: At regular hardware clock intervals, the OS interrupts execution and performs a right-shift operation on every page's counter: Ri \to Ri \gg 1.
  • MSB Injection (R \to MSB): During the shift, the current hardware Referenced (R) bit is inserted into the most significant bit (MSB, position 7) of the register: R7 = R.
  • Eviction Policy: When a page fault occurs, the kernel scans all frame registers as unsigned integers. The page with the lowest numerical value is chosen as the victim (indicating it has not been referenced for the longest sequence of ticks).
Tanenbaum's Aging Principle (Fig. 3-17):
An 8-bit history register records access over the last 8 clock ticks. For example, a register value of `10001000` (136 decimal) means the page was referenced 8 ticks ago and 4 ticks ago. A value of `10000000` (128 decimal) indicates a reference at the most recent interval (shifted into the MSB), while `00000001` (1 decimal) indicates a reference at the oldest tracked interval. Aging provides an exceptional approximation of true LRU.
Step 1 of 4 Interactive Aging Stepper
1. Initial State across 4 Frames

Part 3: Interactive Aging Algorithm Sandbox

Trigger clock ticks, shift history registers, and observe victim selection based on lowest unsigned integer values.

Total Accesses: 0 Hits: 0 Faults: 0 Clock Ticks: 0
Physical Frame Registers (8-bit)
FramePageHardware R8-Bit Register (Binary Cells)Decimal
Kernel Aging Log