Consider a program that consists of 8 pages (from 0 to 7) and we have 4 page…

2014

Consider a program that consists of 8 pages (from 0 to 7) and we have 4 page frames in the physical memory for the pages. The page reference string is :

1 2 3 2 5 6 3 4 6 3 7 3 1 5 3 6 3 4 2 4 3 4 5 1

The number of page faults in LRU and optimal page replacement algorithms are respectively (without including initial page faults to fill available page frames with pages) :

  1. A.

    9 and 6

  2. B.

    10 and 7

  3. C.

    9 and 7

  4. D.

    10 and 6

Attempted by 94 students.

Show answer & explanation

Correct answer: B

Answer: LRU = 10 page faults; Optimal = 7 page faults (excluding initial fills).

Interpretation of "excluding initial page faults": do not count the page faults that occur while filling the four empty frames for the first time. Start counting faults only after the frames have been filled with four distinct pages.

Key steps for the LRU simulation (counting begins after the frames are first filled):

  • After initial fill (pages 1,2,3,5), the subsequent faults and evictions are:

  • Reference 6: fault — evict least recently used page 1

  • Reference 4 (page 4): fault — evict LRU page 2

  • Reference 11 (page 7): fault — evict LRU page 5

  • Reference 13 (page 1): fault — evict LRU page 4

  • Reference 14 (page 5): fault — evict LRU page 6

  • Reference 16 (page 6): fault — evict LRU page 7

  • Reference 18 (page 4): fault — evict LRU page 1

  • Reference 19 (page 2): fault — evict LRU page 5

  • Reference 23 (page 5): fault — evict LRU page 6

  • Reference 24 (page 1): fault — evict LRU page 2

Total LRU page faults counted after initial filling: 10

Key steps for the Optimal simulation (counting begins after the frames are first filled):

  • After initial fill (pages 1,2,3,5), choose the page to evict whose next use is farthest in the future (or not used again):

  • Reference 6 (page 6): fault — evict page 2 (next use at position 19, farthest)

  • Reference 8 (page 4): fault — evict page 5 (next use at position 14, farthest)

  • Reference 11 (page 7): fault — evict page 4 (next use at position 18, farthest among current pages)

  • Reference 14 (page 5): fault — evict page 7 (7 is not used again)

  • Reference 18 (page 4): fault — evict page 6 (6 is not used again)

  • Reference 19 (page 2): fault — evict page 1 (next use at position 24, farthest)

  • Reference 24 (page 1): fault — evict any page not used later (final fault)

Total Optimal page faults counted after initial filling: 7

Conclusion: Counting only the page faults that occur after the four frames are initially filled yields LRU = 10 and Optimal = 7.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor