In a \(k\)-way set associative cache, the cache is divided into \(v\) sets,…
2013
In a \(k\)-way set associative cache, the cache is divided into \(v\) sets, each of which consists of \(k\) lines. The lines of a set are placed in sequence one after another. The lines in set \(s\) are sequenced before the lines in set \((s+1)\). The main memory blocks are numbered 0 onwards. The main memory block numbered \(j\) must be mapped to any one of the cache lines from
- A.
\((j \ mod \ v) * k \ to \ (j \ mod \ v) * k + (k-1)\) - B.
\((j \ mod \ v) \ to \ (j \ mod \ v) + (k-1)\) - C.
\((j \ mod \ k) \ to \ (j \ mod \ k) + (v-1)\) - D.
\((j \ mod \ k) * v \ to \ (j \ mod \ k) * v + (v-1) \)
Attempted by 125 students.
Show answer & explanation
Correct answer: A
Key insight: a memory block j maps to set s = j mod v, and that set's k lines are placed sequentially.
Step 1: Find the set index s = j mod v.
Step 2: The k lines of set s occupy consecutive cache line indices from s*k to s*k + (k-1).
Conclusion: Substituting s = j mod v gives the mapping (j mod v) * k to (j mod v) * k + (k-1).
A video solution is available for this question — log in and enroll to watch it.