A page fault occurs when a process accesses virtual memory that is not
immediately ready for use.
Despite the name, a page fault is often completely normal and expected.
Virtual memory allows a process to behave as though it has large continuous
memory regions. A page fault is part of the mechanism Linux uses to connect
those virtual addresses to real physical memory.
High-Level Idea
Program accesses memory
↓
CPU checks page tables
↓
Page not currently ready
↓
CPU raises page-fault exception
↓
Kernel handles the fault
↓
Memory becomes available
↓
Program continues
Most of the time, the process does not even notice this activity.
The kernel resolves the fault and execution resumes.
What Is a Memory Page?
Linux virtual memory is divided into fixed-size blocks called pages.
On many systems, a page is:
4096 bytes (4 KiB)
The CPU and kernel cooperate to map virtual pages used by a process
onto physical memory pages in RAM.
A process does not directly use physical addresses.
It uses virtual addresses, which are translated by the CPU and kernel.
Why Page Faults Happen
A page fault occurs whenever a process touches memory whose backing page
is not immediately available or fully mapped.
Common Reasons
First access to newly allocated memory
Stack growth
Accessing memory-mapped files
Loading shared libraries
Copy-on-write behavior after fork()
Swapped-out memory returning from disk
Minor vs Major Page Faults
Minor Page Fault
A minor page fault does not require disk access.
The kernel can satisfy the fault using information or pages already
available in memory.
Minor page faults are extremely common and usually normal.
Major Page Fault
A major page fault requires disk or backing-store access.
This is slower because Linux must wait for storage I/O before the page
can be used.
Large numbers of major page faults can severely reduce performance.
Demand Paging
Linux often delays allocating or loading pages until they are actually used.
This behavior is called demand paging.
malloc()
↓
Virtual memory reserved
↓
No actual RAM used yet
↓
Program touches memory
↓
Page fault occurs
↓
Kernel allocates physical page
This is one reason a program may appear to allocate large amounts of memory
without immediately consuming physical RAM.
Copy-on-Write and fork()
After fork(), the parent and child initially share memory pages.
Linux marks those pages as copy-on-write.
fork()
↓
Parent and child share pages
↓
One process modifies page
↓
Page fault occurs
↓
Kernel creates private copy
This allows Linux to avoid immediately copying large memory regions during
process creation.
Copy-on-write is one reason fork() is efficient.
The actual copying is delayed until modification becomes necessary.
Page Fault Handling
When a page fault occurs, the CPU transfers control to the kernel.
The kernel must determine:
Is the address valid?
Does the process have permission?
Does a physical page need allocation?
Must data be loaded from disk?
Is this an illegal access?
Possible Outcomes
Allocate a new page
Load page from storage
Create copy-on-write page
Terminate process with segmentation fault
Segmentation Faults
Not all page faults are recoverable.
If a process accesses invalid memory or violates permissions,
Linux may terminate the process.
Segmentation fault (core dumped)
A segmentation fault is often the visible result of an invalid page fault.
Connection to mmap()
Memory-mapped files often rely heavily on page faults.
Pages from the mapped file are loaded as needed when the process
touches the mapped addresses.
mmap()
↓
Virtual mapping created
↓
No immediate file load
↓
Program accesses mapped memory
↓
Page fault occurs
↓
Kernel loads needed page
Observing Page Faults
Process Fault Counts
ps -o min_flt,maj_flt,cmd -p <PID>
Virtual Memory Statistics
vmstat 1
Per-Process Statistics
cat /proc/<PID>/stat
Memory Maps
cat /proc/<PID>/maps
Relationship to the TLB
Every memory access potentially requires address translation.
The CPU uses the TLB (Translation Lookaside Buffer) to cache recently used
virtual-to-physical translations.
Page faults occur when memory is not ready.
TLB misses occur when address translations are not immediately cached.
That is why the TLB naturally comes next.
Conceptual Summary
Page faults are part of normal Linux virtual memory operation.
They occur when a process accesses memory whose backing page is not
immediately available.
Linux and the CPU cooperate to resolve the fault, map memory,
and continue execution.
Visual Model
See the complete page fault path as a step-by-step diagram.