

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















WRITE data to address [x] n-m
[w] m
[d] b
Block Address A = [x] n-m
[w] m
n-m
m
b
READ from address [x] n-m
[w] m
[d] b
Cache Hit: Replace step 1 with Read word from the cache line and omit step 2
2
Block size in bytes: B = 2
b
Cache size in blocks: M = 2
m ( 2
b+m bytes)
Memory size in blocks = 2
n ( 2
b+n bytes)
Write Allocate and Write-Back Protocol : write data to address [x] n-m
[w] m
[d] b
Block Address A = [x] n-m
[w] m
Compute cache index w = A mod M
if Cache Hit
Write data into byte d of block cache[w].DATA
Set cache[w].D to TRUE
else /* Cache Miss */
Stall Processor
if cache block is dirty /* cache[w].D = TRUE */
Store cache[w].DATA into memory block at address [TAG][w]
Load memory block at address [x][w]
Update cache[w].TAG to x, cache[w].V = TRUE and cache[w].D to FALSE
Retry cache Access
3
Write Allocate and Write-Through Protocol : write data to address [x] n-m
[w] m
[d] b
Block Address A = [x] n-m
[w] m
A
B
C
S
T
U
W A
R S
R T
W B
W C
R U
w A
w B
w C
w A
w B
w C
R S
R T
R U
W B
W C
W A
5
W A
W B
W C
w A
w B
w C
w A
w B
w C
R S
R T
R U
W B
W C
W A
W A
R S
R S
W B
W C
R S
W B
W C
W A
R S
R S
R S
R S
R T
R U
w A
w B
w C
R S
R T
R U
FIFO Queue
W B
W C
R S
Promote Reads over Pending Writes
R S
R S
W A
R S
6
Write Hit: Update both cache and main memory (1W)
Write Miss: Read in block to cache. Update cache and main memory (1R + 1W)
Write Hit: Update cache only
Write Miss: Read in block to cache. Write evicted block if dirty. Update cache. (1R + 1W if dirty
block being replaced)
Write Hit: Update both cache and main memory (1W)
Write Miss: Update main memory only (1W)
Write Hit: Update cache only
Write Miss: Update main memory only (1W)
8
m
n
b
Main
Memory
Cache
Memory
n
m
9
Memory Cache
Blocks Blocks
Direct-Mapped Cache mapping
All cache blocks have different colors
Memory blocks in each page cycle through the
same colors in order
A memory block can be placed only in a cache
block of matching color
Fully Associative mapping
Memory Cache
Blocks Blocks
P a g e 0 P a g e 1
A memory block can be placed in any cache
block
1
Direct Mapped Cache:
Only one cache location to store any memory block
Single collision: cache forces eviction even if other cache blocks unused
Improve miss ratio by providing choice of locations for each memory block
Example: Cache size = M words
while (!done) {
for (i = M; i < limit; i = i+M)
a[i] += (a[i-M] + a[i+M]) / 2 ;
}
a[i] += (a[i-M] + a[i+M]) all map to same cache index: (i mod M)
Every memory access in every iteration could be a cache miss
Reduce Conflict Misses using set associative cache
Therefore memory words with addresses M apart
will map to the same cache block in a DM cache
11
Memory Cache
Blocks Blocks
Memory Cache
Blocks Blocks
Direct-Mapped Cache mapping
All cache blocks have different colors
Memory blocks in any page cycle through the
same colors in order
A memory block can be placed only in a cache
block of matching color
Cache blocks grouped in sets
Page size equals number of sets
All sets of the cache have different colors
All blocks within a set have the same color
Number of blocks in set defines “way” of the cache
A memory block can be placed only in set of matching color
Fully Associative mapping
Memory Cache
Blocks Blocks
2-way Set Associative mapping
13
K-way Set Associative Cache:
Cache size: M = 2
m blocks
Cache divided into sets of size K = 2
k blocks each (K-way set associative)
Cache consists of S = 2
s = 2
m-k sets
Page Size = S blocks
A block in a page is mapped to exactly one set
Memory block with address A mapped to the unique set: (A mod S)
Memory block may be stored in any cache block in the set
With each cache block store a tag of (n - s) MSBs of memory address A
Example:
Cache size: M = 32 blocks,
Cache “way”: K = 4
Number of sets: S = M/K = 8
Consider address trace 0, 32, 64, 96, 128, …….
In Direct mapped cache (K=1) all blocks mapped to cache block 0
In this example (K=4) all blocks mapped to set 0; but 4 cache blocks available in each set
14
0
1
2
3
Cache
0 1 2 3 4 5 6 7 8 9
10
11
12
13
14
15
Memory
x w
Memory Address
Set Index
n-s s b
n = 4, m = 3, k = 1, s = 2
Byte
Offset
16
n-s
n - s
V (Valid) bit: Indicates that the cache entry contains valid data
TAG : identifies which of the 2
n-s memory blocks stored in cache block
DATA : Copy of the memory block stored in this cache block
17
bbbb
0 1 2 3 4 5 6 7 8 9
10
11
12
13
14
15
aaaa
qqqq
tttt
yyyy
ssss
xxxx
pppp
Memory
n = 4, m = 3, k=1, s=
qqqq
bbbb
ssss
yyyy
0
1
2
3
Cache
tttt
11 pppp
aaaa
xxxx
Set 3 : No tag match with 11
Set 3 : Tag match with 01
19
n-s
s
20