CH04 COA10e Updated
CH04 COA10e Updated
William Stallings
Computer Organization
and Architecture
10th Edition
Capacity
Memory is typically expressed in terms of bytes
Unit of transfer
For internal memory the unit of transfer is equal to the number of
electrical lines into and out of the memory module
Each addressable
A word is retrieved
Memory is organized location in memory has
Involves a shared read- based on a portion of
into units of data a unique, physically
write mechanism its contents rather
called records wired-in addressing
than its address
mechanism
0000
0001
0010
0011
Cache (32 byte)
0100
00
..
Block (8 byte)
01
..
10
..
11
..
..
..
..
..
..
1111
0000
0001
To overcome the
0010
disadvantage of
direct mapping, Cache (32 byte)
0011
Associative mapping 00
0100
arise 01
..
..
10
..
11
1000
..
..
1100
..
..
1111
0000
0001
Memory block can be
0010
placed in ANY cache
line Cache (32 byte)
0011
0100
00
..
01
..
10
..
11
1000
..
..
1100
..
..
1111
0000
0001
Tag bits holds the whole
0010
block index bits
0011
Tag bits size = Block Tag bits Cache (32 byte)
0100
Index 00
..
0100 01
..
10
..
11
1000
..
..
1100
..
..
1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
BK 2 00
BK 6 ..
BK 4 01
BK 7 ..
BK 5 10
BK 8 ..
BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
0001 BK 2 00
BK 6 ..
BK 4 01
BK 7 ..
BK 5 10
BK 8 ..
BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
0001 BK 2 00
BK 6 ..
0011 BK 4 01
BK 7 ..
BK 5 10
BK 8 ..
BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
0001 BK 2 00
BK 6 ..
0011 BK 4 01
BK 7 ..
0100 BK 5 10
BK 8 ..
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
CPU Tag bits Cache (32 byte)
Requests: BK 5 0100
0001 BK 2 00
BK 6 ..
0100010 0011 BK 4 01
BK 7 ..
7 bits physical 0100 BK 5 10
BK 8 ..
Address (Why?) 1111 BK 15 11
BK 9 1000
What is W size?? BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
CPU Tag bits Cache (32 byte)
Requests: BK 5 0100
0001 BK 2 00
BK 6 ..
0100010 0011 BK 4 01
BK 7 ..
0100 BK 5 10
BK 8 ..
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 0 0 1 0
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
0001 BK 2 00
BK 6 ..
0011 BK 4 01
BK 7 ..
0100 BK 5 10
BK 8 ..
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 0 0 1 0
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
X 0001 BK 2 00
BK 6 ..
Comparator 0011 BK 4 01
BK 7 ..
Comparator
0100 BK 5 10
BK 8 ..
Comparator
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 0 0 1 0
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
X 0001 BK 2 00
BK 6 ..
Comparator 0011 BK 4 01
X
BK 7 ..
Comparator
0100 BK 5 10
BK 8 ..
Comparator
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 0 0 1 0
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
X 0001 BK 2 00
BK 6 ..
Comparator 0011 BK 4 01
X
BK 7 ..
Comparator Hit 0100 BK 5 10
BK 8 ..
Comparator
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 0 0 1 0
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
0001 BK 2 00
BK 6 ..
Comparator 0011 BK 4 01
BK 7 ..
Comparator
0100 BK 5 10
BK 8 ..
Comparator
1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
1 1 0 0 0 1 1
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
X 0001 BK 2 00
BK 6 ..
Comparator X 0011 BK 4 01
BK 7 ..
Comparator X 0100 BK 5 10
BK 8 ..
Comparator X 1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
1 1 0 0 0 1 1
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
Comparator
X 0001 BK 2 00
BK 6 ..
Comparator X 0011 BK 4 01
BK 7 ..
Comparator X 0100 full BK 5 10
BK 8 ..
Comparator X 1111 BK 15 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
1 1 0 0 0 1 1
BK 13 ..
Tag W 3bits
BK 14 ..
BK 15 1111
0000
0001
To overcome the
0010
Comparators overhead, we
group the cache lines into k- Cache (32 byte)
0011
way in set-Associative 00
0100
mapping 01
..
..
10
..
k is simply the number of 11
1000
lines in a set ..
..
1100
..
..
1111
0000
0001
Example: 2-way sets
0010
0011
Cache (32 byte)
0100
00
Main memory blocks assigns Set 0
..
01
into cache sets using Direct ..
10
Mapping Set 1 ..
11
Inside the set, Associative 1000
..
Thus, set-Associative Mapping is a
1100
combination of both
..
How many number of comparators?? ..
1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
To find the number of sets: 00
0 BK 6 ..
01
no. set = no. Lines / k 10
BK 7 ..
=4/2 1
11
BK 8 ..
= 2 sets BK 9 1000
BK 10 ..
= 21 BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
BK 3 00
0 BK 6 ..
BK 5 01
BK 7 ..
BK 4 10
1 BK 8 ..
BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
001 BK 3 00
0 BK 6 ..
BK 5 01
BK 7 ..
BK 4 10
1 BK 8 ..
BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
001 BK 3 00
0 BK 6 ..
010 BK 5 01
BK 7 ..
BK 4 10
1 BK 8 ..
BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
Tag bits Cache (32 byte)
BK 5 0100
001 BK 3 00
0 BK 6 ..
010 BK 5 01
BK 7 ..
001 BK 4 10
1 BK 8 ..
000 BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
BK 12 1100
BK 13 ..
BK 14 ..
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
CPU Tag bits Cache (32 byte)
Requests: BK 5 0100
001 BK 3 00
0 BK 6 ..
0001010 010 BK 5 01
BK 7 ..
001 BK 4 10
1 BK 8 ..
000 BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 1 0 0 0
BK 13 ..
Ta S W BK 14 ..
g I
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
CPU Tag bits Cache (32 byte)
Requests: BK 5 0100
001 BK 3 00
0 BK 6 ..
0001010 010 BK 5 01
BK 7 ..
Comparator
001 BK 4 10
1 BK 8 ..
Comparator 000 BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 1 0 0 0
BK 13 ..
Ta S W BK 14 ..
g I
BK 15 1111
BK 1 0000
Example BK 2 0001
2-way set associative cache
BK 3 0010
BK 4 0011
CPU Tag bits Cache (32 byte)
Requests: BK 5 0100
001 BK 3 00
0 BK 6 ..
0001010 010 BK 5 01
BK 7 ..
Comparator X 001 BK 4 10
1 BK 8 ..
Comparator Hit 000 BK 2 11
BK 9 1000
BK 10 ..
BK 11 ..
Physical address
BK 12 1100
0 1 0 1 0 0 0
BK 13 ..
Ta S W BK 14 ..
g I
BK 15 1111
First-in-first-out (FIFO)
Replace that block in the set that has been in the cache longest
Easily implemented as a round-robin or circular buffer technique
Write back
Minimizes memory writes
Updates are made only in the cache
Portions of main memory are invalid and hence accesses by I/O
modules can be allowed only through the cache
This makes for complex circuitry and a potential bottleneck
Two-level cache:
Internal cache designated as level 1 (L1)
External cache designated as level 2 (L2)
Cache Replacement
memory
principles algorithms
Write policy
Line size
Number of caches