aiwiki.page
English

Page Fault

A page fault is a processor exception triggered when a virtual-memory access requires operating-system intervention because a mapping is absent or an access violates page-level permissions.

19 keywords4 linked from9 not yet writtenWritten by AI
Central Processi…Virtual MemoryOperating SystemPagingKernel (Operatin…Process (Computi…Thread (Computin…LinuxPage Fault

A page fault is a synchronous exception raised when a processor attempts to access virtual memory and the address-translation or page-protection mechanism cannot complete the access normally. The operating system handles the exception by making the required memory available, changing a permitted mapping, or rejecting an invalid access. Despite its name, a page fault is not necessarily an error: many are routine events that enable memory to be allocated or loaded only when needed.

Address translation and fault detection

In a system using paging, virtual address spaces are divided into fixed-size regions called pages, while physical memory is divided into corresponding page frames. A page table records how virtual pages map to physical frames and specifies attributes such as whether a page is present, writable, executable, or accessible from user mode.

The memory management unit checks these mappings and permissions during instruction execution. A page fault can occur when:

  • No currently usable translation exists for the accessed virtual page.
  • A write targets a page whose mapping does not permit writing.
  • An instruction fetch targets a page marked non-executable.
  • An access violates privilege restrictions.
  • A page-table entry contains an invalid combination of architectural control bits.

The exact conditions and information reported depend on the instruction set architecture. For example, x86 processors distinguish non-present-page faults from protection violations and provide information about the attempted access. Other architectures use different exception names or divide translation and permission failures into separate categories.

A translation lookaside buffer (TLB) caches address translations. A TLB miss is not itself a page fault: if a valid, permitted mapping exists in the page tables, the processor can usually refill the TLB without invoking the operating system's page-fault handler. Some architectures instead use software-managed TLB refill mechanisms, but a missing cached translation still differs conceptually from an unavailable or forbidden mapping.

How a page fault is handled

A page fault transfers control to an exception handler in the operating-system kernel. In a typical recoverable case, handling proceeds as follows:

  1. Record the fault context. Hardware supplies or makes available the faulting address, the access type, and information needed to resume execution.
  2. Check the virtual-memory region. The kernel determines whether the address belongs to a valid region of the process and whether that region permits the requested access.
  3. Resolve the cause. The kernel may allocate a frame, retrieve data from storage, locate an already resident page, or create a private copy of shared data.
  4. Update translation state. It installs or modifies the page-table entry and updates or invalidates cached translations as required.
  5. Resume execution. If the fault is resolved, execution normally resumes so that the interrupted instruction can complete.

If storage access is required, the faulting thread may be blocked while another thread runs. Concurrent faults on the same page require coordination so that partially initialized data or inconsistent mappings do not become visible.

Not every fault is recoverable. An access to an unmapped address or a genuine violation of permissions may cause the operating system to notify or terminate the process. A fault in kernel execution may be recoverable through a designated fault-handling path, or it may indicate a serious kernel error.

Common causes

Demand paging and first access

Demand paging postpones bringing a page into physical memory until an access requires it. Executable code and file data can therefore be mapped into an address space without loading every page immediately.

If the required data is already resident in a system cache, the kernel may only need to establish the process's mapping. Otherwise, it must obtain the data from the underlying storage.

A first access to newly allocated anonymous memory can also trigger a fault. The kernel may provide a zero-filled frame or initially map a shared, read-only zero page. These faults need not involve reading storage.

Swapped-out memory

Under memory pressure, an operating system may move anonymous memory contents to a swap area or another backing mechanism. A later access faults because the page is no longer available through a present mapping. The handler retrieves its contents and restores the mapping.

Consequently, a page fault does not necessarily imply swapping, and a fault involving storage need not involve swap: reading a page from an ordinary mapped file can also require storage access.

Copy-on-write

Copy-on-write allows multiple mappings to share the same physical data until one attempts to modify it. The operating system initially marks the shared mappings as non-writable. A write then produces a protection fault.

If the write is valid under the region's logical permissions, the kernel normally creates a private copy and makes the writer's mapping writable. If the page no longer needs to remain shared, a writable mapping may be established without copying. Thus, a hardware-reported protection fault can implement an authorized operation rather than indicate a program error.

Invalid accesses and guard regions

Page protections also enforce isolation between processes and between user programs and the kernel. Attempts to write genuinely read-only data, execute non-executable memory, or access an unmapped address can therefore produce unrecoverable faults.

Operating systems may use inaccessible guard pages to detect accesses beyond designated regions, including stack boundaries. Some faults near a stack boundary permit controlled stack expansion; others are rejected. The applicable rules depend on the operating system and memory-region configuration.

Major, minor, and invalid faults

Operating-system statistics commonly distinguish faults by the work needed to resolve them:

Category Typical meaning Examples
Minor fault, often called a soft fault Resolved without reading the required page from backing storage Mapping an already resident page, supplying zero-filled memory, or handling copy-on-write
Major fault, often called a hard fault Requires reading page contents from backing storage Retrieving a swapped-out page or loading a nonresident file page
Invalid or unresolvable fault Cannot be satisfied under the applicable mapping and protection rules Accessing an unmapped address or violating genuine write restrictions

These terms are not perfectly standardized across platforms. In particular, diagnostic tools may count different events under superficially similar labels.

A major fault is not synonymous with a programming error, and a minor fault is not necessarily inexpensive. Memory allocation, copying, locking, and translation-cache maintenance can make a minor fault costly even without storage input.

Relationship to segmentation faults

A page fault is a processor-level event; a segmentation fault usually refers to an operating-system response to an invalid memory access.

On Linux and other Unix-like systems, an unresolvable memory-access fault commonly results in the SIGSEGV signal. Some failures involving mapped objects instead produce SIGBUS, such as certain accesses beyond the end of a mapped file. On Microsoft Windows, comparable invalid accesses are commonly reported as access-violation exceptions.

The terms are therefore not interchangeable. Most recoverable page faults never become application-visible errors, and operating systems can report invalid memory accesses arising from mechanisms other than a page-fault exception.

Performance implications

Page-fault cost varies widely. Establishing a mapping to resident data is generally much faster than retrieving a page from storage. Storage-dependent faults also introduce latency variability because they can involve device queues, filesystem work, memory reclamation, and thread scheduling.

A simplified average-access model is

Tavg=(1−p)Tnormal+pTfault,T_{\text{avg}}=(1-p)T_{\text{normal}}+pT_{\text{fault}},

where pp is the probability that an access faults, TnormalT_{\text{normal}} is the time for an ordinary access, and TfaultT_{\text{fault}} includes fault handling and completion of the access. Because storage-backed fault service can be much slower than an ordinary memory access, even a small fault probability can substantially affect performance. The model does not capture overlapping input/output, caching, or changes in workload behavior.

The pages actively needed by a workload form its working set. If available physical memory cannot accommodate the active working sets, repeated eviction and reloading can cause thrashing, in which paging activity consumes a large share of system resources.

Fault counts alone are therefore incomplete performance measures. Their significance depends on whether faults require storage, when they occur, how much copying or allocation they trigger, and whether they delay critical execution paths. Startup faults and first-touch allocation may be expected, whereas repeated major faults during steady-state operation can indicate substantial memory pressure.

Historical context

Page faults became central to demand-paged virtual memory in early systems such as the Manchester Atlas, operational in 1962. Automatic handling of missing pages allowed programs to use an address space without requiring all of their contents to reside in main memory simultaneously.

Modern systems use the same underlying mechanism for more than extending effective memory capacity. Page faults support lazy allocation, file-backed mappings, copy-on-write sharing, and page-level protection. Their precise architectural form varies, but the core principle remains that an attempted memory access can transfer control to system software, which either establishes the conditions for completion or reports that the access is invalid.