Questions tagged [page-fault]

An interrupt that occurs when a program requests data that is not currently in main memory. The interrupt triggers the operating system to fetch the data from a virtual memory and load it into RAM.

A page fault (sometimes #pf or pf) is a trap to the software raised by the hardware when a program accesses a page that is mapped in the virtual address space, but not loaded in physical memory. In the typical case the operating system tries to handle the page fault by making the required page accessible at a location in physical memory or terminates the program in the case of an illegal access. The hardware that detects a page fault is the memory management unit in a processor. The exception handling software that handles the page fault is generally part of the operating system. -- source wikipedia.

Types of page-faults:

MINOR: If the page is loaded in memory at the time the fault is generated, but is not marked in the memory management unit as being loaded in memory, then it is called a minor or soft page fault.

MAJOR: This is the mechanism used by an operating system to increase the amount of program memory available on demand. The operating system delays loading parts of the program from disk until the program attempts to use it and the page fault is generated. If the page is not loaded in memory at the time of the fault, then it is called a major or hard page fault.

INVALID: If a page fault occurs for a reference to an address that is not part of the virtual address space, meaning there cannot be a page in memory corresponding to it, then it is called an invalid page fault. --source wikipedia

Handling illegal accesses and invalid page faults:

  • If the program receiving the error does not handle it, the operating system performs a default action, typically involving the termination of the running process that caused the error condition, and notifying the user that the program has malfunctioned.

  • Page faults, by their very nature, degrade the performance of a program or operating system and in the degenerate case can cause thrashing. Optimization of programs and the operating system that reduce the number of page faults improve the performance of the program or even the entire system.
187 questions
2
votes
2 answers

Operator new behaves differently in Debug mode than in Release mode in MSVC

While testing some things regarding page faults I discovered a curious difference between how new operates in Debug mode and Release mode in MSVC. Consider the following code1: #include constexpr size_t PAGE_SIZE = 4096; int main() { …
janekb04
  • 4,304
  • 2
  • 20
  • 51
2
votes
1 answer

Why would a device driver cause page faults?

I have a Windows console application that uses a parallel IO card for high speed data transmission. (General Standards HPDI32ALT) My process is running in user mode, however, I am sure somewhere behind the device's API there is some kernel mode…
JeffV
  • 52,985
  • 32
  • 103
  • 124
2
votes
3 answers

Getting External Exception C0000006 in D2006 app - how can I force delphi to load the whole executable?

I get this occasionally when exiting my app - my app is running the EXE over a network. I understand it's a page fault when part of the EXE is loaded on demand. I have also observed it in the OnDrawCell method of a TDrawGrid, so I'm mystified how…
rossmcm
  • 5,493
  • 10
  • 55
  • 118
2
votes
1 answer

Can Intel processors delay TLB invalidations?

This in reference to InteI's Software Developer’s Manual (Order Number: 325384-039US May 2011), the section 4.10.4.4 "Delayed Invalidation" describes a potential delay in invalidation of TLB entries which can cause unpredictable results while…
Nitin Kunal
  • 565
  • 5
  • 7
2
votes
1 answer

What cause kernel to eat CPU on page_fault?

hw/os: linux 4.9, 64G RAM. 16 daemons running. Each reading random short (100 bytes) pieces of 5GiB file accessing it as a memory mapped via mmap() at daemon startup. Each daemon reads its own file, so 16 5GiB files total. Each daemon making maybe…
pavelkolodin
  • 2,859
  • 3
  • 31
  • 74
2
votes
1 answer

Profiling resident memory usage and many page faults in C++ program on linux

I am trying to figure out why my resident memory for one version of a program ("new") is much higher (5x) than another version of the same program ("baseline"). The program is running on a Linux cluster with E5-2698 v3 CPUs and written in C++. The…
Kulluk007
  • 902
  • 2
  • 10
  • 24
2
votes
0 answers

On MacOS, how can I track which pages have been loaded into memory?

It seems that on Linux there's userfaultfd and other tools, but what is there for MacOS?
meisel
  • 2,151
  • 2
  • 21
  • 38
2
votes
0 answers

Why does Python calculation with very large numbers sometimes cause excessive page faults?

This shows up in Process Explorer where I am running Python scripts related to the Collatz conjecture. To avoid distraction by the complexity of these scripts, I have created this minimal script to demonstrate the problem:- import time import…
user258279
  • 371
  • 4
  • 12
2
votes
0 answers

Record major-faults caused by read from regular files

As far as I understand when reading from a file descriptor kernel has to map the file into main memory and only then copy the region into the supplied buffer. It means the reading from a file that is not already in cache should cause major page…
Some Name
  • 8,555
  • 5
  • 27
  • 77
2
votes
0 answers

How do_async_page_fault is called?

I was looking into linux internals of how interrupts are handled by kernel. I couldn't find the way do_async_page_fault api is called. As far as my understanding goes, this is stored as function pointer and called when interrupt occurs. can you…
2
votes
0 answers

Getting wrong count of number of page faults

I am trying to calculate number of page faults while reading a file of size 1kB to 1GB using C program on Linux. I am using below mentioned steps: I created a dummy file using dd if=/dev/zero of=file1.txt count=1024 bs=1024 I flushed the…
2
votes
1 answer

Is Linux perf imprecise for page fault and tlb miss?

I wrote a simple program to test page faults and tlb miss with perf. The code is as follow. It writes 1 GB data sequentially and is expected to trigger 1GB/4KB=256K tlb misses and page faults. #include #include #define STEP…
Waker Leo
  • 129
  • 1
  • 5
2
votes
1 answer

How to measure minor page fault cost?

I want to verify transparent huge page(THP) would cause large page fault latency, because Linux must zero pages before returning them to user. THP is 512x larger than 4KB pages, thus slower to clear. When memory is fragmented, the OS often compact…
buweilv
  • 451
  • 1
  • 4
  • 18
2
votes
0 answers

How to make mprotect() to make forward progress after handling pagefaulte exception?

I wan to intercept all memory references to a specific memory block in my application using mprotect(), so I slightly modified the mprotect sample code found here. When I ran the modified code, however, the application would not make a forward…
Zaid Alali
  • 69
  • 1
  • 4
2
votes
1 answer

Page fault count within two arrays?

Homework: Consider the two-dimensional array A: int A[][] = new int[200][200]; where A[0][0] is at location 500 in a paged memory system with pages of size 500 (a little unrealistic -- not 512). A small process that manipulates the matrix…
user427390