缓存读写 [英] cache reads and writes

查看:91
本文介绍了缓存读写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关高速缓存写入策略的信息,我只想知道我是否正确理解了这一点.

当读取导致高速缓存未命中时,它将获取该内存块并将其放入高速缓存中.那么,缓存写未命中将意味着程序要写入的内存中的位置不在缓存中,对吗?因此,我正在阅读回写的描述,根据维基百科,该描述如下:

最初,仅写入高速缓存.推迟到后备存储的写入,直到包含数据的缓存块将被新内容修改/替换为止.

那么唯一可以替换缓存块内存的时间是在读取期间,对吗?而且写操作只会更改特定位置的内存中的数据(如果命中,它将在高速缓存块内),但是它将使块内的实际内存位置保持不变,对吗?

这是我对它的理解,我只想确保它是正确的.

等等,我想在缓存丢失期间,它也会替换/更新缓存块....

解决方案

维基百科对此进行了很好的解释.一方面,回写直写定义了何时将数据写入后备存储(也称为主存储器):

  • 直写–同步写入缓存和后备存储.
  • 回写(或后写)–最初,仅对高速缓存进行写操作.推迟到后备存储的写入,直到包含数据的缓存块即将被新内容修改/替换为止.

另一方面,写分配不写分配定义了如何处理写未命中,即是否将来自后备存储的数据带入缓存:

  • 写入分配(也称为写入时获取)–丢失写入位置处的数据将被加载到缓存中,然后执行写入命中操作.在这种方法中,写未命中类似于读未命中.
  • 无写分配(也称为无写分配或写回)–丢失写位置处的数据不会加载到缓存中,而是直接写到后备存储中.通过这种方法,仅系统读取将被缓存.

I'm reading about cache write policies, and I just want to know if I'm understanding this correctly.

When a read results in a cache miss, it'll get that block of memory and put it in the cache. A cache write miss then would mean that the location in memory that the program wants to write into is not within the cache, correct? So I'm reading the description of write-back, which is as follows according to wikipedia:

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.

So the only time that the memory of a cache block can be replaced is during a read, correct? And a write would simply change the data in a particular location of memory (and this would be within a cache block if it is a hit), but it would leave the actual memory locations within the block the same, correct?

This is my understanding of it and I just want to make sure it's correct.

Edit: wait, I guess during a cache miss it will also be replacing/updating the cache blocks....

解决方案

Wikipedia explains it quite well, actually. On one hand write-back vs. write-through defines when the data is written to the backing store (aka main memory):

  • 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.

On the other hand write allocate vs. no-write-allocate defines how to deal with write misses, i.e. wether or not data from the backing store is brought into the cache:

  • 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 or write 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.

这篇关于缓存读写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