Storage 3: Eviction policies and coherence

Overview

In this lecture, we talk about some metaphors for caching, present some eviction policies and anomalies, and discuss different types of file.

Full lecture notes on storageTextbook readings

What is a cache?

What makes caches different in computer systems?

Caches in our units so far

Types of file

Coherence and invalidation

Cache slots and access patterns

Hits and misses

How many slots should a cache have?

Multi-slot cache abstraction

Refstr→ 1 2 3 4 1 2 5 1 2 3 4 5
Slot A ~1~ ~1~ ~4~ ~4~ ~5~ ~5~ ~5~ ~5~ 5
B ~2~ ~2~ ~1~ ~1~ 1 ~1~ ~3~ ~3~
C ~3~ ~3~ ~2~ ~2~ 2 ~2~ ~4~
Time→ 1 2 3 4 5 6 7 8 9 10 11 12
FIFO, 3 slots, hit rate 3/12

Associativity

Eviction

Eviction and writes

Eviction policies for fully-associative caches

When a slot is needed, evict the slot that:

Eviction policies for fully-associative caches

When a slot is needed, evict the slot that:

Question

The optimal eviction algorithm

Example

1 2 3 4 1 2 5 1 2 3 4 5
A ~1~ ~1~ ?
B ~2~ ?
C ?
Optimal
1 2 3 4 1 2 5 1 2 3 4 5
A ~1~ ~1~ ~1~ 1 ~1~ ~1~ 1 ~1~ ~3~ ~3~
B ~2~ ~2~ ~2~ 2 ~2~ ~2~ 2 ~2~ ~4~
C ~4~ ~4~ ~5~ ~5~ ~5~ ~5~ 5
Optimal, 3 slots, hit rate 5/12

When can you predict the future?

More slots means better hit rate!

1 2 3 4 1 2 5 1 2 3 4 5
A ~1~ ~1~ ~4~ ~4~ ~5~ ~5~ ~5~ ~5~ 5
B ~2~ ~2~ ~1~ ~1~ 1 ~1~ ~3~ ~3~
C ~3~ ~3~ ~2~ ~2~ 2 ~2~ ~4~
FIFO, 3 slots, hit rate 3/12
1 2 3 4 1 2 5 1 2 3 4 5
A ~1~ ~1~ ~1~
B ~2~ ~2~
C ~3~
D
FIFO, 4 slots, hit rate ?
1 2 3 4 1 2 5 1 2 3 4 5
A ~1~ ~1~ ~1~ 1 ~1~ ~5~ ~5~ ~5~ ~4~
B ~2~ ~2~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