Write-Through vs Write-Back Policies
You'll learn: How caches decide whether to update main memory immediately when you write data, or wait until later.
When the CPU writes data to cache, the system faces a critical decision: should it also update main memory right away, or postpone that update? These are the two fundamental write policies.
Write-Through Policy
With write-through, every write to cache is immediately propagated to main memory. Think of it like a secretary who not only updates their desk notes but also files the paperwork in the main office cabinet right away.
Advantages:
- Main memory is always up-to-date and consistent with cache
- Simpler to implement
- Safer if power fails—no data is lost
Disadvantages:
- Slower, because every write must wait for the slower main memory
- Increases memory traffic and power consumption
Write-Back Policy
With write-back (also called write-deferred), writes only update the cache initially. The cache line is marked "dirty," and the updated data is written to main memory later—typically when that cache line needs to be replaced.
Advantages:
- Much faster—writes complete at cache speed
- Reduces memory traffic (multiple writes to the same location need only one memory update)
Disadvantages:
- More complex to implement (need dirty bits, eviction logic)
- Risk of data loss if power fails before write-back occurs
- Memory can temporarily be inconsistent with cache
Choosing Between Them
Write-through prioritizes simplicity and consistency; write-back prioritizes performance. Most modern processors use write-back for better speed, despite its complexity.
Key Takeaway: Write-through updates memory immediately on every cache write (simpler, safer, slower), while write-back delays memory updates until necessary (faster, more complex, but riskier).