4.1.11 · D1Computer Architecture (Deep)

Foundations — Replacement policies — LRU, LFU, FIFO, Random

1,827 words8 min readBack to topic

Before you can compare LRU, LFU, FIFO, and Random, you must be fluent in the words and symbols the parent note throws at you without pausing. This page builds every one of them from zero. Read top to bottom; each idea uses only the ones above it.


1. What is a cache, physically?

Picture a desk with only a few slots. The library (main memory) is huge but far away; the desk (cache) is tiny but right in front of you.

Figure — Replacement policies — LRU, LFU, FIFO, Random

The word slot (also called a line, way, or frame) is one place on the desk that can hold exactly one block. The parent note says "capacity = 3" — that means three slots.

Recall Why a cache exists at all

Because main memory is ~100× slower to reach. Keeping likely-reused data close saves that trip. See Cache Memory Fundamentals and AMAT and Memory Hierarchy.


2. Block and access sequence — the symbols

The picture: a conveyor belt of requests marching at the cache. Each arrival forces the cache to answer "do I have you already, or must I load you?"

Figure — Replacement policies — LRU, LFU, FIFO, Random

3. Hit and miss — the two outcomes

Picture two coloured lamps over the desk: green = hit (item already here), red = miss (fetch trip needed).


4. Evict and victim

Picture: the desk is full, a new book arrives, your hand hovers over the three books deciding which one to shelve away. That hovering hand is the policy.


5. Locality — the bet that makes caches work

These aren't laws — they are observed tendencies of real programs (loops re-touch the same variables; arrays are walked in order). Prerequisite: Temporal and Spatial Locality.


6. Recency vs frequency vs age — the three rulers

The four policies differ only in which property of a block they measure. Three different rulers:

Ruler Plain meaning Picture
Recency how long since this block was last touched a stopwatch that resets every time you use the block
Frequency how many times this block has been touched ever a tally counter that only goes up
Age how long since this block was first loaded a stopwatch that starts on arrival and never resets
Figure — Replacement policies — LRU, LFU, FIFO, Random

Now the parent's four rules read plainly:

  • LRU evicts the block with the largest recency (untouched longest).
  • LFU evicts the block with the smallest frequency (touched fewest times).
  • FIFO evicts the block with the largest age (loaded first).
  • Random ignores all rulers and picks uniformly.

7. The symbols in the AMAT formula

The parent writes Every symbol, defined from zero:


8. The symbol (stack property)

The parent writes . From zero:

Picture two nested boxes: the small cache's contents always sit inside the big cache's contents. When that nesting always holds, adding slots can only help — misses never rise. That is the stack property, and it's why LRU/LFU can't suffer Belady's anomaly. See Set-Associative Mapping for what a "set" of slots is.


9. The symbol (why exact LRU is expensive)

Putting them together: storing one of orderings needs bits. For a -way cache, , needing about bits per set — costly. That is why real hardware uses Pseudo-LRU and Tree-PLRU with only bits.


10. How it all feeds the topic

Cache = tiny fast box of slots

Block = one data chunk labelled A B C

Access sequence = requests in time order

Hit vs Miss outcome

Full cache forces Eviction of a Victim

Locality = recent stays useful

Which ruler? Recency Frequency Age

The four policies LRU LFU FIFO Random

Count misses gives miss rate m

AMAT formula grades a policy

Subset symbol and stack property

Factorial and log2 = LRU cost

Parent topic 4.1.11

Every arrow says "you need the left idea before the right one makes sense."


Equipment checklist

Cover the right side and answer each before moving on.

What is a cache slot (line / way / frame)?
One place in the cache that holds exactly one block.
What do the letters stand for in a trace?
Just labels for four distinct data blocks — not numbers.
Difference between a hit and a miss?
Hit = block already in cache; miss = not present, must load (and maybe evict).
What is a victim?
The block the policy chooses to evict to free a slot.
Recency vs frequency vs age in one line each?
Recency = since last use; frequency = total times used; age = since first loaded.
Why is temporal locality the "bet" behind LRU?
Recently used blocks are likely used again soon, so keep them.
In AMAT, what are , , ?
Cache-probe time, miss rate (fraction of misses), extra time a miss adds.
Why does ?
Every request either hits or misses, so the two fractions cover everything.
What does mean and why care?
Smaller cache's blocks are all in the bigger cache — the stack property banning Belady's anomaly.
Why does exact LRU need bits?
It must remember the full recency ordering of ways, and there are orderings.