Evaluate optimal replacement algorithm for 5 frames

1.7k Views Asked by At

Question:

Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.

How many page faults would occur for the optimal page replacement algorithms, assuming five frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.

I am not quite sure what would happen:

1 -> 1 
2 -> 1, 2
3 -> 1, 2, 3
4 -> 1, 2, 3, 4, 
2 -> What happens here??
1
...etc (with the rest of the reference string)
1

There are 1 best solutions below

2
sudo bangbang On BEST ANSWER

There will be 7 page faults in total.

1 -> 1 
2 -> 1, 2
3 -> 1, 2, 3
4 -> 1, 2, 3, 4 
2 -> 1, 2, 3, 4    (This is a hit 2 is already in the memory)
1 -> 1, 2, 3, 4
5 -> 1, 2, 3, 4, 5 (This is a miss but we have 5 frames.)
6 -> 1, 2, 3, 6, 5 (4 will be replaced as it is not required in future)
...