硬盘Cache写机制 Write-through与Write-back的区别
程序员文章站
2022-06-27 09:58:54
硬盘Cache写机制 Write-through与Write-back的区别这篇文章主要介绍了Write-through与Write-back的区别,需要的朋友可以参考下... 13-08-23...
http://en.wikipedia.org/wiki/cache#writing_policies上的说明,cache写机制分为write through和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(直写模式)在数据更新时,同时写入缓存cache和后端存储。此模式的优点是操作简单;缺点是因为数据修改需要同时写入存储,数据写入速度较慢。
write-back(回写模式)在数据更新时只写入缓存cache。只在数据被替换出缓存时,被修改的缓存数据才会被写到后端存储。此模式的优点是数据写入速度快,因为不需要写存储;缺点是一旦更新后的数据未被写入存储时出现系统掉电的情况,数据将无法找回。
write-misses写缺失的处理方式
对于写操作,存在写入缓存缺失数据的情况,这时有两种处理方式:
write allocate (aka fetch on write) – datum at the missed-write location is loaded to cache, followed by a write-hit operation. in this approach, write misses are similar to read-misses.
no-write allocate (aka write-no-allocate, write around) – datum at the missed-write 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方式将写入位置读入缓存,然后采用write-hit(缓存命中写入)操作。写缺失操作与读缺失操作类似。
no-write allocate方式并不将写入位置读入缓存,而是直接将数据写入存储。这种方式下,只有读操作会被缓存。
无论是write-through还是write-back都可以使用写缺失的两种方式之一。只是通常write-back采用write allocate方式,而write-through采用no-write allocate方式;因为多次写入同一缓存时,write allocate配合write-back可以提升性能;而对于write-through则没有帮助。
处理流程图
write-through模式处理流程:
a write-through cache with no-write allocation
write-back模式处理流程:
a write-back cache with write allocation
来源:
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(直写模式)在数据更新时,同时写入缓存cache和后端存储。此模式的优点是操作简单;缺点是因为数据修改需要同时写入存储,数据写入速度较慢。
write-back(回写模式)在数据更新时只写入缓存cache。只在数据被替换出缓存时,被修改的缓存数据才会被写到后端存储。此模式的优点是数据写入速度快,因为不需要写存储;缺点是一旦更新后的数据未被写入存储时出现系统掉电的情况,数据将无法找回。
write-misses写缺失的处理方式
对于写操作,存在写入缓存缺失数据的情况,这时有两种处理方式:
write allocate (aka fetch on write) – datum at the missed-write location is loaded to cache, followed by a write-hit operation. in this approach, write misses are similar to read-misses.
no-write allocate (aka write-no-allocate, write around) – datum at the missed-write 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方式将写入位置读入缓存,然后采用write-hit(缓存命中写入)操作。写缺失操作与读缺失操作类似。
no-write allocate方式并不将写入位置读入缓存,而是直接将数据写入存储。这种方式下,只有读操作会被缓存。
无论是write-through还是write-back都可以使用写缺失的两种方式之一。只是通常write-back采用write allocate方式,而write-through采用no-write allocate方式;因为多次写入同一缓存时,write allocate配合write-back可以提升性能;而对于write-through则没有帮助。
处理流程图
write-through模式处理流程:
a write-through cache with no-write allocation
write-back模式处理流程:
a write-back cache with write allocation
来源: