retagged by
13,995 views
73 votes
73 votes

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

  1. $(j\text{ mod }v) * k \text{ to } (j \text{ mod } v) * k + (k-1) $
  2. $(j \text{ mod } v) \text{ to } (j \text{ mod } v) + (k-1) $
  3. $(j \text{ mod } k) \text{ to } (j \text{ mod } k) + (v-1) $
  4. $(j \text{ mod } k) * v \text{ to } (j \text{ mod } k) * v + (v-1) $
retagged by

5 Answers

Best answer
97 votes
97 votes
Number of sets in cache $= v$.

The question gives a sequencing for the cache lines. For set $0$, the cache lines are numbered $0, 1, .., k-1$. Now for set $1$, the cache lines are numbered $k, k+1,... k+k-1$ and so on.

So, main memory block $j$ will be mapped to set $(j \ \text{mod} \ v)$, which will be any one of the cache lines from $(j \ \text{mod  } v) * k \ \text{ to } (j \ \text{mod  } v) * k + (k-1)$.
(Associativity plays no role in mapping- $k$-way associativity means there are $k$ spaces for a block and hence reduces the chances of replacement.)

Correct Answer: $A$
edited by
27 votes
27 votes
set number block 
0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3

In above exaple 16 blocks are there. and 4 sets.Each set contains 4 blocks.

Suppose memory address are like this : 0,4,8,14 these all can fit into set 0 in any order where it get place but mostly FIFO.

jth is memory block will be placed at j mod v = set number 

Let j=14 the main memory block. 14 mod 4 = 2 we are at set number 2  but to read at set to we need to pass set0 and set1 each having k size .

so 2 * k =2*4 gives =8th cache block that is starting block of 3rd cache set.But each cache also having k way set associativy that means more k-1 block can be placed in that set.

so (j mod v) * k + (j mod v)*k +(k-1) should be the ans.

1 votes
1 votes

Think of it as two-dimensional array, $A[v][k]$ with $v$ rows and $k$ columns since each set $i$ has exactly $k$ blocks in it.

A block $j$ will map to set $j\%v$ and any of the blocks $0$ through $k-1$ of that set.

Thus, you need the position of $A[j\%v][0]$ and $A[j\%v][k-1]$ in memory. Using simple 2D array address translation, these come out to be $(j\%v)*k$ and $(j\%v)*k+(k-1)$.

Answer: Option (A).

1 votes
1 votes

..….......…..….…..….….…...……………………................….…

Answer:

Related questions

42 votes
42 votes
5 answers
1
Arjun asked Sep 24, 2014
14,929 views
Consider the following sequence of micro-operations.MBR ← PC MAR ← X PC ← Y Memory ← MBRWhich one of the following is a possible operation performed by this seque...