Cache - Memory Mapping
Cache - Memory Mapping
• Mapping process
– Use tag to see if a desired word is in cache
– It there is no match, the block containing the required word
must first be read from the memory
– For example: MOVE $A815, DO
10101 0000001 0101
Tag Block # Word
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
Direct Mapping Technique (Continued)
• Advantage
– simplest replacement algorithm
• 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
Associative Mapping Technique – No. 2
• Any block can go anywhere in cache
12
• 4095 blocks -> 4095 tag = 2 -> 12 bit tag
Cache Main Memory
tag Block 0 tag Block 0
tag Block 1 tag Block 1
6 6 4
Cache
Set 0 tag Block 0 • The blocks in cache are divided
tag Block 1
into 64 sets and there are two blocks
tag Block 2
Set 1 in each set
tag Block 3
• How the blocks in the main memory
be mapped into cache?
• Main memory blocks 0, 64, 128,
tag Block 126 4032 maps to set 0 and can occupy
Set 63 Block 127 either of the two positions
tag
Set Associative Mapping Technique
(continued)
• A set could have one block -> direct mapping; 128 blocks ->
associative mapping
• k blocks per set is referred to as k-way set-associative mapping
Main memory Block 0
Tag 0
Block 63
Block 64
Tag 1 Set 0
Block 127
Block 4032
Tag 63
Block 4095
Cache Memory Details
• Block size
– Depends on how memory is addressed (byte, word, or
long word) and accessed (word at a time)
– 8-16 quite reasonable
• 68040 – 16 bytes per block
• Pentium IV – 64 bytes per block
– 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