operating-systems

Definition

Page Fault

A page fault is a type of exception raised by computer hardware (the MMU) when a process attempts to access a page that is mapped into its virtual address space, but is not currently resident in physical RAM.

Handling Mechanism

When a page fault occurs, the operating system must intervene to bring the required page into memory:

  1. Trap to Kernel: The hardware generates a trap, transferring control to the OS.
  2. Locate Page: The OS determines the location of the required page on secondary storage (disk).
  3. Find Free Frame: The OS searches for an available physical frame. If none are free, it must invoke a replacement policy.
  4. I/O Operation: The page is read from disk into the allocated frame.
  5. Update Page Table: The process’s page table is updated (setting the present bit to 1).
  6. Restart Instruction: The CPU restarts the instruction that caused the fault.

Performance Impact

Frequent page faults can lead to thrashing, where the system spends more time performing I/O than executing user code.