Cache Memory Mapping Techniques
Cache Memory Mapping Techniques
Consider a memory of 64K words divided into 4096 blocks Where blocks 0, 128, 256, 3968 should be mapped to?
Word
Tag
Block
a. Check if cache has tag 10101 for block 1 match -> hit; different -> miss, load the corresponding block b. Access word 5 of the block
Disadvantage
not flexible there is contention problem even when cache is not full For example, block 0 and block 128 both take only block 0 of cache: 0 modulo 128 = 0 128 modulo 128 = 0 If both blocks 0 and 128 of the main memory are used a lot, it will be very slow
Main Memory
Block 0 Block 1
Tag
Word
tag
Block 4095
Tag
Set
Word
tag
Set 63
tag
The blocks in cache are divided into 64 sets and there are two blocks in each set How the blocks in the main memory be mapped into cache? Main memory blocks 0, 64, 128, 4032 maps to set 0 and can occupy either of the two positions
Set 0
Always work with 1 block at a time How many blocks in cache? No of words in cache divided by number of words 11 4 per block e.g. 2 k words, 16-word block: 2 / 2 = 2 7 = 128 blocks
Examples
Small Instruction Cache (read 8.6.3)
Cache has 8 blocks, 1 word each Main memory has 256 blocks (words) 8 bit address Execute the following program Cache Use direct mapping first
C0 C1 branch D0 D1 D2 branch E0
Loop 5 times
Tag 0
Tag 1
Loop 10 times
Tag 31
Tag
Block
Block 255
Misses Hits
2x5
2x5 18 x 5
2 + 1x4 = 26 1x4 = 94
8
Cache Block 0 1 2 3 4 5 6 7 Misses Hits After C1 C0 C1 After Inner Loop C0 C1 D0 D1
After E0 C0 C1 D0 D1 D2 E0
= 6
After E0 E0 D0 C1 D1 D2
E0 C0 C1 D1 D2
D0 C0 C1 D1 D2
2 + 1x4 = 18