目录
HANDLING METHOD FOR WRITE-MISSES
This post brings you the topic of differences between disk Cache Write-through and Write-back. Please find more information as you read further down the post.
BACKGROUND INFORMATION
The cache mechanism includes write-through and write-back.
Write-through: Write is done synchronously - both to the cache and to the backing store.
Write-back (or Write-behind): Writing is done only to the cache. A modified cache block is written back to the store, just before it is replaced.
Write-through: When data is updated, it is written to both the cache and the back-end storage. This mode is easy to slow in data writing because data has to be written to both the cache and the storage.
Write-back: When data is updated, it is written only to the cache. The modified data is written to the back-end storage only when data is removed from the cache. This mode has fast data write data will be lost if a power failure occurs before the updated data is written to the storage.
HANDLING METHOD FOR WRITE-MISSES
CPU读Cache时
●若hit,则CPU直接从Cache中读取数据即可。
●若miss,有两种处理方式:
>Read through,即直接从内存中读取数据;
>Read allocate,先把数据读取到Cache中,再从Cache中读数据。
写操作
先检查cache里是否有对应数据,如果有(write hit):
根据是write-back还是write-through来具体操作:
write-back:将数据更新到cache,并不更新到内存(DRAM),待后续flush cache时存入内存;
write-through:数据同时会更新到cache和内存;
如果没有(write miss):
Two methods are available for handling write-misses.
根据是write-allocate或是write-no-allocate:
write-allocate:将要写入的位置从内存读到cache,然后按照上述write hit继续操作;
write-no-allocate:不会将要写入的数据从内存读到cache,直接将要写的数据写入内存。
Both Write-through and Write-back can use Write allocate or No-write allocate. Typically, Write-back uses Write allocate and Write-through No-write allocate, because Write allocate improves performance for Write-not for Write-through when data is written to one cache for multiple times.
FLOWCHARTS
Figure 1. Write-through flowchart: A Write-through cache with No-write allocate
Figure 2. Write-back flowchart: A Write-back cache with Write