cache 相关知识 read/write through/back/allocate
来源:互联网 发布:浏览器收集用户数据 编辑:程序博客网 时间:2024/05/01 13:42
所謂的read/write cache的hit/miss,指的是CPU要read/write某一位址的資料,若此時cache裡的資料剛好是該位址的資料,則稱為cache hit,若此時cache裡的資料不是該位址的資料,則稱為cache miss。
A. [Read]
---------------------------------------------
.當cache hit時,若CPU要讀取某一位址的資料時,會直接從cache中讀取資料。
.當cache miss時,若CPU要讀取某一位址的資料時,又可分為二種方式:一種是read through,這種方式會直接將資料從主記憶體端讀進CPU;另一種是no read through,這種方式會先將資料從主記憶體端讀進cache,然後再從cache讀進CPU。
---------------------------------------------
B. [Write]
---------------------------------------------
.當cache hit時,若CPU要寫入資料到某一位址時,可分為二種方式:一種是write through,此種方式資料會立刻寫到cache及主記憶體中;另一種是write back,此種方式會先將資料寫入cache中,然後再將同一位址的資料整批一起寫入主記憶體中(非立即寫入)。
.當cache miss時,若CPU要寫入資料到某一位址時,可分為二種方式:一種是no write allocate,此種方式會直接將資料寫到主記憶體中,不會再從記憶體中載入到cache,另一種方式是write allocate,此種方式會先將資料從主記憶體中載入到cache,然後再依cache hit的規則,將資料寫出。
---------------------------------------------
转自http://witmax.cn/cache-writing-policies.html
Cache写机制
参考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模式处理流程:
Write-back模式处理流程:- cache 相关知识 read/write through/back/allocate
- 有關 Cache 的 read/write through/back/allocate
- Read/Write through/back/allocate区别
- [有關 Cache 的 read/write through/back/allocate 的意義]
- 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
- 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
- Cache 的write back和write through
- Cache 的write back和write through
- 段限检查
- MFC模态对话框和非模态对话框
- C与C++的区别
- netty 执行流程的例子
- View工作原理(一)事件传递原理详解
- cache 相关知识 read/write through/back/allocate
- 老罗 Android系统的智能指针(轻量级指针、强指针和弱指针)的实现原理分析
- 《史仙》入围凤凰网首届原创文学大赛
- 成为Java GC专家IV— Apache的MaxClients参数详解及其在Tomcat执行FullGC时的影响
- IOS网络编程常用的代码
- oracle10g上机练习题型总结
- opencv学习(1)
- 引导装载程序做什么
- 《第五项修炼》读书笔记