Cache 的write back和write through 收藏
为了保证cache和memory的数据一致性,通常有三种方法:
1〉write through:CPU向cache写入数据时,同时向memory也写一份,使cache和memory的数据保持一致。优点是简单,缺点是每次都要访问memory,速度比较慢。
2〉post write:CPU更新cache数据时,把更新的数据写入到一个更新缓冲器,在合适的时候才对memory进行更新。这样可以提高cache访问速度,但是,在数据连续被更新两次以上的时候,缓冲区将不够使用,被迫同时更新memory。
3〉write back:CPU更新cache时,只是把更新的cache区标记一下,并不同步更新memory。只是在cache区要被新进入的数据取代时,才更新memory。这样做的原因是考虑到很多时候cache存入的是中间结果,没有必要同步更新memory。优点是CPU执行的效率提高,缺点是实现起来技术比较复杂。
回写与透写
对于cache的算法。大方面有两种,Write-Through(通写)和Write-Back(回写). Write-Through,也就是说OS发送的处理data的请求,一直要等到全部memory里面的data正确写到稳定存储media(如硬盘)中,然后返回给OS报告处理完毕,然后OS才会去update其状态;这种情况下,通常不会有dirty cache. 而Write-Back,就是在OS发送处理data的请求后,该算法会将它用buffer存起来,并在没有正确写到稳定存储media(如硬盘)中前,就告诉OS处理完毕,然后OS就会去update;但是要是此时掉电或其他故障,buffer的数据没有被写入稳定存储media(如硬盘),那么os update的信息就和media中的信息不一致.为了避免这样,所以才用NVRAM,它在调电后数据仍然不丢失,但是在被重新上电后,其数据会是dirty的,也就是楼主所提到的dirty cache(如何将dirty cache更新到media,这是Write-Back应该做的事)。 这和买卖东西相似,Write-Through就相当于你亲自去买东西,你买到什么就可以亲手拿到;而Write-Back就和中介差不多,你给了中介钱,然后它告诉你说你的东西买到了,然后就相信拿到这个东西了,但是要是出现特殊情况中介跑了(掉链子了),你再去检查,东西原来没有真正到手。
1.Cache的两个类型
--Write Through
当写数据进Cache时,也同时更新了相应的Memory里的内容
--Write back
只是写到Cache里,Memory的内容要等到cache保存的要被别的数据替换或者系统做cache flush时,才会被更新。
2.Cache的两个函数
--Flush
把Cache内容写回Memory,当Cache为Write through,不需要Flush
--Invalidate
把Cache内容直接丢掉不要。
3.Cache的使用场合
当有DMA在使用memory的时候,一般要用到cache的处理。因为DMA在访问memory时是不经过cache的。比较典型的比如在Ethernet,wireless,USB等driver里,DMA会操作descriptors和packet buffers,Driver要做这些处理
--如果driver使用descripter和packet buffer的地址都是cache的地址,那么
a).Driver在读descripter里一些状态比如Owned by CPU/DMA,有没有收到包时,要对descripter当前结构里的内容做cache invalidate,收到packet后,也要对packet buffer做cache invalidate
b).Driver在写descripter里一些状态比如Owned by DMA,要发送包时,要对descripter当前结构里的内容做cache flush,发送packet时,也要对packet buffer做cache flush
--有些driver会对descripter使用uncache 地址,那么上面两种情况里invalidate/flush就不用做了。一般很少会对packet buffer也用uncache地址的,因为对packet内容的处理将会很频繁,使用uncache会很慢。而descripter一般由于结构比较小,如果也使用cache地址的话,做invalidate/flush的时间消耗可能会比uncache的还要多。
分享到:
相关推荐
本文主要讲述cache中write back和write through名词解释
硬盘Cache写机制 Write-through与Write-back的区别.docx
阵列Cache写机制:Write-through与Write-back区别.docx
cache memory, cache line, write through and write back. Average memory access time = Hit time + Miss rate x Miss penalty
write through:系统的写入请求直接写入硬盘, 安全性很高,性能很低 write back:系统的写入请求先存放到缓存 ,再根据时机统一回写到硬盘中,由于缓存的 写速度远远高于磁盘,所以这种方式性能可以 大大提高,但是...
" "Write "虚拟磁盘的数据写策略,分以下三种: " "Policy "Write " " "Back:当控制器Cache收到所有的传输数据后,将给主机返回" " "数据传输完成信号。 " " "Write " " "Through:当磁盘子系统接受到所有传输数据...
The Windows 2000 cache manager provides data caching for both local and network file system drivers. By caching virtual blocks, the cache manager can reduce disk I/O and provide intelligent read ahead...
Register Write-Back....................................................................................................18 The Control Unit ................................................................
Paul Wilton is a successful Wrox "Beginning" book author and is an ideal author to write for those who want a firm grasp of standard SQL before learning the details specific to a particular database ...
Seize the power of the application stack through Angular 2, Bootstrap, and PostgreSQL. When used together, these powerful and easy-to-use tools will open you to a new world of possibilities. This ...
[3111577] No "back" option in log settings [3108422] Timing window in NE2K emulation [3084390] Bochs won't load floppy plugin right on startup [3043174] Docbook use of '_' build failure [3085140]...
14. If the two ISPs do not peer with each other, then when they send traffic to each other they have to send the traffic through a provider ISP (intermediary), to which they have to pay for carrying ...
* This version is a back to fondamentals. Somes features are removed ! * This version need testing ! * Remove old marker <!--st_tag_cloud--> * Remove related posts * Remove related tags * ...
- Updated Level 2 and Level 3 CPU cache information for newer Intel CPU's. - Updated the detection of Hyperthreading and the number of logical CPUs for a new Intel CPU. Release 5.3 build 1025 WIN32...
included complex flex-property by name registered through TCustomProp.InitPublished. - ADD: Added the property TCustomProp.PropData[PropName]: Variant, which uses the methods GetPropValue/Set...
command back in your CONFIG.SYS file. 2.3 Bernoulli Drive ------------------- If Setup refers you to this section, contact Iomega at (801) 778-3000 before you install MS-DOS 5.0 to get information ...
private static final boolean USE_CACHE = false; private static final int DEFAULT_OFFSCREEN_PAGES = 1; private static final int MAX_SETTLE_DURATION = 600; // ms private static final int PAGER_NEXT...
笔记本的风扇控制 ---------------------------------------- 09 November 2006. Summary of changes for version 20061109: 1) ACPI CA Core Subsystem: Optimized the Load ASL operator in the case where the...