Writethrough Write is done synchronously both to the cache and to the backing store
Writeback (or Writebehind) – Writing is done only to the cache A modified cache block is written back to the store just before it is replaced
Writethrough(直寫模式)在數據更新時同時寫入緩存Cache和後端存儲此模式的優點是操作簡單;缺點是因為數據修改需要同時寫入存儲數據寫入速度較慢
Writeback(回寫模式)在數據更新時只寫入緩存Cache只在數據被替換出緩存時被修改的緩存數據才會被寫到後端存儲此模式的優點是數據寫入速度快因為不需要寫存儲;缺點是一旦更新後的數據未被寫入存儲時出現系統掉電的情況數據將無法找回
Writemisses寫缺失的處理方式
對於寫操作存在寫入緩存缺失數據的情況這時有兩種處理方式
Write allocate (aka Fetch on write) – Datum at the missedwrite location is loaded to cache followed by a writehit operation In this approach write misses are similar to readmisses
Nowrite allocate (aka Writenoallocate Write around) – Datum at the missedwrite location is not loaded to cache and is written directly to the backing store In this approach actually only system reads are being cached
Write allocate方式將寫入位置讀入緩存然後采用writehit(緩存命中寫入)操作寫缺失操作與讀缺失操作類似
Nowrite allocate方式並不將寫入位置讀入緩存而是直接將數據寫入存儲這種方式下只有讀操作會被緩存
無論是Writethrough還是Writeback都可以使用寫缺失的兩種方式之一只是通常Writeback采用Write allocate方式而Writethrough采用Nowrite allocate方式;因為多次寫入同一緩存時Write allocate配合Writeback可以提升性能;而對於Writethrough則沒有幫助
處理流程圖
Writethrough模式處理流程
A WriteThrough cache with NoWrite Allocation
Writeback模式處理流程
A WriteBack cache with Write Allocation
From:http://tw.wingwit.com/Article/Common/201311/7144.html