Chapter 5: Q13E (page 492)
In this exercise, we will examine how replacement policies impact miss rate. Assume a 2-way set associative cache with 4 blocks. To solve the problems in this exercise, you may find it helpful to draw a table like the one below, as demonstrated for the address sequence “0, 1, 2, 3, 4”.
Address of Memory Block Accessed | Hit or Miss | Evicted Block | Contents of Cache Blocks After Reference | |||
Set 0 | Set 0 | Set 1 | Set 1 | |||
0 | Miss | Mem[0] | ||||
1 | Miss | Mem[0] | Mem[1] | |||
2 | Miss | Mem[0] | Mem[2] | Mem[1] | ||
3 | Miss | Mem[0] | Mem[2] | Mem[1] | Mem[3] | |
4 | Miss | 0 | Mem[4] | Mem[2] | Mem[1] | Mem[3] |
… |
Consider the following address sequence: 0, 2, 4, 8, 10, 12, 14, 16, 0
(5.13.1) Assuming an LRU replacement policy, how many hits does this address sequence exhibit?
(5.13.2) Assuming an MRU (most recently used) replacement policy, how many hits does this address sequence exhibit?
(5.13.3) Simulate a random replacement policy by flipping a coin. For example, “heads” means to evict the first block in a set, and “tails” means to evict the second block in a set. How many hits does this address sequence exhibit?
(5.13.4) Which address should be evicted at each replacement to maximize the number of hits? How many does this address sequence exhibit if you follow this “optimal” policy?
(5.13.5) Describe why it is difficult to implement a cache replacement policy that is optimal for all address sequences.
(5.13.6) Assume you could make a decision upon each memory reference whether or not you want the requested address to be cached. What impact could this have on the miss rate?
Short Answer
(5.13.1)
With LRU replacement, there is 0 hit with the address sequence 0, 2, 4, 8, 10, 12, 14, 16, 0.
(5.13.2)
With MRU replacement, there is 1 hit with the address sequence 0, 2, 4, 8, 10, 12, 14, 16, 0.
(5.13.3)
With random replacement policy, there is 0 or 1 hit with the address sequence 0, 2, 4, 8, 10, 12, 14, 16, 0.
(5.13.4)
Any replacement policy is optimal if it gives 1 hit.
(5.13.5)
It is difficult to implement a cache replacement policy that is optimal for all address sequences because the cache doesn’t know the future address sequences.
(5.13.6)
The miss rate could decrease if an address with less temporal locality is replaced. Otherwise, the miss rate could increase too.