4.1.11 · D5Computer Architecture (Deep)
Question bank — Replacement policies — LRU, LFU, FIFO, Random
True or false — justify
Every eviction decision considers all blocks in the entire cache.
False. With Set-Associative Mapping a block maps to exactly one set; the policy picks a victim only among that set's ways. Direct-mapped is the extreme: one candidate, so no policy is needed.
In a direct-mapped cache, LRU, FIFO and Random all behave identically.
True. A direct-mapped cache has one way per set, so there is only ever one possible victim. The "policy" has no choice to make, so all four collapse to the same behaviour.
On a cache hit, LRU changes its internal state but FIFO does not.
True. LRU resets that block's recency to "most recent" on every touch; FIFO's insertion-order queue is untouched by a hit. This single asymmetry is the whole difference between them.
If two policies produce the same eviction on one trace, they are the same policy.
False. They only agreed on that trace. A policy is defined by its rule for all possible traces; you can always construct a trace where LRU and FIFO diverge (any trace with a hit to a non-newest block).
Belady's OPT gives the minimum possible number of misses for a given cache size.
True. OPT evicts the block whose next use is farthest away, which is provably miss-optimal. It is unimplementable because it needs future knowledge, but it is the yardstick every real policy is measured against — see Belady's Optimal Algorithm.
LRU can suffer Belady's anomaly if the trace is adversarial enough.
False. LRU is a stack algorithm: a size- cache's contents are always a subset of size-'s, so misses are monotonically non-increasing in size. No trace can make more cache hurt LRU.
Adding one more way to a FIFO cache can never increase the miss count.
False. This is exactly Belady's anomaly — the classic trace
1,2,3,4,1,2,5,1,2,3,4,5 gives 9 misses at 3 frames but 10 at 4. FIFO's queue changes shape with size, breaking the subset property.Random replacement has a pathological worst-case trace that makes it thrash badly.
False. Because Random ignores all history, an adversary has no lever to pull; there is no input that reliably forces bad evictions. This lack of a worst case is precisely why Random is respected despite zero metadata.
LFU always keeps the objectively most-useful blocks because popularity predicts the future.
False. This ignores stale popularity: a block accessed 1000× in the distant past keeps a huge count and refuses to leave even after it is dead. Real LFU needs aging (periodic count decay) to fix this pollution.
The AMAT formula drops on a miss because a miss goes straight to memory.
False. A miss still probes the cache first and fails, then goes to memory — so it pays . Algebra collapses to , keeping always. See AMAT and Memory Hierarchy.
Pseudo-LRU (tree-PLRU) always evicts exactly the same block as true LRU.
False. Tree-PLRU uses only ~ bits and tracks an approximate order, so it can occasionally pick a different victim. It is "good enough" and far cheaper than the bits true LRU needs — see Pseudo-LRU and Tree-PLRU.
A larger cache with a good policy can still have a higher miss rate on a specific short trace than a smaller cache.
False for stack algorithms (LRU/LFU): more size never increases misses. True only for FIFO/non-stack policies, which is the anomaly. Be precise about which policy before answering.
Spot the error
"LRU evicts the oldest block, i.e. the one that entered the cache longest ago."
The error is confusing recency with insertion age. LRU evicts the least-recently-used block; a very old block that was just touched is safe. The stated rule is actually FIFO.
"FIFO promotes a block to the front of the queue whenever it's re-accessed."
FIFO never reorders on a hit — that is its defining property. Promoting on access would turn it into (approximately) LRU. FIFO's queue only changes when a block is inserted or evicted.
"Since Random has no metadata, it can't be implemented in real hardware."
Backwards — having no metadata makes it the cheapest to implement (often just a free-running counter or LFSR). Zero bookkeeping is an advantage, not a blocker.
"To avoid Belady's anomaly, just always make the cache bigger."
For FIFO, a bigger cache is exactly what can trigger the anomaly, so this can backfire. The real fix is to use a stack algorithm (LRU/LFU), which is anomaly-proof at any size.
"LFU breaks the stack property because counts change over time."
LFU is a stack algorithm — a smaller LFU cache's contents remain a subset of the larger one for the same trace. Changing counts don't violate the subset relation; the ordering by frequency is size-independent, just like LRU's ordering by recency.
"AMAT improves only if you increase speed; the policy is irrelevant."
The policy directly controls the miss rate , and dominates when . A better policy that lowers is often the biggest AMAT lever available.
Why questions
Why can't we just use Belady's OPT in real caches, since it's optimal?
Because OPT requires knowing each block's next use time in the future, which hardware does not have at eviction time. It is a theoretical benchmark, not a buildable policy.
Why does a replacement policy exist at all — why not evict any full block?
Because the choice of victim decides your future hit rate. Locality means the right victim (unlikely to be reused) preserves data you'll actually need soon; a wrong choice causes thrashing.
Why do CPUs use pseudo-LRU instead of exact LRU on high-associativity caches?
Exact LRU must store a full ordering of the ways, costing bits per set (painful at 16-way). Tree-PLRU approximates it with only ~ bits, trading a little accuracy for a lot of area savings.
Why does LRU exploit temporal locality specifically?
Temporal locality says recently-used data tends to be reused soon. LRU's proxy — "keep the recently-touched, evict the stale" — is a direct bet on that pattern, which is why it usually beats FIFO.
Why is FIFO cheap but risky?
It needs only one pointer into a queue (cheap), but it ignores usage entirely, so it can evict a hot block just because it entered early — mediocre prediction and vulnerable to Belady's anomaly.
Why does halving the miss rate roughly halve AMAT in the parent's example?
With and , the term dwarfs the constant . So AMAT , and halving nearly halves the total — the penalty is the leverage point.
Why is per-set reasoning essential when comparing policies?
Because a policy only chooses among the ways of one set (Set-Associative Mapping). Two blocks in different sets never compete for eviction, so global "which is oldest" intuition is misleading.
Edge cases
What does any policy do when the cache is not yet full and a miss occurs?
It simply loads the new block into a free slot — no eviction happens because there is room. Policies only differ once every slot in the relevant set is occupied.
What happens on a hit for FIFO versus LRU when the block is already the newest inserted?
For both, the queue/order is effectively unchanged (LRU re-marks it most-recent, which it already was). The policies only visibly diverge when the hit lands on a non-newest block.
In a direct-mapped cache, does the replacement policy ever matter?
No. One way per set means a single forced victim; every policy makes the same "choice", so LRU/LFU/FIFO/Random are indistinguishable there.
What does LFU do when two blocks are tied on frequency count?
The rule is under-specified, so a tie-breaker is needed — commonly evict the least-recently-used among the tied blocks (LFU-with-LRU-tiebreak) or the oldest. Without a stated tie-break, the answer is ambiguous.
What is the miss rate on a trace where every access is to the same single block after the first?
After the first (compulsory) miss loads it, every later access is a hit for all policies, because the block is never evicted while it's the only one being used. Miss rate approaches 0 regardless of policy.
For an access sequence longer than the cache with all distinct blocks (no reuse), how do the policies compare?
Every access is a compulsory miss for all of them, so miss counts are equal. Replacement policy only creates differences when there is reuse to reward or punish.
What happens to LFU counters if a block is evicted and later re-loaded — does it remember its old count?
Standard LFU resets the counter to a fresh value on re-insertion, since the block's metadata left with it. This is actually protective: it prevents an evicted-then-returned block from instantly reclaiming stale high popularity.
Does Random ever guarantee it won't evict the block you're about to use next?
No guarantee — Random can, on any single decision, evict the soon-needed block. Its strength is statistical: over many decisions no adversary can force this consistently, so average behaviour stays close to LRU.
Recall One-line self-test before you leave
Ask yourself: "Did a hit change who gets evicted?" If yes → LRU-family. "Can more cache hurt me?" If yes → you're on FIFO. "Do I need future knowledge?" If yes → that's OPT, and you can't build it.