cache reads and writes

纵饮孤独 提交于 2019-12-08 13:36:04

问题


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


回答1:


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.


来源:https://stackoverflow.com/questions/23355136/cache-reads-and-writes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!