Cache写机制:Write-through与Write-back
来源:互联网 发布:百度域名后面有尾巴 编辑:程序博客网 时间:2024/06/06 11:00
无论是Write-through还是Write-back都可以使用写缺失的两种方式之一。只是通常Write-back采用Write allocate方式,而Write-through采用No-write allocate方式;因为多次写入同一缓存时,Write allocate配合Write-back可以提升性能
1.CPU读Cache时:
●若hit,则CPU直接从Cache中读取数据即可。
●若miss,有两种处理方式:
>Read through,即直接从内存中读取数据;
>Read allocate,先把数据读取到Cache中,再从Cache中读数据。
2.CPU写Cache时:
●若hit,有两种处理方式:
>Write through:把数据同时写到Cache和内存中;
>Write back:先把数据写到Cache中,再通过flush方式写入到内存中。
●若miss,有两种处理方式:
>Write allocate:先把要写的数据载入到Cache中,写Cache,然后再通过flush方式写入到内存中;
>No write allocate:直接把要写的数据写入到内存中。
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 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.
Cache写机制
参考http://en.wikipedia.org/wiki/Cache#Writing_Policies上的说明,Cache写机制分为write through和write back两种。
Write-through(直写模式)在数据更新时,同时写入缓存Cache和后端存储。此模式的优点是操作简单;缺点是因为数据修改需要同时写入存储,数据写入速度较慢。
Write-back(回写模式)在数据更新时只写入缓存Cache。只在数据被替换出缓存时,被修改的缓存数据才会被写到后端存储。此模式的优点是数据写入速度快,因为不需要写存储;缺点是一旦更新后的数据未被写入存储时出现系统掉电的情况,数据将无法找回。
Write-misses写缺失的处理方式
对于写操作,存在写入缓存缺失数据的情况,这时有两种处理方式:
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模式处理流程:
Write-back模式处理流程:
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写机制:Write-through与Write-back
- Cache写策略 — write-through与 write-back
- Cache写策略——write-through与write-back
- Cache之write back与write through
- Cache 的write back和write through
- Cache 中 Write through/Write back 区别
- Cache 的write back和write through
- Cache 的write back和write through
- Cache 的write back和write-through
- Cache 的write back和write through
- Cache 的write back和write through
- 存储;数组
- SpringMVC利用AOP实现自定义注解记录日志
- CentOS 7(Linux) 编译安装 pcntl扩展
- 自定义SPI的注册
- 第四周项目一 建立单链表
- Cache写机制:Write-through与Write-back
- 对监督学习和无监督学习很好的解释,通俗易懂
- 回归任务偏差与方差
- 高二&高一&初三模拟赛18 总结
- instanceof 与 getClass()的区别
- 求任意整数n的阶乘
- 简单描述为什么编译Android C程序所用的交叉编译工具链是arm-linux-androideabi-xx不是GNU开发的工具链arm-linux-gnueabi-xx?
- ORACLE PACKAGE 包详解
- 网络通信socket连接数上限