7 Mem Cache
7 Mem Cache
Main memory
Cache
Internal
• primary memory
RAM
ROM
Bipolar MOS
magnetic semiconductor
core
10
A9-A0
1K x 4 4
WE RAM chip D3-D0
CS
• Memory band-switching
log2 n
1-of-n
Processor Decoder
n
1 2 Enable n
Enable 2
Memory bank
Data bus
4-bit
base Base
address
Processor
20 bit
Physical
address
to memory
16-bit Address bus
Offset
c c external
CPU a
Main
a
c
c memory storage
h
e h
e
let c = 160 ns
m = 960 ns
h = .90 (common)
efficiency = c / mean
= 160/256 = 62.5%
Main memory
1
Cache
i mod N i
N-1
M-1
• [4.38]
• use a hash function to find cache location
• normally, modulo some bit field of address, then just use
low end field
• cache fields:
– valid bit
– tag - block # being held
– value - data block
• scheme:
• memory request:
– compute cache slot (low n bits)
– check block (tag) field
• hit: return value
• miss: fetch block from memory, give to CPU,
and put into that computed slot (replace existing
item if there)
• can occasionally produce thrashing
– eg. addresses that are multiple of cache size (64K) will
reside at same entry
– split instn/data cache helps avoid thrashing
1
Cache
Set 0
S blocks per set
Set 1
i
Set i mod (N/S)
Set N/S - 1
M-1
4.30
• [4.39]
• use same hash function as direct mapping, except that each
cache slot holds multiple data blocks
– usually max. 4 blocks (“4-way”)
• searching blocks in a slot done associatively: simultaneous
pattern matching
• more flexible than direct: multiple blocks in set
• use smaller tag than associative, therefore cheaper to
implement associative matching
• commonly used in larger systems (VAX 11-780)
• which line should be replaced when slot full?
– eg. LRU (least recently used)
• write through:
– (ii) whenever modifying data, always write it back to
main memory
– have to do this if memory being shared in a DMA or
multiprocessing system
4 byte blocks
1 byte words
8 slots in cache