In paged virtual memory, a process may reference a page that isn’t currently in RAM. The CPU needs to know this page isn’t present so the OS can fetch it from disk.
A page fault occurs when a program accesses a page not loaded in RAM, triggering the OS to fetch the page from disk (swap space) into a free frame.
- CPU accesses a virtual address
- MMU looks up page table, finds page not present (valid bit = 0)
- CPU raises a page fault exception
- OS checks if access is legal, finds free frame
- OS schedules disk read to load page from swap
- Page loaded, update page table, restart instruction
- Minor page fault: page is in memory but not in process’s page table
- Major page fault: page must be loaded from disk (slow!)
- Too many page faults = thrashing (system slow)
- Handled by OS, transparent to process
- Built from: Paging, Page Table
- Builds into: Demand Paging, Thrashing
- Related: Swap Space, Virtual Memory
- Contrasts with: Segmentation (different memory model)
- Invalid access (segfault) raises SIGSEGV, not page fault
- Copy-on-write: page fault used to duplicate pages
- Page fault handling is expensive (disk I/O)