Cache

来源:互联网 发布:淘宝网红裤子店铺 编辑:程序博客网 时间:2024/05/17 04:27

wiki: http://en.wikipedia.org/wiki/Cache_(computing)


1、cache原理


不多解释。参考链接:http://www.doc88.com/p-549882154113.html


2、写策略

   

  • Write-through - Write is done synchronously both to the cache and to the backing store.
  • Write-back (or Write-behind) - Initially, writing is done only to the cache. The write to the backing store is postponed until the cache blocks containing the data are about to be modified/replaced by new content.

写回模式实现上更复杂,因为需要跟踪哪个地址被修改,并且标记为dirty以备将来写入到主存中。仅仅在这些地址的数据被交换出cache时才写入主存,这也被称为lazy write。因为这个原因,针对写回cache的read miss往往需要两份:一份用于将替换的数据写回主存,一份用于获取需要的数据。

也有其他策略触发数据的写回。client可能大量修改了cache中的数据,并显示的通知cache写回数据。

http://blog.chinaunix.net/uid-21091200-id-1830760.html

该文解释了三种策略:写透、写回、写一次。

Since on write operations, no actual data are needed back, there are two approaches for situations of 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-allocateWrite around) - Datum at the missed-write location is not loaded to cache, and is written directly to the backing store. In this approach, only system reads are being cached.
虽然写透和写回策略可以使用以上任一write miss策略,但实际他们是成对使用的:
  • 写回策略使用write allocate, 以便后续写或读改地址的内存,已提前做好cache。
  • 写透策略使用no-write allocate. 直接写到主存,无需cache,只有读的时候需要cache。

Entities other than the cache may change the data in the backing store, in which case the copy in the cache may become out-of-date or stale. Alternatively, when the client updates the data in the cache, copies of those data in other caches will become stale. Communication protocols between the cache managers which keep the data consistent are known as coherency protocols.


3、cache算法

tbd


4、cache一致性

tbd


5、cache染色

tbd