Caching Hit&;未命中使用4路关联缓存

Caching Hit&;未命中使用4路关联缓存,caching,memory-management,Caching,Memory Management,问题: Given a computer ,where were made the following memory accesses (from left to right) : 5 ,10 ,2 ,34 ,18 ,4 ,22 ,21 ,11 ,2 * Decide if we have a HIT or MISS when dealing with a 4-way associative mapping , when the total size of the cache is

问题:

Given a computer ,where were made the following memory accesses 

(from left to right) : 

5 ,10 ,2 ,34 ,18 ,4 ,22 ,21 ,11 ,2

* Decide if we have a HIT or MISS when dealing with a 4-way associative mapping ,
  when the total size of the cache is 32 blocks of 2 bytes !

* When you're done , write the final map of the cache 
我的答覆是:

集合的大小为4,因此:

(区块数量)/(通道数量)=32/4=8

然后我们有一个缓存,它有八个单元格,从0到7(如果我错了,请纠正我!!?

现在:5:(4,5)→5/2=2→2 % 8=2→第2单元→错过

10:(10,11)→10/2=5→5 % 8=5→第5单元→错过

2:(2,3)→2/2=1→1 %8=1→第1单元→错过

34:(34,35)→34/2=17→17 % 8=1→第1单元→错过

18:(18,19)→18/2=9→9 % 8=1→第1单元→错过

4:在第二单元中击中

22:(22,23)→22/2=11→11 % 8=3→第三单元→错过

21:(20,21)→21/2=10→10 % 8=2→第2单元→错过

11:在第5单元中击中

2:在第1单元中击中

现在,缓存的最终映射是:

0: empty
1: (2,3) (34,35) (18,19)
2: (4,5) (20,21)
3: (22,23)
4: empty
5: (10,11)
6: empty
7: empty
  • 我的回答正确吗

  • 我把缓存的地图弄错了吗

  • 非常感谢你的帮助。。。。我的考试马上就要开始了:)

    谢谢

    Ron

    一个简单的Python程序(忽略替换,因为没有替换)说您是正确的

    from collections import defaultdict
    
    d = defaultdict(list)
    
    for item in (5 ,10 ,2 ,34 ,18 ,4 ,22 ,21 ,11 ,2):
        value = item // 2 * 2, item // 2 * 2 + 1
        cell = item // 2 % 8
        if value in d[cell]:
            print "HIT", cell
        else:
            d[cell].append(value)
            print "MISS", cell
    
    for i in range(8):
        print i, d[i]
    
    --

    MISS 2
    MISS 5
    MISS 1
    MISS 1
    MISS 1
    HIT 2
    MISS 3
    MISS 2
    HIT 5
    HIT 1
    
    0 []
    1 [(2, 3), (34, 35), (18, 19)]
    2 [(4, 5), (20, 21)]
    3 [(22, 23)]
    4 []
    5 [(10, 11)]
    6 []
    7 []