Memory - System - Cache - Memory and Virtual Memory
Memory - System - Cache - Memory and Virtual Memory
Memory
CPU
Processor
Block of data
(unit of data copy) Increasing distance
Level 1
from the CPU in
access ti me
Level n
hits
miss rate = 1 – hit rate
hit time: time to determine if the access is indeed a
X4 X4
Reference to Xn
X1 X1
causes miss so
Xn – 2 Xn – 2
it is fetched from
memory
Xn – 1 Xn – 1
X2 X2
Xn
X3 X3
000
001
010
011
111
100
101
110
also need a valid bit to recognize valid entry
Memory
Accessing Cache
Example:
(0) Initial state: (1) Address referred 10110 (miss):
Index V Tag Index V Tag Data
Data 000 N
000 N 001 N
001 N 010 N
010 N 011 N
011 N 100 N
100 N 101 N
101 N 110 Y 10 Mem(10110)
110 N 111 N
111 N
(3) Address referred 10110 (hit):
(2) Address referred 11010 (miss):
Index V Tag Data Index V Tag Data
000 N 000 N
001 N 001 N
010 Y 11 Mem(11010) 010 Y 11 Mem(11010)
011 N 011 N
100 N 100 N to CPU
101 N 101 N
110 Y 10 Mem(10110) 110 Y 10 Mem(10110)
111 N 111 N
(4) Address referred 10010 (miss):
Index V Tag Data
000 N
001 N
010 Y 10 Mem(10010)
011 N
100 N
101 N
110 Y 10 Mem(10110)
111 N
Address division for DM cache with 1K one word blocks ?
Direct Mapped Cache
MIPS style:
A d dre ss ( s h o w ing b it p os itio ns )
31 30 1 3 12 11 2 1 0
Byte
offse t
20 10
H it D a ta
Tag
Ind e x
In de x V a lid T ag D a ta
0
1
2
1021
1022
1023
20 32
16 14 Byte
offset
H it D ata
16 bits 32 bits
Valid Tag D ata
16K
entries
16 32
memory write
performance is improved with a write buffer where
words are stored while waiting to be written to
memory – processor can continue execution until
write buffer is full
when a word in the write buffer completes writing
into main memory that buffer slot is freed and
becomes available for future writes
DEC 3100 write buffer has 4 words
Write-back scheme
write the data block only into the cache and write-back
implement
Direct Mapped Cache: Taking Advantage of Spatial
Locality
Taking advantage of spatial locality with larger blocks:
16 12 2 Byte
H it T ag D a ta
offset
Index Block offset
1 6 bits 12 8 bits
V T ag D ata
4K
entrie s
16 32 32 32 32
M ux
32
35%
30%
15%
10%
5%
0%
4 16 64 256
Block size (bytes) 1 KB
8 KB
16 KB
64 KB
256 KB
Example
How many total bits are required for a direct-mapped cache with
128 KB of data and 1-word block size, assuming a 32-bit
address?
Example
How many total bits are required for a direct-mapped cache with
128 KB of data and 1-word block size, assuming a 32-bit
address?
ABR DBR ABR DBR ABR DBR ABR DBR ABR DBR ABR DBR
Multiplexor
Cache Cache
Cache
Bus
12 mod 8 = 4 12 mod 4 = 0
1 1 1
Tag Tag Tag
2 2 2
4 1
5 2
6 3
2 (two-way set-associative)
Block address Cache set
0 0 (= 0 mod 2)
6 0 (= 6 mod 2)
8 0 (= 8 mod 2)
Block address translation in a two-way set-associative cache
3 misses
Implementation of a Set-Associative
Cache Ad dr es s
31 3 0 1 2 11 10 9 8 3 2 1 0
22 8
I nd ex V Ta g D ata V Ta g D a ta V T ag D at a V T ag D at a
0
1
2
Set
253
254
255
22 32
4 - to - 1 m ultip le x o r
Hit D a ta
12%
9%
Miss rate
6%
3%
0%
O n e -w a y T w o-w a y F ou r-w a y E ig h t- w a y
A sso c ia tiv ity 1 KB 16 KB
2 KB 32 KB
4 KB 64 KB
8 KB 1 28 KB
accessed
if data is found in second-level cache, miss penalty of
Virtual address
Data MMU
Physical address
Cache
Main memory
DMA transfer
Disk storage