What is Page Fault

Page Fault is an event that occurs when a program tries to access a block of memory that is not currently in physical RAM (could be swapped out). The term page refers to a fixed-length contiguous block of virtual memory.[1]

here's what happens during a page fault:

  1. access a non-resident page: the program tries to access a page that is not present in the physical memory. This might be because
    1. the page has been swapped out to disk to free up physical RAM
    2. the page has not been loaded from disk
  2. trap to the kernel: the CPU's MMU detects that required page is not present, and it generates a page fault interrupt, which traps kernel to handle the fault.
  3. kernel handle the page fault: kernel's page fault handler takes over and determines the cause of the page fault.
  4. page Replacement: if physical memory is full, the kernel might need to select another page to be paged out to make room for the needed page.
  5. resume execution: once the needed page is in physical memory, the process is moved back to the 'runnable' state.

Two types of Page Fault

What Cause Page Fault

How to Check Process's Page Fault

Use ps -eo

ps -eo min_flt,maj_flt,comm

example output:

 MINFL  MAJFL COMMAND
 16210   2985 dockerd
 83674    177 nxserver.bin
  1708    155 safeadmin
  1091      8 whoopsie
    63      0 kerneloops
    63      0 kerneloops
     0      0 iprt-VBoxWQueue
     0      0 iprt-VBoxTscThr
    63      0 vmware-authdlau
   781     13 xdg-desktop-por
  3455      7 xdg-desktop-por
    52      0 bpfilter_umh
  2567    246 fwupd
 13893     30 containerd-shim
 14252     21 containerd-shim
  2573     46 bash
   923      9 docker-init
  2775     90 run.sh

  1. https://medium.com/@boutnaru/linux-memory-management-part-3-page-faults-2c05f07cf924 ↩︎