CWHsu
CWHsu

Reputation: 87

Evaluate optimal replacement algorithm for 5 frames

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)

Upvotes: 0

Views: 2079

Answers (1)

sudo bangbang
sudo bangbang

Reputation: 28169

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)
...

Upvotes: 1

Related Questions