Wondering when a write-back should be performed? I thought it was when you’re writing to an address, that isn’t in the cache already. So if there is something in that slot, that has a valid Dirty Bit, then you’d want to copy that back to its place in main_mem, so you don’t lose the data.
But what about when you want to read a different address (this is a direct-mapped cache)?
So do you perform a write-back everytime there is a cache miss and a dirty bit (Regardless of read or write)?
You are right that when a cache line needs to be re-used for any reason, if its dirty it needs to be written out (possibly to a lower cache or main memory)