Write-through, write-around and write-back cache
There are three main caching techniques that can be deployed, each with their own pros and cons.
- Write-through cache directs write I/O ontocache and through to underlying permanent storage before confirming I/O completion to the host. This ensures data updates are safely stored on, for example, a shared storage array, but has the disadvantage that I/O still experiences latency based on writing to that storage. Write-through cache is good for applications that write and then re-read data frequently as data is stored in cache and results in low read latency. 同时写cache和主存。
- Write-around cache is a similar technique to write-through cache, but write I/O is written directly to permanent storage, by passing the cache. This can reduce the cache being flooded with write I/O that will not subsequently be re-read, but has the disadvantage is that a read request for recently written data will create a “cache miss” and have to be read from slower bulk storage and experience higher latency. 只写内存,绕过cache。
- Write-back cache is where write I/O is directed to cache and completion is immediately confirmed to the host. This results in low latency and high throughput for write-intensive 集中写 applications, but there is data availability exposure risk because the only copy of the written data is in cache. As we will discuss later, suppliers have added resiliency with products that duplicate writes. Users need to consider whether write-back cache solutions offer enough protection as data is exposed until it is staged to external storage. Write-back cache is the best performing solution for mixed workloads as both read and write I/O have similar response time levels.
----- 在有cache的单机系统中,通常有两种写策略:write through 和 write back。
这两种写策略都是针对写命中(write hit)情况而言的:
--------- write through是既写cache也写main memory;
--------- write back是只写cache,并使用dirty标志位记录cache的修改,直到被修改的cache 块被替换时,才把修改的内容写回main memory。
那么在写失效(write miss)时,即所要写的地址不在cache中,该怎么办呢?
一种办法就是把要写的内容直接写回main memory,这种办法叫做no write allocate policy;
另一种办法就是把要写的地址所在的块先从main memory调入cache中,然后写cache,这种办法叫做write allocate policy。
在有cache的多处理器系统中仍然会有写失效(write miss)的情况,而且no write allocate policy和write allocate policy也仍然都可以使用。需要讨论的只是在出现write miss这种情况后,snooping cache该如何处理的问题。假设执行写操作的是P1,监听的是P2的cache,那么无论P1执行写操作时是write hit还是write miss,P2的cache(即snooping cache)都会检查P1所写的地址是否在P2的cache中,假如执行的是write invalid策略,那么snooping cache或者把相应的块置为invalid,或者什么都不做(因为它没有相应的块),肯定不会把其它处理器所要写的块调入自己的cache中(因为没有任何意义)。
本文介绍了三种主要的缓存写策略:Write-through、Write-around 和 Write-back,详细探讨了各自的优缺点及其适用场景。Write-through 确保数据更新的安全性,Write-around 减少了缓存的负载,而 Write-back 则提供了最佳的性能。
3293

被折叠的 条评论
为什么被折叠?



