Associative Mapping
Associative Mapping
Associative Caches
Fully associative
Allow a given block to go in any cache entry
Requires all entries to be searched at once
Comparator per entry (expensive)
n-way set associative
Each set contains n entries
Block number determines which set
(Block number) modulo (#Sets in cache)
Search all entries in a given set at once
n comparators (less expensive)
Chapter 5 — Large and Fast: Exploiting Memory Hierarchy — 2
Associative Cache Example
0 0 miss Mem[0]
8 0 miss Mem[8]
0 0 miss Mem[0]
Chapter 5 — Large and Fast: Exploiting Memory Hierarchy — 5
6 2 miss Mem[0] Mem[6]
Associativity Example
2-way
Block
address
set
Cacheassociative
index
Hit/miss Cache content after access
Set 0 Set 1
0 0 miss Mem[0]
Fully
6
associative
0 miss Mem[0] Mem[6]
0 miss Mem[0]
31 10 9 4 3 0
Tag Index Offset
18 bits 10 bits 4 bits
Read/Write Read/Write
Valid Valid
32 32
Address Address
32 Cache 128 Memory
CPU Write Data Write Data
32 128
Read Data Read Data
Ready Ready
Multiple cycles
per access
Could partition
into separate
states to
reduce clock
cycle time
0 0
1 CPU A reads X 0 0
2 CPU B reads X 0 0 0
3 CPU A writes 1 to X 1 0 1
Chapter 5 — Large and Fast: Exploiting Memory Hierarchy — 53
Coherence Defined
Informally: Reads return most recently
written value
Formally:
P writes X; P reads X (no intervening writes)
read returns written value
P1 writes X; P2 reads X (sufficiently later)
read returns written value
c.f. CPU B reading X after step 3 in example
P1 writes X, P2 writes X
all processors see writes in the same order
End up with the same final value for X