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:
- access a non-resident page: the program tries to access a page that is not present in the physical memory. This might be because
- the page has been swapped out to disk to free up physical RAM
- the page has not been loaded from disk
- 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.
- kernel handle the page fault: kernel's page fault handler takes over and determines the cause of the page fault.
- 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.
- resume execution: once the needed page is in physical memory, the process is moved back to the 'runnable' state.
Two types of Page Fault
- Minor Page Fault: this occurs when the page is not in the current process's working set but is still resident somewhere in physical memory.
- Major Page Fault: this occurs when the page is not in physical memory at all and needs to be read from disk, which involves I/O.
What Cause Page Fault
- When very first time access the memory
- copy on write
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