Saturday, April 19, 2014

What is page fault? How FIFO page replacement algorithm works?

Consider the following page trace: 4,3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5
Percentage of page fault that would occur if FIFO page replacement algorithm is used with number of frames for the JOB m = 4 will be                [Paper II June 2012]
(A) 8               
(B) 9
(C) 10            
(D) 12

Answer is C
Read detailed explanation with page fault and FIFO page replacement algorithm. 

What is page fault?
A page fault is the situation arises when running program tries to access the required page in Physical Memory (RAM) but the page is not available in RAM this is called page fault. when page is not available in RAM then operating system tries to find page data from virtual memory and load the page into RAM.
An invalid page fault or page fault error occurs when the operating system cannot find the data in virtual memory. This usually happens when the virtual memory area, that maps virtual addresses to real addresses, becomes corrupt.
The term page fault is a bit misleading as it implies that something went seriously wrong. Although page faults are undesirable – as they result in slow accesses to the hard disk – they are quite common in any operating system that uses virtual memory.
Now, we need to actually solve the problem. The easiest way to do this is to break the problem down into the number of pages. See what happens each time a page is referenced by the program, and at each step see whether a page fault is generated or not. Of course, we want to keep track of what pages are currently in the physical memory (the RAM).
The first four page accesses will result in page faults because the frames are initially empty. After that, if the program tries to access a page that’s already in one of the frames then there’s no problem. But if the page that the program is trying to access is not already in one of the frames then that results in a page fault. In this case, we have to determine which page we want to take out (or ‘swap’) from the RAM, and for that we use the FIFO algorithm.
Below is the explanation of page 4, 3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5 and page frame size is 4.
Page
4
3
2
1
4
3
5
4
3
2
1
5
Sr. No.
1
2
3
4
5
6
7
8
9
10
11
12
1
4
4
4
4
4
4
5
5
5
5
1
1
2

3
3
3
3
3
3
4
4
4
4
5
3


2
2
2
2
2
2
3
3
3
3
4



1
1
1
1
1
1
2
2
2
Buffer of 4 Frame


As per above image we have size of 4 frame.  When operating system trying to access data 4 from physical memory then data is not available in physical memory so data 4 will be as page fault so operating system will search data page in virtual memory and load the frame with data 4, afterward data 3, 2, 1 also be a page fault. At column no. 5 demanding of data 4 which is available in physical memory (RAM) so no page fault, afterwards same as 3 is available in   physical memory.  At column no. 7 demanded of data 5 which is not available in physical memory and we have to follow FIFO page replacement algorithm so data 4 has came first so data 4 will be removed and data 5 will be placed as a page fault because it is not available in physical memory.  Same as all other data pages and procedure will work and at the end we can count grayed area which is demanded but does not available in physical memory and became page fault so total grayed area are 10. So page fault is 10.

No comments:

Post a Comment