1.4k views
Assume that there are $3$ page frames which are initially empty. If the page reference string is $\text{1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6}$ the number of page faults using the optimal replacement policy is__________.
edited | 1.4k views

Answer : initially all empty frames fill by $\mathbf{1,2,3}$ so all time page fault which is $\mathbf{3}$ .

Then next $4$ was not available in frame set so, we look at ahead of request which was coming last we replace $4$ with that so, $3$ will be replace by $4$ and like wise next $2$ and $1$ is present already, so no. page fault and then next $5$ is not present so, replace with $1$ and then $3$ was not present and replace with $5$ and then $2$ and $4$ are present already so no page fault and then last $6^{th}$ was not already there so, page fault.

So, total page fault at : $\mathbf{1 , 2 , 3 , 4 , 5 , 3 , 6}$ . so, total $\mathbf{7}$ page fault occur ...

edited by
0
after processing the requests completly page reference 3,6,4 are present in main memory.
am i right ??
0

@ saurabh rai  3,6,4 or 6,2,4?

+2
6,2,4 are in memory @jagmeet

In optimal page replacement replacement policy, we replace the place which is not used for longest duration in future.

Given three page frames.

Reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6

Initially, there are three page faults and entries are
1  2  3

Page 4 causes a page fault and replaces 3 (3 is the longest
distant in future), entries become
1  2  4
Total page faults =  3+1 = 4

Pages 2 and 1 don't cause any fault.

5 causes a page fault and replaces 1, entries become
5  2  4
Total page faults =  4 + 1 = 5

3 causes a page fault and replaces 1, entries become
3  2  4
Total page faults =  5 + 1 = 6

3, 2 and 4 don't cause any page fault.

6 causes a page fault.
Total page faults =  6 + 1 = 7

In optimal we go into the future and see which page will not be referred for the longest time.

we will get 7 page faults