edited by
28,667 views
76 votes
76 votes

A computer has twenty physical page frames which contain pages numbered $101$ through $120$. Now a program accesses the pages numbered $\text{1, 2, ..., 100}$ in that order, and repeats the access sequence THRICE. Which one of the following page replacement policies experiences the same number of page faults as the optimal page replacement policy for this program?

  1. Least-recently-used
  2. First-in-first-out
  3. Last-in-first-out
  4. Most-recently-used
edited by

11 Answers

0 votes
0 votes

Answer: (D)

Explanation: The optimal page replacement algorithm swaps out the page whose next use will occur farthest in the future.

 

In the given question, the computer has 20 page frames and initially page frames are filled with pages numbered from 101 to 120. Then program accesses the pages numbered 1, 2, …, 100 in that order, and repeats the access sequence THRICE.

 

The first 20 accesses to pages from 1 to 20 would definitely cause page fault. When 21st is accessed, there is another page fault. The page swapped out would be 20 because 20 is going to be accessed farthest in future. When 22nd is accessed, 21st is going to go out as it is going to be the farthest in future.

 

The above optimal page replacement algorithm actually works as most recently used in this case.

 

Iteration 1: (1-100) Not present – all replaced 1-20 in 20 frames, 21-100 in 20th frame. hence, page faults = 100


Iteration 2: (1-19) present | (20-99) NOT present | (100) present – the replacements are done at the 19th frame hence, page faults = 100 – 19 – 1 = 80


Iteration 3: (1-18) present | (19-98) NOT present | (99-100) present – the replacements are done at the 18th frame hence page faults = 100 – 18 – 2 = 80


Iteration 4: (1-17) present | (17-97) NOT present | (98-100) present – the replacements are done at the 17th frame hence page faults = 100 – 17 – 3 = 80

 

Total page faults = 100 + 80 + 80 +80 = 340

 

Along with generating same number of page faults M.R.U also generates replacements at the same positions as in the Optimal algorithm.(Assuming the given 101-120 pages are INVALID (not belonging to the same process) or Empty).

While the LIFO replacement does not behave like Optimal replacement algorithm as it generates 343 page faults. Because from 21st page all pages are placed in 20th frame, therefore hits per iteration reduces down to 19 from the 2nd iteration of pages. Whereby

Total Page faults = 100 + 81 + 81 + 81 = 343

0 votes
0 votes

101….120 are already loaded in 1…..20...by MRU we would end up replacing 20th frame(120) as this is most recently used..I dont think it will match Optimal Algo..

0 votes
0 votes
1,2,3...........,98,99,100,1,2,3............19,20........98,99,100,1,2,3..........98,99,100,1,2,3..........98,99,100

INIT

{101,102,103....120}

 

OPTIMAL:

Round 1:

{1,2,3....100} == 100

Round 2:

{1,2,3....18,99,100} == 80  HIT {1-19,100}

Round 3:

{1,2,3....18,99,100} == 80  HIT {1-18,99,100}

Round 4:

{1,2,3....17,98,99,100} == 80  HIT {1-17,98,99,100}

Total = 340
Answer:

Related questions

24 votes
24 votes
4 answers
1
go_editor asked Sep 26, 2014
7,371 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 ...