OS Page Fault Handling

When page fault occurs, then there are the following sequence of events happens:

  • The computer hardware traps to kernel saving the program counter on stack.
  • An assembly code routine is started just to save the general registers and some volatile information to keep the OS from destroying it.
  • The OS discovers that the page fault has occurred, and it tries to find that which virtual page is needed.
  • When virtual address that caused the page fault is known, then system simply checks to see if the address is valid or not and protection consistent with access.
  • In case, if selected page frame is dirty, then that page is scheduled for transfer to the disk, and a context switch takes place, suspending the faulting process and letting other to run until the disk transfer has completed. In a event, page frame is marked as busy just to prevent it from being used for other purpose.
  • As soon as page frame is clean, then the OS looks up the disk address where the needed page is, an scheduler a disk operation just to bring it in.
  • When disk interrupt indicates that the page has arrived, then the page tables are updated just to reflect its position, and page frame is marked as being in the normal state.
  • Now the page faulting instruction is just backed up to state it had when it began and the program counter is reset to the point to that instruction.
  • The page faulting process is scheduled, and the OS returns to assembly language routine that called it.
  • Now this routine reloads the registers and other state information and then returns to the user space just to continue the execution, as if no any fault had occurred.

Operating System Online Test

« Previous Tutorial Next Tutorial »

Like/Share Us on Facebook 😋