Showing posts with label operating system. Show all posts
Showing posts with label operating system. Show all posts

Saturday, June 29, 2013

When do page fault occur? Describe the actions taken by an OS when a page fault occur?



Any computations and executions take place only when the program is resided in the main memory and it is getting the CPU time. This state of program is referred to as a process. Whenever a process undergoes computations the necessary pages from the auxiliary storage are copied down in the physical memory. At a particular instance of time the process may refer to the page that is not yet   resided in the physical memory but still present in the auxiliary memory, such an unpredictable condition is called a Page Fault. This condition is unpredictable, in perspective with the operating system because the OS cannot determine what type of page reference the process can make once the CPU is allocated to it.
Certain steps and procedure should be carried out by the OS whenever the page fault is generated to make the page available to the process. First step the OS follow is to determine if the page is valid in the auxiliary memory or not. If not certain message are given to the process. But if it is valid then certain calculations are carried out related to the page size and its content. Then certain page in the physical memory is selected which must be replaced by the requesting page, which is done by following certain page replacement algorithms.  Now the OS replaces the requesting page with the existing page in the physical memory and finally updates the page table and register values.

. 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 for the Optimal Page replacement? Remember all frames are Initially empty, so your first unique pages will all cost one fault each.



For Optimal Page replacement algorithm:
:: for 3 page frames
Request
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
Page frame
1*
1
1
1
1
1*
1
1
1
1*
1
3*
3
3
3*
3
3
3
3*
3

2*
2
2
2*
2
2
2
2*
2
2*
2
7*
7
7
2*
2
2*
2
2


3*
4*
4
4
5*
6*
6
6
6
6
6
6*
6
6
1*
1
1
6*
Page fault
No
No
No
no
no
No
No
No
no

:: for 5 page frames
Request
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
Page frame
1*
1
1
1
1
1*
1
1
1
1*
1
1
1
1
1
1
1*
1
1
1

2*
2
2
2*
2
2
2
2*
2
2*
2
2
2
2
2*
2
2*
2
2


3*
3
3
3
3
3
3
3
3
3*
3
3
3*
3
3
3
3
3



4*
4
4
4
6*
6
6
6
6
6
6*
6
6
6
6
6
6






5*
5
5
5
5
5
7*
7
7
7
7
7
7
7
Page fault
No
No
No
no
no
no
no
no
no
no
no
no
No

:: for 7 page frames
Request
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
Page frame
1*
1
1
1
1
1*
1
1
1
1*
1
1
1
1
1
1
1*
1
1
1

2*
2
2
2*
2
2
2
2*
2
2*
2
2
2
2
2*
2
2*
2
2


3*
3
3
3
3
3
3
3
3
3*
3
3
3*
3
3
3
3*
3



4*
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4






5*
5
5
5
5
5
5
5
5
5
5
5
5
5







6*
6
6
6
6
6
6*
6
6
6
6
6
6*












7*
7
7
7
7
7
7
7
Page fault
No
No
no
No
no
no
No
no
no
no
no
no
No

Page Frame
Page fault
3
11
5
7
7
7