Assuming i have 4 blocks of cache memory, Using the LRU (Least Recently Used) replacement algorithm on this following sequence of access to memory blocks: 1 2 3 4 5 2 5 4 1 5 2 3 :
1 2 3 4 5 2 5 4 1 5 2 3
1 1 1 1 5 5 5 5 5 5 5 5
2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 1 1 1 1
4 4 4 4 4 4 4 4 3
So in the end, the cache memory will contains this memory blocks : "5 2 1 3"
But the correct result is "1 5 2 3"
Please tell me what am I doing wrong here!
Edit:
I will be honest, I'm doing an excercise and can't get help from anywhere but here, and may be I misread the question, so this is the original question :

In a straightforward cache, the order doesn't matter. And the LRU algorithm is simple enough that you don't need to run the whole simulation. Just look at the last 4 numbers in your sequence:
... 1 5 2 3
So is my simulation of the LRU wrong? Honestly i still don't get it!
The simulation goes awry in column 5 where you add the newest data to the oldest position.
Here's the correction:
1 2 3 3 3 2 2 4 1 <-- Oldest accesses
1 2 3 4 4 2 5 4 1 5
1 2 3 4 5 2 5 4 1 5 2
1 2 3 4 5 2 5 4 1 5 2 3 <-- Newest accesses
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With