• edited by
25,327 views
61 61 votes

Consider a fully associative cache with $8$ cache blocks (numbered $0-7$) and the following sequence of memory block requests:

$4, 3, 25, 8, 19, 6, 25, 8, 16, 35, 45, 22, 8, 3, 16, 25, 7$
If LRU replacement policy is used, which cache block will have memory block $7$?

  1. $4$
  2. $5$
  3. $6$
  4. $7$

6 Answers

Best answer
48 48 votes

When $45$ comes, the cache contents are:
$4$ $3$ $25$ $8$ $19$ $6$ $16$ $35$

LRU array (first element being least recently used)

$[4$ $3$ $19$ $6$ $25$ $8$ $16$ $35]$.  

So, $45$ replaces $4$.

4$5$ $3$ $25$ $8$ $19$ $6$ $16$ $35$ $[3$ $19$ $6$ $25$ $8$ $16$ $35$ $45]$

Similarly, $22$ replaces $3$ to give:

$45$ $22$ $25$ $8$ $19$ $6$ $16$ $35$ $[19$ $6$ $25$ $8$ $16$ $35$ $45$ $22]$

$8$ hits in cache.

$45$ $22$ $25$ $8$ $19$ $6$ $16$ $35$ $[19$ $6$ $25$ $16$ $35$ $45$ $22$ $8$]

$3$ replaces $19$

$45$ $22$ $25$ $8$ $3$ $6$ $16$ $35$ $[6$ $25$ $16$ $35$ $45$ $22$ $8$ $3]$

$16$ and $25$ hits in cache.

$45$ $22$ $25$ $8$ $3$ $6$ $16$ $35$ $[6$ $35$ $45$ $22$ $8$ $3$ $16$ $25]$

Finally, $7$ replaces $6$, which is in block $5$.

So, answer is (B).

• edited by
29 29 votes

Although many people have given correct answer but mentioning another approach to reduce error probability.

In the following image X axis is representing cache block and Y axis is representing Time. 

So answer is Option (B)

0 0 votes

This is my approach:

step1: make one block of 8 elements 

step2: just use LRU as below and update in block 

Note : From this method you will never  made any mistake just practice it.   

Answer:
Position:
Show:

Related questions

83 83 votes
13 answers 13 answers
45.2k
45.2k views
Ishrat Jahan asked Nov 1, 2014
45,158 views
Consider a system with $2$ level cache. Access times of Level $1$ cache, Level $2$ cache and main memory are $1$ $ns$, $10$ $ns$, and $500$ $ns$ respectively. The hit rat...
78 78 votes
8 answers 8 answers
39.4k
39.4k views
Ishrat Jahan asked Nov 2, 2014
39,357 views
The storage area of a disk has the innermost diameter of $10$ cm and outermost diameter of $20$ cm. The maximum storage density of the disk is $1400$ bits/cm. The disk ro...
37 37 votes
3 answers 3 answers
12.6k
12.6k views
Ishrat Jahan asked Nov 2, 2014
12,631 views
A CPU has only three instructions $I1, I2$ and $I3,$ which use the following signals in time steps $T1-T5$:$I1 : T1$ : Ain, Bout, Cin $T2$ : PCout, Bin $T...
48 48 votes
5 answers 5 answers
21.6k
21.6k views
Ishrat Jahan asked Nov 2, 2014
21,627 views
Consider a pipeline processor with $4$ stages $S1$ to $S4$. We want to execute the following loop:for (i = 1; i < = 1000; i++) {I1, I2, I3, I4}where the time taken (in ns...