Professional Documents
Culture Documents
Cache Main
Memory
RA= Read
Address Read Miss
Read Hit
Block 255
Cache=2k
128 block
Tag = 31
There is 4096/128 = 32 different blocks in MM
could reside in the same block location in Cache
Block 4095
Direct Mapping
In Direct Mapping, each block in the memory could reside in
only one block location in Cache.
Tag = 4096/128 = 32
Memory Address 5 7 4
Format
Direct Mapping
Tag Block Word
Memory Address 5 7 4
Memory Address 7 7 3
Memory Address 12 4
Format
More flexible
But Cost to search 128 tag is high.
Replacement Algorithm:
When all positions are full, Cache controllers decide which
block to remove.
Replace Least Recently Used (LRU) block.
Set - Associative Mapping
Cache blocks are grouped into sets. (For example a set could
contain 2 blocks - it is called 2-way set associative).
Tag
Block 0
Set 0 Block 1
Block 255
Block 256
MM= 64k
Block 126
Set 63 4096 block
Block 127
Tag
Cache=2k
128 block
Memory Address 6 6 4
Format
Set - Associative Mapping
How Cache determine whether it has referenced data or not.
-First, 6 bits set determine which set in Cache.
Then, 6 bits tag is compared to all tags in the set to decide if the required
word is in Cache or not.
Replacement Algorithm:
When all positions in set are full, Cache controllers decide
which block to remove from the set.
Replace Least Recently Used (LRU) block.
Set - Associative Mapping
Replacement Algorithm
- Use Least Recently Used (LRU) block to be replaced.
- Assume set associative mapping with each set contains 4
blocks.
- To track the accessing of each block, we need two bit counter
associated with each block.
LRU Algorithm
- To track the accessing of each block, we need two bit counter
associated with each block.
- When a hit occurs:
- Set counter of block to 0
- Increment lower counters by 1
- All others remain the same
- When a miss occurs:
- (Cache is not full)
- Set new counter block to 0
- (Cache is full)
- Remove block with counter=3
- direct mapping
- associative mapping
- set-associative mapping with 2 blocks per set
Example:
Assume
A cache with 128 blocks of data,
A main memory with 256 blocks of data,
Each block consists of 8 words. Show the format of the main memory
address if the cache uses
Tag Block Word
- direct mapping
1 7 3
Tag Word
- associative mapping
8 3
2 6 3
Other Replacement Algortihms