In: Computer Science
In the implementation of a cache replacement policies, some write policies are employed. Explain two of them. What is the relevance of a dirty block or bit in cache replacement policies?
The 2 cache replacement write policies are :
In write back cache, when the contents of the cache are updated after the CPU executes an instruction, the contents of the block are written back to main memory when the cache block is replaced by some other block. This can be illustrated by the following example :
Suppose instruction I1 is executed by CPU and it requires the cache block B1 which contains the value of a variable a as 5. This is also present in the main memory too. Every cache block has a dirty bit and when some new value is updated in a particular cache block, the corresponding value of the dirty bit changes from 0 to 1.
After the instruction is executed, let the value of a be changed from a = 5 to a = 10. In write back technique, the value is changed only on the cache and it will changed in main memory after sometime. Since an updation occurs, the value of dirty bit of cache block B1 will change from 0 to 1.
After executing some instructions, let the cache block B1 be present in the cache and the value of a is updated only in the cache and not in main memory as of now.
Then, after sometime, an instruction I12 is executed and a block B2 is needed which is currently not in cache.and it is mapped to the same location in cache as that of block B1. So, there is a conflict miss in the cache. Hence, the block B1 has to be replaced.
Now, when the main memory finds out that the value of dirty bit of block B1 is 1, it will update its value from a = 5 to a = 10 and so the main memory will also be updated.
So, this concludes that the updation in main memory takes place when the cache block with dirty bit 1 that is dirty block is replaced during the write back procedure.
Write through is the cache replacement technique which updates the main memory at the same time the cache is updated during execution. This can be illustrated using the following diagram :
So, this concludes that the updation in main memory takes place at the same time as that of the cache during write through procedure.