Professional Documents
Culture Documents
Cosc 3P92
George Jessel
1
COSC 3P92
Memory Organization
• In a typical computer system, the storage system is organized according to
the following hierarchy:
Cache
Internal
2
COSC 3P92
Memory speed
3
COSC 3P92
Classes of Memory
• RAM (“normal memory”)
• Direct-access storage: HD, CD ROM, DVD
• Sequential access storage tapes: DAT
• Associative (content-addressable) memory:
searches for data via bit patterns
– CAM (Content Addressable Memory)
» Includes comparison logic with each bit of storage.
» A data value is broadcast to all words of storage and
compared with the values there.
» Words which match are flagged.
» Subsequent operations can then work on flagged words.
» (computing-dictionary.thefreedictionary.com)
• ROM
4
COSC 3P92
primary memory
RAM ROM
5
COSC 3P92
1K x 4 4
WE RAM chip D3-D0
CS
6
COSC 3P92
7
COSC 3P92
• Memory band-switching
log2 n 1-of-n
Processor Decoder n
1 2 Enable n
Enable 2
Addr bus Enable 1
Memory bank
8
COSC 3P92
9
COSC 3P92
Cache Memory
c
C external
CPU a Main
a
c c
h h memory storage
e e
• cache hit:
– requested memory resides in cache
10
COSC 3P92
Cache
• cache miss:
– requested memory not in cache, and must be fetched from main
memory and put into cache
• unified cache:
– instns, data share same cache
• split cache:
– separate instn, data caches
• parallel access:
– double the bandwidth
• level 2 cache:
– between instn/data cache and main memory
• Cache maintenance algorithms similar in spirit to
virtual memory ideas at operating system level; main
difference is that cache is hardware-supported,
whereas v.m. is software implemented
11
COSC 3P92
Measuring cache
performance
• c - cache access time
• m - main memory access time
• hr - hit ratio ( 0 <= hr <= 1) :
– # cache hits / total memory requests
• mr - miss ratio (1-hr)
• mean access time = c + (1-hr)m
12
COSC 3P92
Cache Example
• example:
let c = 160 ns
m = 960 ns
h = .90 (common)
efficiency = c / mean
= 160/256 = 62.5%
13
COSC 3P92
Direct mapping
Main memory
0
1
Cache
0
i mod N i
N-1
M-1
14
COSC 3P92
15
COSC 3P92
Direct mapping
• 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
16
COSC 3P92
Set associative mapping
Main memory
0
1
Cache
Set 0 S blocks per set
Set 1
Set N/S - 1
M-1
17
COSC 3P92
18
COSC 3P92
19
COSC 3P92
• 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
20
COSC 3P92
21
COSC 3P92
Example (cont)
22
COSC 3P92
The end
23