Cache Inclusion Assume you have an L2 cache that is direct-mapped with 4 sets. Assume L1 cache is fully-associate with capacity of 2 blocks and it uses LRU policy If you know that blocks A, B, C and D map to sets 0, 1, 2 and 3 in L2 Cache. If you know the current state of both L1 and L2 cache is as following: Set 0 LRU t 1 Set 2 DIC Set 3 L1 Cache L2 Cache .If our next access is for block E that maps to set 3 in L2 cache, fill/describe the state of the caches after the access, if we use: Inclusive L2 Cache Non-Inclusive L2 Cache
The Correct Answer and Explanation is :
Here’s the step-by-step explanation for the given scenario:
Assumptions:
- L2 Cache: Direct-mapped with 4 sets (Set 0 to Set 3).
- L1 Cache: Fully associative with a capacity of 2 blocks and uses LRU replacement.
- Current State:
- L1 Cache: Contains
AandB(most recently used first order assumed asA, B). - L2 Cache:
- Set 0: Contains
A. - Set 1: Contains
B. - Set 2: Contains
C. - Set 3: Contains
D.
- Set 0: Contains
- Block
Emaps to Set 3 in L2 Cache.
Access: Block E (maps to Set 3 in L2)
Case 1: Inclusive L2 Cache
- Rule: L1 cache must contain only blocks also present in L2 cache.
- Access flow:
- Block
EreplacesDin Set 3 of L2 (due to direct mapping). - Since
Dis removed from L2, it must also be invalidated in L1 (inclusive property). - Block
Eis loaded into L1. - L1 now updates based on LRU replacement:
- Since
AandBare in L1 and the capacity is 2, the least recently used block (B) is evicted to accommodateE.
- Since
- Final State:
- L1 Cache:
A, E(most recent first). - L2 Cache:
- Set 0:
A. - Set 1:
B. - Set 2:
C. - Set 3:
E.
- Set 0:
Case 2: Non-Inclusive L2 Cache
- Rule: L1 and L2 are independent; L1 may contain blocks not present in L2.
- Access flow:
- Block
EreplacesDin Set 3 of L2 (due to direct mapping). - No invalidation occurs in L1 (non-inclusive property allows
Dto remain in L1). - Block
Eis loaded into L1. Based on LRU,B(least recently used in L1) is evicted.
- Final State:
- L1 Cache:
A, E(most recent first). - L2 Cache:
- Set 0:
A. - Set 1:
B. - Set 2:
C. - Set 3:
E.
- Set 0:
Key Difference:
- Inclusive L2 Cache: Blocks evicted from L2 are invalidated in L1.
- Non-Inclusive L2 Cache: No invalidation in L1 occurs when blocks are evicted from L2.