0% found this document useful (0 votes)
8 views

Unit 4 Part 3

Uploaded by

devang040204
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unit 4 Part 3

Uploaded by

devang040204
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT 04

Page Replacement Algorithm – Numerical


Q1. Consider the following page reference string 3,2,1,3,4,1,6,2,4,3,4,2,1,4,5,2,1,3,4. How
many page faults would occur assuming three frames are made available for FIFO, LRU, and
optimal page replacement algorithm?

FIFO: First In First Out Page Replacement Algorithm

- Oldest page in the memory will be replaced.


- Has the highest page fault rate.

Frames 3 2 1 3 4 1 6 2 4 3 4 2 1 4 5 2 1 3 4
0 3 3 3 3 4 4 4 4 4 3 3 3 3 3 5 5 5 5 4
1 2 2 2 2 2 6 6 6 6 4 4 4 4 4 2 2 2 2
2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 3 3
Page * * * * * *
Hit

Total Page Hit = 6

Total Page Fault/Page Miss = Total Page – Page Hit = 19-6 = 13

Hit Ratio = Page Hit/Total no of Pages = 6/19 = 0.315

Miss Ratio = Page Fault/Total no of Pages =13/19 = 0.6842

LRU: Least Recently Used Page Replacement Algorithm

- Page which has not been used for the longest time is replaced.

FRAME 3 2 1 3 4 1 6 2 4 3 4 2 1 4 5 2 1 3 4
0 3 3 3 3 3 3 6 6 6 3 3 3 1 1 1 2 2 2 4
1 2 2 2 4 4 4 2 2 2 2 2 2 2 5 5 5 3 3
2 1 1 1 1 1 1 4 4 4 4 4 4 4 4 1 1 1
Page * * * * *
Hit

Total Page Hit = 5

Total Page Fault/Page Miss = Total Page – Page Hit = 19-5 = 14

Hit Ratio = Page Hit/Total no of Pages = 5/19 = 0.263

Miss Ratio = Page Fault/Total no of Pages = 14/19 = 0.736


Optimal Page Replacement Algorithm

- Replace the page that will not be used for the longest time.
- Has the lowest page fault.

FRAME 3 2 1 3 4 1 6 2 4 3 4 2 1 4 5 2 1 3 4
0 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3
2 1 1 1 1 6 6 6 3 3 3 1 1 1 1 1 1 4
Page * * * * * * * * *
Hit
1

Total Page Hit = 9

Total Page Fault/Page Miss = Total Page – Page Hit = 19-9=10

Hit Ratio = Page Hit/Total no of Pages = 9/19=0.473

Miss Ratio = Page Fault/Total no of Pages=10/19=0.5263


Q2. Consider the following page reference string 1,2,3,4,2,1,5,6,2,1,2,3,7,6,3,2,1,2,3,6. How
many page faults would occur assuming three frames are made available for FIFO, LRU, and
optimal page replacement algorithm?

FIFO: First In First Out Page Replacement Algorithm

- Oldest page in the memory will be replaced.


- Has the highest page fault rate.

Frames 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
0 1 1 1 4 4 4 4 6 6 6 6 3 3 3 3 2 2 2 2 6
1 2 2 2 2 1 1 1 2 2 2 2 7 7 7 7 1 1 1 1
2 3 3 3 3 5 5 5 1 1 1 1 6 6 6 6 6 3 3
Page * * * *
Hit

Total Page Hit = 4

Total Page Fault/Page Miss = Total Page – Page Hit = 20-4 = 16

Hit Ratio = Page Hit/Total no of Pages = 4/20 = 0.2

Miss Ratio = Page Fault/Total no of Pages = 16/20 = 0.8

LRU: Least Recently Used Page Replacement Algorithm

- Page which has not been used for the longest time is replaced.

FRAME 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
0 1 1 1 4 4 4 5 5 5 1 1 1 7 7 7 2 2 2 2 2
1 2 2 2 2 2 2 6 6 6 6 3 3 3 3 3 3 3 3 3
2 3 3 3 1 1 1 2 2 2 2 2 6 6 6 1 1 1 6
Page * * * * *
Hit

Total Page Hit = 5

Total Page Fault/Page Miss = Total Page – Page Hit = 20-5 = 15

