The main memory of a computer has 2cm blocks while the cache has 2c blocks. If…
2020
The main memory of a computer has 2cm blocks while the cache has 2c blocks. If the cache uses the set-associative mapping scheme with two blocks per set, then block k of the main memory maps to the set:
Answer: B. (k mod c) of the cache — In set-associative mapping, a cache is partitioned into equal-size sets and each main-memory block is assigned to exactly one set. The governing rule is: set…
- A.
(k mod m) of the cache
- B.
(k mod c) of the cache
- C.
(k mod 2c) of the cache
- D.
(k mod 2cm) of the cache
Attempted by 244 students.
Show answer & explanation
Correct answer: B
In set-associative mapping, a cache is partitioned into equal-size sets and each main-memory block is assigned to exactly one set. The governing rule is: set index = (block number) mod (number of cache sets). The modulus is the number of sets, not the number of cache blocks.
Applying the rule to this item:
Notation check: 2c and 2cm in the source are ordinary products, 2 × c and 2 × c × m; they are not powers of 2.
Cache size: the cache contains 2c blocks.
Associativity: two blocks are stored in each set.
Number of sets: S = (2c cache blocks) / (2 blocks per set) = c.
Mapping: block k is assigned to set k mod c.
Therefore, block k of main memory maps to set (k mod c) of the cache.
Contrast with the other values:
(k mod m) uses the main-memory multiplier m rather than the cache-set count.
(k mod 2c) uses the total number of cache blocks before grouping them two per set.
(k mod 2cm) uses the total number of main-memory blocks rather than the cache-set count.
Cross-check: 2cm main-memory blocks distributed across c sets give 2cm / c = 2m candidate blocks per set, which is consistent with c cache sets.