Question

In a kk-way set associative cache, the cache is divided into vv sets, each of which consists of kk lines. The lines of a set are placed in sequence one after another. The lines in set ss are sequenced before the lines in set (s+1)(s+1). The main memory blocks are numbered 0 onwards. The main memory block numbered jj must be mapped to any one of the cache lines from

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2013 answer key

Solution

Derive the set index for memory block j and multiply by line capacity k to obtain the line number range.

In a kk-way set associative cache:

  • Total number of sets =v= v.
  • Each set contains kk lines.
  • A main memory block numbered jj maps to set index:
    s=j mod vs = j \bmod v

Because the cache lines are arranged sequentially set by set:

  • Set 0 occupies lines 00 through k−1k - 1.
  • Set 1 occupies lines kk through 2k−12k - 1.
  • In general, set ss begins at line s⋅ks \cdot k and ends at line s⋅k+(k−1)s \cdot k + (k - 1).

Substituting s=j mod vs = j \bmod v:

Starting line=(j mod v)∗k\text{Starting line} = (j \bmod v) * k
Ending line=(j mod v)∗k+(k−1)\text{Ending line} = (j \bmod v) * k + (k - 1)

Thus, block jj may be placed in any cache line from (j mod v)∗k(j \bmod v) * k to (j mod v)∗k+(k−1)(j \bmod v) * k + (k - 1).

Final answer

Option (A)

Common trap

Confusing the number of sets vv with associativity kk in the modulo operation.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2013 Computer Science and Information Technology (CS)
Question
20 of 65, printed as CS Q.20
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.