如何实现分类缓存未命中?

时间:2018-10-22 01:00:58

标签: caching

有三种类型的高速缓存未命中:强制性,容量和冲突。现在,我需要添加缓存未命中分类功能。

假设我们遇到了一个由 tag 标签的读写错误。我使用全局向量 V1 来模拟无限缓存,使用另一个向量 V2 来模拟完全关联。缓存。 V2 中,最近使用最少的(LRU)元素是head元素,如果V2已满,则将其转储,并将V2的大小保持为实际缓存大小 CacheSize

我的想法如下:

if (V1 does not contain tag):
    it is compulsory miss.
    add tag to V1.
    if (V2's size == CacheSize):
        remove head element of V2.
    add tag to V2 tail.

if not compulsory miss:
    if V2 does not contain tag:
        it is capacity miss.
        if (V2's size == CacheSize):
             remove head element of V2.
        add tag to V2 tail.
    else: // V2 contains tag, rearrange tag's position
        remote tag from V2 then add tag to V2 tail.

if this miss is not compulsory miss or capacity miss, then it is conflict miss. 

我在代码中实现了这个想法,强制错失是正确的,但是没有容量错失。我在哪里做错了?谢谢。

0 个答案:

没有答案
相关问题