CS 152 Computer Architecture and Engineering Lecture 7 - Memory Hierarchy-II
CS 152 Computer Architecture and Engineering Lecture 7 - Memory Hierarchy-II
Krste Asanovic
Electrical Engineering and Computer Sciences University of California at Berkeley http://www.eecs.berkeley.edu/~krste http://inst.eecs.berkeley.edu/~cs152
Cache holds small set of values in fast memory (SRAM) close to processor
Need to develop search scheme to find values in cache, and replacement policy to make space for newly accessed locations
2/17/2009 CS152-Spring09 2
Placement Policy
Block Number
1111111111 2222222222 33 0123456789 0123456789 0123456789 01
Memory
Set Number
01234567
Cache
Fully Associative anywhere (2-way) Set Associative anywhere in set 0 (12 mod 4) Direct Mapped only into block 4 (12 mod 8)
3
CS152-Spring09
Direct-Mapped Cache
Tag t V Tag Index k
Block Offset
Data Block
2k lines t =
HIT
2/17/2009 CS152-Spring09
Tag
= HIT
Block Offset
b
2/17/2009
Replacement Policy
In an associative cache, which block from a set should be evicted when the set becomes full? Random
Least Recently Used (LRU)
LRU cache state must be updated on every access true implementation only feasible for small sets (2-way) pseudo-LRU binary tree often used for 4-8 way used in highly associative caches
CS152-Spring09
block address
offsetb
b bits 32-b bits 2b = block size a.k.a line size (in bytes) Larger block size has distinct hardware advantages
less tag overhead exploit fast burst transfers from DRAM exploit fast burst transfers over wide busses
CPU-Cache Interaction
(5-stage pipeline)
0x4
Add
nop
PC addr inst hit?
IR D
ALU
PCen
MD1
MD2
Stall entire CPU on data cache miss To Memory Control Cache Refill Data from Lower Levels of Memory Hierarchy
2/17/2009
CS152-Spring09
2/17/2009
CS152-Spring09
10
Processor
Data
CACHE
Data
Main Memory
tcache + (1 - ) tmm e
Main Memory
Processor
Data
CACHE
Data
tmm e
tcache + (1 - ) high
High bandwidth required for memory path Complexity of handling parallel paths can slow tcache
2/17/2009 CS152-Spring09
start misses
Capacity: cache is too small to hold all data needed by the program
- misses that would occur even under perfect replacement policy
2/17/2009
CS152-Spring09
12
Higher associativity
2/17/2009
CS152-Spring09
13
write back: write cache only (memory is written only when the entry is evicted)
a dirty bit per block can further reduce the traffic
Cache miss:
no write allocate: only write to main memory write allocate (aka fetch on write): fetch into cache
Common combinations:
2/17/2009
write through and no write allocate write back with write allocate
CS152-Spring09 14
Write Performance
Tag t V Tag Index k
Block Offset
b Data 2k lines t = WE
HIT
2/17/2009
CS152 Administrivia
2/17/2009
CS152-Spring09
17
Tag
Index
Store Data
Delayed Write Data
=?
Tags
=?
S L
Data
1 0
Hit?
Data from a store hit written into data portion of cache during tag access of subsequent store
2/17/2009 CS152-Spring09
18
Evicted dirty lines for writeback cache OR All writes in writethru cache
Processor is not stalled on writes, and read misses can go ahead of write to main memory
Problem: Write buffer may hold updated value of location needed by a read miss Simple scheme: on a read miss, wait for the write buffer to go empty Faster scheme: Check write buffer addresses against read miss addresses, if no match, allow read miss to go ahead of writes, else, return value in write buffer
2/17/2009 CS152-Spring09 19
Block-level Optimizations
Tags are too large, i.e., too much overhead
Simple solution: Larger blocks, but miss penalty could be large.
1 1 0
1 1 1
1 0 0
1 0 1
20
CS152-Spring09
Not energy-efficient
A tag and data word is read from every way
Two-phase approach
=? =?
First read tags, then just read data from selected way More energy-efficient Doubles latency in L1 OK, for L2 and above, why?
Tag
Index
Offset
2/17/2009
CS152-Spring09
21
Multilevel Caches
A memory cannot be large and fast Increasing sizes of cache at each level
CPU
L1$
L2$
DRAM
Local miss rate = misses in cache / accesses to cache Global miss rate = misses in cache / CPU memory accesses Misses per instruction = misses in cache / number of instructions
2/17/2009
CS152-Spring09
22
CPU
RF Multiported register file (part of CPU)
2/17/2009
CS152-Spring09
23
2/17/2009
CS152-Spring09
24
Inclusion Policy
Inclusive multilevel cache:
Inner cache holds copies of data in outer cache External access need only check outer cache Most common case
2/17/2009
CS152-Spring09
25
Acknowledgements
These slides contain material developed and copyright by:
Arvind (MIT) Krste Asanovic (MIT/UCB) Joel Emer (Intel/MIT) James Hoe (CMU) John Kubiatowicz (UCB) David Patterson (UCB)
MIT material derived from course 6.823 UCB material derived from course CS252
2/17/2009
CS152-Spring09
27