LRU

What it does

Replaces the page that has not been used for the longest time in the past. Assumes recently used pages will be used again soon.

How it works

  • Keep track of last-used time for each page.

  • On page fault:

    • Replace the page that was used least recently.

Can be implemented using:

  • Timestamps (expensive), or
  • Stack / linked list (updated on every access)

Pros

  • Performs well in practice.
  • No Belady’s anomaly.

Cons

  • More complex to implement.
  • Slower than FIFO if done in software.

Example

Same reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2

Frames: 3

StepPageFramesPage Fault?Explanation
177 _ _✅First use
207 0 _✅Add 0
317 0 1✅Add 1
420 1 2✅ (7 out)7 least recently used
500 1 2❌Used recently
630 2 3✅ (1 out)1 LRU
700 2 3❌In memory
840 3 4✅ (2 out)2 LRU
920 4 2✅ (3 out)3 LRU
1030 2 3✅ (4 out)4 LRU
1100 2 3❌In memory
1230 2 3❌In memory
1320 2 3❌In memory
  • Total Page Faults: 10
Last updated on