3

I'm wondering about MESI protocol implementation of writing with the allocation on write miss policy. Let's say that we have write request and got cache miss with no other copies of cache line. This diagram says that the next step is to fetch value from main memory (or L2 cache), store it and mark cache line as M (modified). I suppose then the new value is stored in cache block. The question is: Why we need the step of fetching data from main memory? Why we can't simply write the new value in to the first found cache line in I (invalid) state/replace the eldest cache line and mark it as M (modified)?

Thank you for your help!

Alex
  • 43
  • 4

1 Answers1

4

Assume you have 64-byte cache lines, and you write one byte. You can't put "1/64ths of a cache line" into the cache, so where do the remaining 63 bytes come from? They have to come from main memory (or the next level cache).

Brendan
  • 35,656
  • 2
  • 39
  • 66
  • ok, i've understood. Thank you. One more question. The same situation, but other (not local) caches have copy of requested cache line. For example in case of M (modified) cache line copy the steps are: write back to main memory, invalidate, fetch data from main memory to local cache line, update local cache line. What is the point of writing to the main memory and then reading to the local cache? Why not to put copy of cache line on bus and save it in local cache. The same algorithm used in read miss with existing copy. – Alex Aug 27 '16 at 16:48
  • 1
    Actually, one can provide 64 validity bits for a 64-byte cache line and only require a read of memory on writeback if the entire line was not overwritten while in cache. (Such is a significant overhead.) One factor is the assumption of spatial locality, that items near the store will be read in the near future. –  Aug 28 '16 at 01:03