Steps taken by operating system to handle a page fault

Here is the sequence of steps which occurs in handling a page fault:

1) Hardware traps to kernel mode.

2) Program counter is saved in stack.

3) Current instruction state is saved in CPU registers.

4) An assembly code program is run to save general registers and other information.

5) Operating system founds that page fault has occurred.

6) It finds a virtual address which caused the page fault by using a hardware register or by using the software.

7) Virtual address is checked to see if it valid. If it is not valid then process is killed.

8) It is also checked to see if a protection fault has occurred.

9) If virtual address is valid and if protection fault has not occurred, then, operating system checks if a frame is free.

10) If there is no frame free, then page replacement algorithm is run.

11) If selected page frame is dirty, page is scheduled for transfer to disk.

12) Context switch happens and the process which caused the fault is suspended and another process is run.

13) Frame is marked as busy.

14) When page frame is clean, then the page is loaded from the disk.

15) When the page has been loaded, page frame is set in normal state.

16) Instruction that caused the fault is set to initial state program counter is reset to point this instruction.

17) Process which caused the fault is scheduled.

18) Operating system runs assembly language program to reload registers and other state information.

19) Control is shifted back to user space for execution.

Leave a Reply