1. Introduction
In a demand paging system, not all pages of a process are present in memory at all times. When a process attempts to access a page that is not currently loaded in RAM, the operating system must intervene and bring the page into memory.
This event is called a Page Fault, and the procedure used to resolve it is known as Page Fault Handling.
Page fault handling is one of the most important runtime operations in a virtual memory system.
2. What is a Page Fault?
A page fault occurs when a process tries to access a page whose page table entry indicates that the page is not currently present in physical memory.
Definition
A page fault is an exception generated when a referenced page is absent from main memory.
Important Clarification
A page fault is not an error.
It is a normal mechanism used by demand paging systems.
3. Why Page Faults Occur
Page faults occur because:
Only some pages are initially loaded into RAM
Memory is limited
Programs access pages dynamically
Demand paging loads pages only when needed
Example
Process Accesses Page 5
↓
Page 5 Not in RAM
↓
Page Fault Occurs
4. Components Involved in Page Fault Handling
CPU
Generates logical addresses.
MMU
Checks page table entries.
Page Table
Determines whether the page is present.
Operating System
Handles the page fault.
Backing Store
Stores pages currently not present in RAM.
5. Detecting a Page Fault
Each page table entry contains a Valid/Invalid bit.
Valid Bit = 1
Page Present in RAM
Valid Bit = 0
Page Located on Disk
When the MMU finds:
Valid Bit = 0
it generates a page fault trap.
6. Step-by-Step Page Fault Handling
This sequence is extremely important for exams and interviews.
Step 1: CPU Generates Logical Address
The CPU produces a virtual address.
Example:
(Page Number, Offset)
Example:
(Page 7, Offset 120)
7. Step 2: Page Table Lookup
The MMU checks the page table entry corresponding to Page 7.
Suppose:
Valid Bit = 0
This indicates that the page is not present in RAM.
8. Step 3: Trap to Operating System
Since the page is absent, hardware generates a page fault interrupt.
Control transfers to the operating system.
Page Fault
↓
Trap to OS
9. Step 4: Validate Memory Reference
The operating system first determines whether the reference is legal.
Case A: Illegal Reference
The process attempted to access an invalid address.
Result:
Terminate Process
Example:
Segmentation fault
Invalid pointer access
Case B: Legal Reference
The page simply isn't loaded yet.
Continue handling the page fault.
10. Step 5: Locate Page on Disk
The operating system searches the backing store.
Page Number
↓
Disk Location
The required page is identified.
11. Step 6: Find a Free Frame
The operating system now needs space in RAM.
Two possibilities exist.
Case A: Free Frame Available
A free frame exists.
Free Frame Found
↓
Use Frame
The page can be loaded immediately.
Case B: No Free Frame Available
Memory is full.
A page replacement algorithm must select a victim page.
Victim Page Selected
↓
Remove Victim
↓
Free Frame Created
12. Handling Modified Pages
Before replacing a page, the operating system checks the Dirty Bit.
Dirty Bit = 1
Page has been modified.
Write Page Back to Disk
↓
Replace Page
Dirty Bit = 0
Page unchanged.
Discard Page
↓
Replace Directly
13. Step 7: Load Page into Memory
The required page is transferred from disk to RAM.
Disk
↓
RAM Frame
This is usually the most time-consuming part.
14. Step 8: Update Page Table
The page table entry is updated.
Changes include:
Frame Number
Valid Bit
Status Information
Example:
| Page | Frame | Valid |
|---|---|---|
| 7 | 12 | 1 |
The page is now officially present in memory.
15. Step 9: Restart Instruction
The instruction that caused the fault is restarted.
Page Loaded
↓
Instruction Re-executed
↓
Continue Execution
The process proceeds normally.
16. Complete Page Fault Handling Flow
CPU References Page
↓
Page Table Lookup
↓
Valid Bit = 0
↓
Page Fault
↓
Trap to Operating System
↓
Check Validity
↓
Locate Page on Disk
↓
Find Free Frame
↓
Load Page into RAM
↓
Update Page Table
↓
Restart Instruction
↓
Continue Execution
17. Types of Page Faults
17.1 Minor Page Fault
The page is already available in memory but not properly mapped.
Characteristics:
No disk access required
Fast handling
Example
Page Exists
↓
Mapping Missing
↓
Update Mapping
18. Major Page Fault
The required page is absent from RAM and must be fetched from disk.
Characteristics:
Requires disk I/O
High latency
Example
Page on Disk
↓
Load into RAM
↓
Resume Execution
19. Invalid Page Fault
Occurs when a process attempts to access an illegal address.
Examples:
Accessing memory outside address space
Dereferencing invalid pointers
Result:
Process Terminated
20. Page Replacement During Fault Handling
If memory is full:
The operating system must remove an existing page.
This leads to page replacement algorithms such as:
FIFO
LRU
Optimal
Second Chance
Clock Algorithm
These determine the victim page.
21. Time Components of a Page Fault
Page fault service time includes:
Trap Handling
Transfer control to OS.
Validity Checking
Verify legal access.
Disk Search
Locate required page.
Page Transfer
Move page from disk to RAM.
Page Table Update
Modify mappings.
Instruction Restart
Resume execution.
22. Why Page Faults Are Expensive
Normal memory access:
≈ 100 ns
Page fault handling:
Several Milliseconds
Comparison:
Memory Access
↓
Nanoseconds
Page Fault
↓
Milliseconds
A page fault can be millions of times slower than a normal memory access.
23. Effective Access Time (EAT)
Average memory access time depends on page fault rate.
Where:
p = Page Fault Rate
MAT = Memory Access Time
PF_Time = Page Fault Service Time
Key Insight
Even a very small increase in page fault rate can dramatically reduce system performance.
24. Example of Performance Impact
Suppose:
Memory Access Time = 100 ns
Page Fault Time = 8 ms
Since:
8 ms = 8,000,000 ns
A single page fault costs roughly:
80,000 Normal Memory Accesses
or more.
25. Advantages of Page Fault Handling
Supports Demand Paging
Only required pages are loaded.
Efficient Memory Usage
Inactive pages remain on disk.
Enables Virtual Memory
Programs larger than RAM can execute.
Improves Multiprogramming
More processes can coexist.
26. Disadvantages
High Latency
Disk access is slow.
Increased Complexity
Requires sophisticated OS support.
Context Switching Overhead
Fault handling interrupts execution.
Thrashing Risk
Too many page faults can severely degrade performance.
27. Real-World Analogy
Imagine reading a book.
While reading Chapter 5:
Required Page Missing
You must:
Go to Library
↓
Find Page
↓
Bring It Back
↓
Continue Reading
The interruption is costly but allows you to keep only a few pages with you at a time.
Most Important Point
A page fault is a normal event in demand paging systems where the operating system loads a required page from disk into memory and then resumes execution.