我很难理解计算缓存命中的过程/公式是什么。所以,如果我们有一个主内存,有16个条目,缓存内存有4个条目,CPU加载内存地址: 0,1,2,8,9,2‘,如果缓存是直接映射的,b)双向关联的,我如何计算命中次数a?
发布于 2020-11-30 13:38:31
假设没有预取器和LRU作为替换机制。
a)用于直接映射缓存,每个内存项只能在一个缓存项中.缓存将像这样映射(默认假定分布一致):
Cache 0 --> can hold 0,4,8,12 of the main memory entries.
Cache 1 --> can hold 1,5,9,13 of the main memory entries.
Cache 2 --> can hold 2,6,10,14 of the main memory entries.
Cache 3 --> can hold 3,7,11,15 of the main memory entries.重置后,缓存为空。
Load from 0 will be missed and will be cached in cache entry 0.
Load from 1 will be missed and will be cached in cache entry 1.
Load from 2 will be missed and will be cached in cache entry 2.
Load from 8 will be missed and will be cached in cache entry 0 (replaced load 0).
Load from 9 will be missed and will be cached in cache entry 1 (replaced load 1).
load from 2 will be hit and will be taken from cache entry 2.:1次命中,5次未命中,命中率为1/(5+1) = 1/6 = 16%
b)用于2种方式的关联,您将对缓存中的内存中的每个条目有两个要访问的条目。因此,set0 (缓存中的条目0,1 )将保存所有偶数主内存条目,而set1将保存所有奇怪的条目,因此,如果我们跨越它,就会有如下所示:
cache 0 (set 0) --> can hold 0,2,4,6,8,10,12,14 of the main memory entries.
cache 1 (set 0) --> can hold 0,2,4,6,8,10,12,14 of the main memory entries.
cache 2 (set 1) --> can hold 1,3,5,7,9,11,13,15 of the main memory entries.
cache 2 (set 0) --> can hold 1,3,5,7,9,11,13,15 of the main memory entries.重置后,缓存为空。
Load from 0 will be missed and will be cached in cache entry 0.
Load from 1 will be missed and will be cached in cache entry 2.
Load from 2 will be missed and will be cached in cache entry 1.
Load from 8 will be missed and will be cached in cache entry 0 (replaced load 0 because we replace the Least Recently Used).
Load from 9 will be missed and will be cached in cache entry 3.
load from 2 will be hit and will be taken from cache entry 1.在这种情况下,命中率是相同的:1/(5+1) = 1/6 = 16%
https://stackoverflow.com/questions/64945848
复制相似问题