Professional Documents
Culture Documents
Unit 2 Chap - 3
Unit 2 Chap - 3
Example-
a. Only A in memory
b. Process B is swapped in from hard disk to memory
c. Process C is swapped in from hard disk to memory.
d. A goes in waiting state. So swapped out to hard disk.
e. D swapped in.
f. B goes in waiting state. So swapped out to hard disk.
g. A has come out of waiting state and ready to execute again. So swapped in again to RAM
Characteristics-
1. Variable partitions
2. Number, location and size of partitions vary dynamically.
Memory Compaction-
Swapping creates multiple holes in memory. Combine all holes together to form big one by moving all
the processes downwards.
Page Fault-
No space in physical memory for new page. In order to add new page, one page must be removed
from RAM. Which page must be removed to make room for new page is decided by Page replacement
Algorithms.
Q. 4 Explain optimal page replacement algorithm with example.
1. Replace the page that won’t be needed for longest time in the future.
2. Knowledge of future is required i.e. whole sequence has to be known in advance.
3. Not realizable in practice as algorithm the page on the basis of future use.
4. Has lowest page fault rates.
5. Example- Consider a page sequence as given below-
6. Pages 2,3,4 are initially brought into main memory causing page fault. Next 2 page is to be added,
which is already there in main memory, so page hit.
7. In order to add page 1, replace the page 2 as it is not needed for long time in future.
8. In above case, total page faults= 6, total hits=4
6. Pages 4,7,3 are initially brought into main memory causing page fault.
7. In order to add page0, replace the page 4 as it has come first into the RAM.
8. Next page 7 will be replaced as it is the oldest page in RAM.
9. Total page Faults=11 , total page hits= 1
Q.6 Write a short note on second chance page replacement algorithm
1. It is modification in FIFO.
2. This algorithm uses additional bit called as Reference bit (R). If page in main memory is referenced
again, reference bit is incremented by 1.
3. Before replacing the page, reference bit is checked,
If R=0 ---page is unused and old, replace it
If R=1 ---do not replace the page, a second chance is given to that page
4. After page gets second chance, its reference bit is made zero.
5. Example- Consider the page sequence given below
5. Initially bring page 2 in main memory causing page fault. R=0 for page 2 as it is referenced single
time.
6. Then bring page 3 in main memory causing page fault. R=0 as it is referenced single time.
7. Now page 2 is already in RAM and is referenced again, so make R=1 for page 2.
8. Bring in page 1 with R=0.
9. In order to add 5, page 2 is supposed to be replaced as per FIFO policy. But page 2 has second
chance (R=0), so it cannot be replaced. So page 2 will remain in RAM with R=0. Then page 3 will be
removed as per FIFO policy.
10. Total page faults=7 , total page hits= 5
Q.7 Write a short note on LRU page replacement algorithm.
1. Removes the page that has not been used for longest time.
2. In order to add new page, this algorithm replaces the page that was used far back in past.
3. This algorithm looks backward in time, while optimal algorithm looks forward in time.
4. Example- Consider following sequence-
5. Pages 4,7,3 are initially brought into 3 frames of main memory causing page fault.
6. Next, page 2 is already in memory so it will lead to page hit.
7. In order to add page 1, algorithm checks 3 distinct pages in the past and removes the page that is
far away (i.e. 3rd page). Out of pages 2,4,3 , page 3 is far away in past. So algorithm will remove page 3
and will add page 1 at the place of page 3.
8. Total page faults-8, total page hits- 2
Q.8 Explain clock page replacement algorithm with neat diagram.
1. Similar to second chance page replacement algorithm, only difference here is, frames are arranged
clockwise i.e. in circular manner as shown in diagram below.
2. The hand of clock points to the oldest page.
3. This algorithm uses additional bit called as Reference bit (R). If page in main memory is referenced
again, reference bit is incremented by 1.
4. When page fault occurs, page pointed by hand is inspected.
5. Before replacing the page, reference bit is checked,
If R=0 ---page is unused and old, replace it. Then advance the hand by 1 position.
If R=1 ---do not replace the page, a second chance is given to that page. After page gets
second chance, its reference bit is made zero and then advance the hand by 1 position.
Q.9 Explain NRU page replacement algorithm.
1. Each page has reference bit R and modified bit M.
2. R is set when page is referenced(read/written)
3. M is set when page is modified (i.e. written).
4. Pages are divided into 4 categories-
Class 0- not referenced, not modified
Class 1- not referenced, modified
Class 2- referenced, not modified
Class 3- referenced, modified
5. Removes the page that has not been used recently. Class 0 is of lowest priority while class 3 is of
highest priority.
6. In case of page fault, first replace pages of class 0, then class 1 or class 2.
7. R=1 and M=1 indicates recently used pages.