2082 2

BIT204 ยท 2082 ยท 10 marks

When does page fault occur?Given the 7 page reference strings 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3, find the number of page fault using Optimal Page Replacement, FIFO and Second Chance Replacement algorithm. Assume the size of page frame is 4.[1+9]

When does page fault occur?Given the 7 page reference strings 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3, find the number of page fault using Optimal Page Replacement, FIFO and Second Chance Replacement algorithm. Assume the size of page frame is 4.[1+9]

Operating SystemsChapter 8: Virtual Memory and PagingPage fault definition and occurrenceNumerical: page replacement algorithms

Page Fault and Page Replacement Algorithms

When Does a Page Fault Occur?

A page fault occurs when a process references a page that is not currently present in main memory (RAM). The CPU generates a trap, and the OS must bring the required page from secondary storage into a frame. If no free frame exists, a page replacement algorithm chooses a victim to evict.


Given Data

  • Reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3
  • Number of frames: 4
  • Total references: 14

1. Optimal Page Replacement

Replace the page not needed for the longest time in the future.

RefFrames (contents)Fault
77F
07 0F
17 0 1F
27 0 1 2F
07 0 1 2Hit
3replace 1 โ†’ 7 0 3 2F
07 0 3 2Hit
4replace 7 โ†’ 4 0 3 2F
24 0 3 2Hit
3Hit
0Hit
3Hit
2Hit
3Hit

At ref 3 (index 6), page 1 is never used again โ†’ evict 1.
At ref 4, remaining future refs: 2,3,0,3,2,3. Page 7 never used again โ†’ evict 7.

Optimal Page Faults = 6


2. FIFO Page Replacement

Replace the oldest loaded page.

RefFramesFIFO QueueFault
77[7]F
07 0[7,0]F
17 0 1[7,0,1]F
27 0 1 2[7,0,1,2]F
07 0 1 2[7,0,1,2]Hit
3replace 7 โ†’ 0 1 2 3[0,1,2,3]F
00 1 2 3[0,1,2,3]Hit
4replace 0 โ†’ 1 2 3 4[1,2,3,4]F
21 2 3 4[1,2,3,4]Hit
31 2 3 4[1,2,3,4]Hit
0replace 1 โ†’ 2 3 4 0[2,3,4,0]F
32 3 4 0[2,3,4,0]Hit
22 3 4 0[2,3,4,0]Hit
32 3 4 0[2,3,4,0]Hit

FIFO Page Faults = 7


3. Second Chance (Clock) Page Replacement

FIFO order maintained, but on a hit the reference bit R is set to 1. When selecting a victim, if the oldest page has R=1, clear it to 0 and move it to the back (give it a second chance); if R=0, replace it.

Notation: page(R).

RefFrames (queue oldestโ†’newest)ActionFault
77(0)loadF
07(0) 0(0)loadF
17(0) 0(0) 1(0)loadF
27(0) 0(0) 1(0) 2(0)loadF
07(0) 0(1) 1(0) 2(0)hit, set R(0)=1Hit
37 is oldest, R=0 โ†’ evict 7. New: 0(1) 1(0) 2(0) 3(0)replace 7F
00(1) 1(0) 2(0) 3(0)hit (0 already R=1)Hit
4Oldest 0 has R=1 โ†’ clear to 0, move back. Next oldest 1 has R=0 โ†’ evict 1. New: 2(0) 3(0) 0(0) 4(0)replace 1F
22(1) 3(0) 0(0) 4(0)hit, set R=1Hit
32(1) 3(1) 0(0) 4(0)hit, set R=1Hit
02(1) 3(1) 0(1) 4(0)hit, set R=1Hit
32(1) 3(1) 0(1) 4(0)hitHit
22(1) 3(1) 0(1) 4(0)hitHit
32(1) 3(1) 0(1) 4(0)hitHit

Step detail at ref 4: clock pointer at oldest = 0 (R=1) โ†’ set R=0, advance; page 1 (R=0) โ†’ victim. Result frames = {2,3,0,4}. This matches FIFO's replacement here because giving 0 a second chance saved it.

Second Chance Page Faults = 6


Summary

AlgorithmPage Faults
Optimal6
FIFO7
Second Chance6

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.