IAE Academy

GATE 2025 CS1 Q.54: solution and answer

GATE 2025 · CS1Q.54 · 2 marks · NAT

In optimal page replacement algorithm, information about all future page references is available to the operating system (OS). A modification of the optimal page replacement algorithm is as follows:

The OS correctly predicts only up to next 4 page references (including the current page) at the time of allocating a frame to a page.

A process accesses the pages in the following order of page numbers: 1, 3, 2, 4, 2, 3, 1, 2, 4, 3, 1, 4.

If the system has three memory frames that are initially empty, the number of page faults that will occur during execution of the process is ________. (Answer in integer)

See the question in the paper

Answer and solution

ANSWER

The process incurs 6 page faults.

Official answer: 6Source: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. Number the references as positions to . When a fault occurs and all frames are full, look only at the next references (the current one included). Evict the page whose next use in that window is farthest away, or which does not appear in the window at all.

  2. Positions , and (pages ) fault into empty frames. That is faults, and the frames hold .

  3. Position (page ) is a fault, making faults. The window is , so the resident pages are next used at: page at position , page at position , page at position . Page is farthest, so evict it. The frames hold .

  4. Positions and (pages ) are hits.

  5. Position (page ) is a fault, making faults. The window is , so the resident pages are next used at: page at position , page at position , page at position . Page is farthest, so evict it. The frames hold .

  6. Positions and (pages ) are hits.

  7. Position (page ) is a fault, making faults. Only remain, so the window is . Page does not appear in the window, so evict it. The frames hold .

  8. Positions and (pages ) are hits. The total is page faults.

KEY IDEA

Simulate optimal replacement with a limited lookahead. On a fault with full frames, evict the page whose next use inside the next 4 references (current included) is farthest, and treat a page absent from that window as farthest of all.

WATCH OUT FOR

Using full future knowledge, as in ordinary optimal replacement, instead of only the 4-reference window. Another slip is forgetting that the window shrinks near the end of the string, and so miscounting which page to evict at position 10.

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

More Virtual memory questions