IAE Academy

GATE 2022 CS Q.64: solution and answer

GATE 2022 · CSQ.64 · 2 marks · NAT

Consider a demand paging system with four page frames (initially empty) and LRU page replacement policy. For the following page reference string

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

the page fault rate, defined as the ratio of number of page faults to the number of memory accesses (rounded off to one decimal place) is ______.

See the question in the paper

Answer and solution

ANSWER

The page fault rate is 9/15 = 0.6.

Official answer: 0.6Source: Official answer key, GATE 2022 CS (IIT Kharagpur)

  1. There are 4 frames and references. Simulate LRU, evicting the page whose last use is oldest.

  2. Reference 4 (position 8): the frames are full. Last uses are 7 at position 3, 2 at 5, 5 at 6 and 3 at 7, so 7 is least recently used. Fault, evict 7. Frames: 2,3,5,4.

  3. Reference 6 (position 9): last uses are 2 at 5, 3 at 7, 5 at 6 and 4 at 8, so evict 2. Fault. Frames: 6,3,5,4.

  4. Reference 7 (position 10): last uses are 3 at 7, 5 at 6, 4 at 8 and 6 at 9, so evict 5. Fault. Frames: 6,3,7,4. The next 7 (position 11) is a hit.

  5. Reference 1 (position 12): last uses are 3 at 7, 4 at 8, 6 at 9 and 7 at 11, so evict 3. Fault. Frames: 6,1,7,4.

  6. Reference 5 (position 13): last uses are 4 at 8, 6 at 9, 7 at 11 and 1 at 12, so evict 4. Fault. Frames: 6,1,7,5. The last two references, 6 and 1, are hits.

  7. Faults occur on 7, 2, 3, 5, 4, 6, 7, 1, 5, which is faults in accesses.

KEY IDEA

Under LRU, on a fault with full frames evict the page whose most recent use is oldest. Count faults over all 15 accesses and divide by 15.

WATCH OUT FOR

Counting only faults after the frames fill, or evicting by first arrival (FIFO) instead of by last use. Another slip is dividing by the number of distinct pages instead of the 15 accesses.

From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 6 Virtual memory questions, with notes

More Virtual memory questions