Hit Ratio = Page Hit/Total no of Pages = 5/20 = 0.25

Miss Ratio = Page Fault/Total no of Pages = 15/20 = 0.75

Optimal Page Replacement Algorithm

- Replace the page that will not be used for the longest time.
- Has the lowest page fault.
-
FRAME 1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6
0 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 6
1 2 2 2 2 2 2 2 2 2 2 2 7 7 7 2 2 2 2 2
2 3 4 4 4 5 6 6 6 6 6 6 6 6 6 1 1 1 1
Page * * * * * * * * *
Hit

Total Page Hit = 9

Total Page Fault/Page Miss = Total Page – Page Hit = 20-9 = 11

Hit Ratio = Page Hit/Total no of Pages = 9/20 = 0.45

Miss Ratio = Page Fault/Total no of Pages = 11/20 = 0.55


Q3. How many page faults would occur for the following reference string for four page
frames using LRU and FIFO algorithms: 1,2,3,4,5,5,3,4,1,6,7,8,7,8,9,7,8,9,5,4,5,4,2.

FIFO: First In First Out Page Replacement Algorithm

- Oldest page in the memory will be replaced.


- Has the highest page fault rate.

Frames 1 2 3 4 5 5 3 4 1 6 7 8 7 8 9 7 8 9 5 4 5 4 2
0 1 1 1 1 5 5 5 5 5 5 5 8 8 8 8 8 8 8 8 8 8 8 2
1 2 2 2 2 2 2 2 1 1 1 1 1 1 9 9 9 9 9 9 9 9 9
2 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6 5 5 5 5 5
3 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 4 4 4 4
Page * * * * * * * * * *
Hit

Total Page Hit = 10

Total Page Fault/Page Miss = Total Page – Page Hit = 23-10 = 13

Hit Ratio = Page Hit/Total no of Pages = 10/23 = 0.4347

Miss Ratio = Page Fault/Total no of Pages = 13/23 = 0.5652

LRU: Least Recently Used Page Replacement Algorithm

- Page which has not been used for the longest time is replaced.

Frames 1 2 3 4 5 5 3 4 1 6 7 8 7 8 9 7 8 9 5 4 5 4 2
0 1 1 1 1 5 5 5 5 5 6 6 6 6 6 6 6 6 6 5 5 5 5 5
1 2 2 2 2 2 2 2 1 1 1 1 1 1 9 9 9 9 9 9 9 9 9
2 3 3 3 3 3 3 3 3 7 7 7 7 7 7 7 7 7 4 4 4 4
3 4 4 4 4 4 4 4 4 8 8 8 8 8 8 8 8 8 8 8 2
Page * * * * * * * * * *
Hit

Total Page Hit = 10

Total Page Fault/Page Miss = Total Page – Page Hit = 23-10 = 13

Hit Ratio = Page Hit/Total no of Pages = 10/23 = 0.4347

Miss Ratio = Page Fault/Total no of Pages = 13/23 = 0.5652


Q4. Consider a main memory with five page frames and the following sequence of page
references: 3, 8, 2, 3, 9, 1, 6, 3, 8, 9, 3, 6, 2, 1, 3. which one of the following is true with
respect to page replacement policies First-In-First-out (FIFO) and Least Recently Used
(LRU)?

A. Both incur the same number of page faults


B. FIFO incurs 2 more page faults than LRU
C. LRU incurs 2 more page faults than FIFO
D. FIFO incurs 1 more page faults than LRU

Q5. Consider the following page reference string 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1. How


many page faults would occur assuming three frames are made available for FIFO, LRU, and
optimal page replacement algorithm?

Q6. Consider the following page reference string 1,2,3,2,1,5,2,1,6,2,5,6,3,1,3,6,1,2,4,3. How


many page faults would occur assuming three frames are made available for FIFO, LRU, and
optimal page replacement algorithm?

Q7. Consider the following page reference string 5,4,3,2,1,4,3,5,4,3,2,1,5. How many page
faults would occur assuming three frames are made available for FIFO page replacement
algorithm? Would the FIFO page replacement algorithm suffer from Belady’s Anomaly if
number of frames increase from three to four? Justify.

You might also like