Handling Writes


Suppose on a store instruction, we wrote the data into only the data cache; then, memory would have a different value from that in the cache. In such a case, the cache and memory are said to be inconsistent. There are generally two ways to solve the problem:
Write-Through
Writes always update both the cache and the next lower level of the memory hierarchy, ensuring that data is always consistent between the two. These writes will take a long time and could slow down the processor considerably. One solution is to use a write buffer, which is used to hold data being written back to main memory. This frees the cache to service read requests while the write is taking place.

Write-Back or Copy Back
Writes update values only to the block in the cache, then writing the modified block to the lower level of the hierarchy when the block is replaced. This scheme can improve performance because multiple writes to a cache block requires only one write to memory; however, it is more complex to implement than write-through.
When a write miss occurs, two major schemes are usually used:
Write Allocate
It allocates a block in the cache. The block is fetched from memory and then the appropriate portion of the block is overwritten. Typically, write-back caches use this scheme and hope subsequent writes will be captured in the cache.

No Write Allocate
It updates the portion of the block in memory but not put it in the cache. Write-through caches often use this scheme because writes must still go to lower level memory.