Storage 3: Eviction policies and coherence

Overview

In this lecture, we present some eviction policies and anomalies, and discuss different types of file.

Full lecture notes on storageTextbook readings

Cache slots and access patterns

Hits and misses

How many slots should a cache have?

Multi-slot cache abstraction

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

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

More slots means better hit rate for LRU

1 2 3 4 1 2 5 1 2 3 4 5
A
B 1
C 2
LRU, 3 slots, hit rate 2/12
1 2 3 4 1 2 5 1 2 3 4 5
A 1 1
B 2 2
C
D
LRU, 4 slots, hit rate 4/12

Cache correctness

coherence.cc

Forking, piping, and stdio

Streams vs. random-access files

Special files

Streams

Write semantics

Memory mapping