Professional Documents
Culture Documents
Chapter 4
Cache
Chapter 5
Internal Memory
4.1 Memory system overview
1. Characteristics
• Location
• Capacity
• Unit of transfer
• Access method
• Performance
• Physical type
• Physical characteristics
• Organisation
Location
• Word ‼
The natural unit of memory organisation
e.g. 8, 16, 32
• Size of word / Word length ‼
Number of bits used to represent a word
• Addressable unit ‼
Smallest location which can be uniquely addressed
Unit of Transfer ‼
• number of bits read/written at a time
• Internal
Usually governed by data bus width
word
• External
Usually a block which is much larger than a word
Cluster on disks
Access Methods‼ (1)
• Sequential
• Move from previous location to desired location
• Read through in order/ in sequence
• Access time depends on data location and
previous location
e.g. tape
• Direct
• Individual blocks have unique address
• Access is by jumping to vicinity plus sequential
search
• Access time depends on data location and
previous location
e.g. disk
Access Methods‼ (2)
• Random
• Individual addresses identify locations exactly
• Access time is independent of location or
previous access
e.g. RAM
• Associative
• Data retrieved based on a portion of its contents
rather than its address
• Access time is independent of location or
previous access
e.g. cache
Performance‼
• Access time (latency)
• Time between presenting the address and data
being stored(write) or available for use(read)
• Memory Cycle time
• Time may be required for the memory to
“recover” before next access
• Cycle time = access time+ recovery time
• Transfer Rate
• Rate at which data can be transferred into or
out of a memory unit
Physical Types
• Semiconductor
e.g. RAM
• Magnetic surface memory
e.g. Disk & Tape
• Optical
e.g. CD & DVD
Physical Characteristics
• Decay
• Volatility
• Erasable
Organisation
• Permanent storage
• Microprogramming
• Library subroutines
• Systems programs (BIOS)
• Function tables
Types of ROM
• Written during manufacturing
• Very expensive for small runs
• Programmable (once)
• PROM
• Needs special equipment to program
• Read “mostly”
• Erasable Programmable (EPROM)
• Erased by UV
• Electrically Erasable (EEPROM)
• Takes much longer to write than read
• Flash memory
• Erase whole memory electrically
4. Organisation in detail‼
256K words
Memory 1 bit each word
Address Chip #1
Register (MAR) Memory
Buffer
Register (MBR)
1
18 2
256K words 7
1 bit each word 8
Address Chip #7
Bus
Data
18
256K words 256K words 256K words
1 bit each word 1 bit each word 1 bit each word
Chip #1 Chip #2 Chip #8
Address
Bus
1 2 8 Data
256K*8 Bus
Module
A How to get 512K*8 with module A?
18 address 8 data
lines lines Combine two module A?
How to get 512K*8 with module A?
256K*8
Module
A
18 address 8 data
512K lines lines
? address
lines
x8 ? data
lines
= +
256K*8
Module
A
18 address 8 data
lines lines
00 000000000000000000
... ...
00 111111111111111111
01 000000000000000000
... ...
01 111111111111111111
... ...
11 000000000000000000
... ...
256K*8 256K*8 ... 256K*8 11 111111111111111111
*DRAM Organisation
Address Refresh
Bus Counter
MUX
Data Input
Column D0
A10 Buffer D1
Address Sense Amplifier
And I/O Gate Data Output D2
Buffer D3
Buffer
Column Decoder
5. Error Correction
• Hard Failure
• Permanent defect
• Soft Error
• Random, non-destructive
• No permanent damage to memory
• Detected using Hamming error correcting
code
Error Correcting Code Function
Error
Error Signal Not possible to Correct
No Error
Error
Data Out M Possible to Correct
Corrector
Data In M M K
f
K Memory Compare
f K
4.3 Hierarchy List
• Registers
• L1 Cache
• L2 Cache
• Main memory
• Disk cache
• Disk
• Optical
• Tape
Design constraints of memory
• How much? Capacity
• How fast? Time is money
• How expensive? Budget
----------------------- Dilemma ----------------------
• Faster access, higher cost per bit
• Larger capacity, smaller cost per bit
• Larger capacity, slower access
…
…
Cache
C-1 Main …
Memory
…
Block Length
(K words)
Block j
2n-1
Word Length
Cache Read Operation
Address
Address
System Bus
Buffer
Processor Control Control
Cache
Data
Data
Buffer
4.5 Cache Design
• Cache Size
• Mapping Function
• Replacement Algorithm
• Write Policy
• Line Size
• Number of Caches
1 Cache Size
• Cost
• More cache is expensive
• Speed
• More cache is faster (up to a point)
• Checking cache for data takes time
Example :
• Cache of 64kBytes
• Cache block of 4 bytes
• i.e. cache is 16k (214) lines of 4 bytes
4*214=16k
• 16MBytes main memory
• Addressable by a 24 bit address
224=16M
(1) Direct Mapping
n:
1
16 Kword cache
HEX BINARY
160000 0001 0110 0000 0000 0000 0000
160001 0001 0110 0000 0000 0000 0001
160002 0001 0110 0000 0000 0000 0010
160003 0001 0110 0000 0000 0000 0011
Cache
②
④
③
Direct Mapping pros & cons
• Simple
• Inexpensive
• Comparer
• Comparing times
• Fixed location for given block
If a program accesses 2 blocks that map to the
same line repeatedly, cache misses are very
high
(2) Associative Mapping
22bits 2bits
S W
Associative Mapping Example
Address Data HEX BINARY
000000 0000 0000 0000 0000 0000 0000
000000 13579249 000001 0000 0000 0000 0000 0000 0001
000004 000002 0000 0000 0000 0000 0000 0010
000003 0000 0000 0000 0000 0000 0011
0000 0000 0000 0000 0000 00
0A0000
Line
Tag Data Number
3FFFFF 11223344 0000
058001 11235813 0001
160004 11235813 …
3FFE
000000 13579246 3FFF
22 Bits 32Bits
FFFFF4
FFFFF8 11223344 16K word Cache
HEX BINARY
FFFFFC 160000 0001 0110 0000 0000 0000 0000
160001 0001 0110 0000 0000 0000 0001
32Bits 160002 0001 0110 0000 0000 0000 0010
160003 0001 0110 0000 0000 0000 0011
16Mbyte Main Memory 0001 0110 0000 0000 0000 00
Fully Associative Cache Organization
Cache
Memory Address Tag Data Main Memory
Tag Word W0
L0 W0
W1 B0
W2 W1
s w W3 W2
s W3
②
w W0 ③
s W1 Lj
①
W2 W(4j)
W3 Bj
W (4j+1)
W (4j+2)
Compare
W (4j+3)
W0
s W1 Lm-1
W2
Hit in Cache W3
Miss in Cache
(3) Set Associative Mapping
②
③
3 Replacement Algorithms
(1) Direct mapping
• No choice
• Each block only maps to one line
• Replace that line
Replacement Algorithms
(2)Associative & Set Associative
• Hardware implemented algorithm (speed)
• Least Recently used (LRU)
• e.g. in 2 way set associative
• Which of the 2 block is lru?
• First in first out (FIFO)
• replace block that has been in cache longest
• Least frequently used
• replace block which has had fewest hits
• Random
4 Write Policy