retagged by
408 views
1 votes
1 votes

Consider a set associative cache memory with $8$ cache blocks $(0 - 7)$ and main memory with $128$ blocks. The following block requests are made by the $CPU$ ($\text{LRU}$ (Least Recently Used) policy is used for cache block replacement).

$0 \;5\;  3\;  9\;  7\;  0\;  16\;  55$

If the cache is $2 - way$ set associative, then the cache set and block pair in which main memory block $7$ is present is:

  1. $3, 7$
  2. $3, 6$
  3. $2, 5$
  4. $7$ is recently replaced
retagged by

1 Answer

Best answer
4 votes
4 votes

$8$ blocks in $2-way$ set-associative means we have $\frac{8}{2} = 4$ cache sets.

  • $0\% 4 = 0$ - set $0,$ block $0$
  • $5\% 4 = 1$ - set $1,$ block $2$
  • $3\% 4 = 3$ - set $3,$ block $6$
  • $9\% 4 = 1$ - set $1,$ block $3$ (as $2$ is occupied)
  • $7\% 4 = 3$ - set $3$, block $7$ (as $6$ is occupied)
  • $0\% 4 = 0$ - set $0$, block $1$ (as $0$ is occupied)
  • $16\% 4 = 0$ - set $0$, block $0$ after replacement
  • $55\% 4 = 3$ - set $3$, block $6$ after replacement


$7$ is present in set number $3$ and since $3$ is already there, $7$ moves to the second block which is block number $2\times 3 + 1=7.$

$55$ replaces $3$ in block $6$ due to $\text{LRU}$ replacement policy. With $\text{MRU}$ (Most Recently Used) policy it would have replaced $7$.

edited by
Answer:

Related questions