Professional Documents
Culture Documents
08 Memory Hierarchy Updated
08 Memory Hierarchy Updated
08 Memory Hierarchy Updated
Memory Hierarchy
Memory Hierarchy
As you go further, capacity and latency increase
L1 data or
Registers instruction L2 cache Memory
1KB Cache 2MB 1GB Disk
1 cycle 32KB 15 cycles 300 cycles 80 GB
2 cycles 10M cycles
2
Memory Hierarchy
Users want large and fast memories
expensive and they dont like to pay
Make it seem like they have what they want
memory hierarchy
hierarchy is inclusive, every level is subset of lower level
performance depends on hit rates
CPU
Processor
Block of data
(unit of data copy) Increasing distance
Level 1
from the CPU in
access time
Level n
Xn 1 Xn 1
X2 X2
Xn
X3 X3
000
001
010
011
111
100
101
110
recognize valid entry
Memory
Accessing Cache
Example:
offset
In MIPS 20 10
Hit Data
Tag
Index
1021
1022
1023
20 32
offset
In MIPS 20 10
Hit Data
Tag
Index
1021
1022
1023
20 32
Write-back scheme
write the data block only into the cache and write-back the block to main
only when it is replaced in cache
more efficient than write-through, more complex to implement
Direct Mapped Cache: Taking
Advantage of Spatial Locality
Taking advantage of spatial locality with larger blocks:
Address
Addressshowing
(showing bitbit positions
positions)
31 16 15 4 32 1 0
16 12 2 Byte
Hit Tag Data
offset
Index Block offset
16 bits 128 bits
V Tag Data
4K
entries
16 32 32 32 32
Mux
32
Cache with 4K 4-word blocks: byte offset (least 2 significant bits) is ignored, next 2 bits are
block offset, and the next 12 bits are used to index into cache
Direct Mapped vs Set Associative vs
Fully Associative Cache
Direct Mapped
Direct mapped
2-way Set Associative
Set associative
Fully Associative
Fully associative
Block # 0 1 2 3 4 5 6 7 Set # 0 1 2 3
12 mod 8 = 4 12 mod 4 = 0
1 1 1
Tag Tag Tag
2 2 2
4 1
5 2
6 3
3 misses
Implementation of a Set-Associative
Cache
Address
Address
31 30 12 11 10 9 8 321 0
22 8
4-to-1 multiplexor
Hit Data
4-way set-associative cache with 4 comparators and one 4-to-1 multiplexor:
size of cache is 1K blocks = 256 sets * 4-block set size
Multilevel Caches
Page
Virtual Address
Virtual addresses Physical Address
Physical addresses
Address translation
Main Memory
Virtual
Memory
Disk addresses
Secondary Storage
Virtual address
31 30 29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
Page table
18
If 0 then page is not
present in memory
29 28 27 15 14 13 12 11 10 9 8 3 2 1 0
Physical address
1
1
1
1
0
1
1
0
1 Disk storage
1
0
1
1
1
1 Physical memory
1
0
1
Page table
Physical p
Valid age
or disk address
1
1
1
Disk storage
1
0
1
1
0
1
1
0
1
On a page reference, first look up the virtual page number in the TLB; if
there is a TLB miss look up the page table; if miss again then true page fault