View worked solution
Answer: 7
Under the Optimal Page Replacement policy, we replace the page that will not be used for the longest period of time in the future. We have initially empty frames.
The step-by-step trace of the page reference string is shown below:
| Ref | Frame 1 | Frame 2 | Frame 3 | Result | Reason / Replacement |
|---|---|---|---|---|---|
| 1 | 1 | - | - | Page Fault (1) | Initially empty |
| 2 | 1 | 2 | - | Page Fault (2) | Initially empty |
| 3 | 1 | 2 | 3 | Page Fault (3) | Initially empty |
| 4 | 1 | 2 | 4 | Page Fault (4) | Replace 3 (used furthest in future at step 8) |
| 2 | 1 | 2 | 4 | Hit | Page 2 already present |
| 1 | 1 | 2 | 4 | Hit | Page 1 already present |
| 5 | 5 | 2 | 4 | Page Fault (5) | Replace 1 (not used in future) |
| 3 | 3 | 2 | 4 | Page Fault (6) | Replace 5 (not used in future) |
| 2 | 3 | 2 | 4 | Hit | Page 2 already present |
| 4 | 3 | 2 | 4 | Hit | Page 4 already present |
| 6 | 6 | 2 | 4 | Page Fault (7) | Replace any (e.g., 3) |
Thus, the total number of page faults is 7.
Free practice · Your answers on this page are not saved.
