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.
169 questions
33
votes
6 answers

Can't understand Belady's anomaly

So Belady's Anomaly states that when using a FIFO page replacement policy, when adding more page space we'll have more page faults. My intuition says that we should less or at most, the same number of page faults as we add more page space. If we…
devoured elysium
  • 90,453
  • 117
  • 313
  • 521
27
votes
2 answers

segmentation fault vs page fault

I was wondering what differences and relations are between segmentation fault and page fault? Does segmentation fault only belong to segmented memory model? Does page fault only belong to paged memory model? If both are yes, since most computer…
Tim
  • 1
  • 122
  • 314
  • 481
15
votes
3 answers

Where does the OS get the needed disk address when page fault happens from?

When a page table entry(PTE) is not marked as valid, it means the data needed is not in memory, but on the disk. So now page fault happens and the OS is responsible to load this page of data from the disk to memory. My question is, how does the OS…
Elrid
  • 161
  • 3
15
votes
4 answers

Calculating number of page faults for 2-d array

I am trying to study for an exam..and I found this example but can't understand how they got the answer. Can anyone explain it please? Question: Consider the two-dimensional array A: int A[][] = new int[100][100]; where A[0][0] is at location…
user1411893
  • 568
  • 2
  • 7
  • 17
15
votes
2 answers

What happens when a mov instruction causes a page fault with interrupts disabled on x86?

I recently encountered an issue in a custom Linux kernel (2.6.31.5, x86) driver where copy_to_user would periodically not copy any bytes to user space. It would return the count of bytes passed to it, indicating that it had not copied anything. …
Edward
  • 478
  • 2
  • 14
10
votes
3 answers

Measure page faults from a c program

I am comparing a few system calls where I read/write from/to memory. Is there any API defined to measure page faults (pages in/out) in C ? I found this library libperfstat.a but it is for AIX, I couldn't find anything for linux. Edit: I am aware of…
brokenfoot
  • 9,630
  • 9
  • 46
  • 71
10
votes
2 answers

Can the Linux kernel use pageable (swappable) memory for its own buffers?

If the answer to the question is NO, why is it not a good idea to do this? Can the kernel not handle and fix page faults that occur in kernel mode? Does the answer change if the code that uses pageable memory only executes as part of the bottom-half…
Mayank
  • 1,186
  • 1
  • 10
  • 19
9
votes
2 answers

stack prefaulting in linux - single or multiple faults needed

In Linux, when process asks for some (virtual) memory from system, it just registered in vma (descriptor of process's virtual memory) but physical page for every virtual is not reserved at time of call. Later, when process will access this page, it…
osgx
  • 80,853
  • 42
  • 303
  • 470
9
votes
1 answer

Linux, will zeroed page pagefault on first read or on first write?

My question is Linux specific and needs understanding of kernel, virtual memory, mmap, pagefaults. I have C program with large static arrays, which will go into bss section (memory, initialized to zero). When program starts, this memory is not…
osgx
  • 80,853
  • 42
  • 303
  • 470
8
votes
1 answer

Delphi + Indy causes high page fault and RAM usage

I experience one weird problem. I use Delphi and Indy to upload and backup some files. It runs just fine on many computers (Win7 64bit, WinXP) . CPU usage is less then 1% and max. 20MB in RAM. But there is one computer (Win 2008 R2) where it is…
smooty86
  • 1,072
  • 7
  • 13
7
votes
1 answer

How can I avoid the huge number of soft page faults generated by my C# .NET app?

I'm profiling a C# .NET WinForms application and i have noticed that it generates millions of soft page faults and keep increasing during the work ... I know that in .NET the number of pages fault that an application generates is usually high, but…
aleroot
  • 66,082
  • 27
  • 164
  • 205
7
votes
2 answers

Does the Meltdown mitigation, in combination with `calloc()`s CoW "lazy allocation", imply a performance hit for calloc()-allocated memory?

So calloc() works by asking the OS for some virtual memory. The OS is working in cahoots with the MMU, and cleverly responds with a virtual memory address which actually maps to a copy-on-write, read-only page full of zeroes. When a program tries to…
7
votes
3 answers

How to identify read or write operations of page fault when using sigaction handler on SIGSEGV?(LINUX)

I use sigaction to handle page fault exception, and the handler function is defind like this: void sigaction_handler(int signum, siginfo_t *info, void *_context) So it's easy to get page fault address by reading info->si_addr. The question is, how…
6
votes
1 answer

What is the Faults column in 'top'?

I'm trying to download Xcode (onto version El Capitan) and it seems to be stuck. When I run 'top', I see a process called 'storedownloadd' and the "STATE" column is alternating between sleeping, stuck,and running. The 'FAULTS' has a quickly…
TPM
  • 704
  • 3
  • 7
  • 18
6
votes
2 answers

Log memory accesses that cause major page faults

Does anyone know how to get the memory accesses (pointers) that cause page faults? I'm interested mostly in the major page faults. A bit of background about what I'm trying to achieve. I have an application with a large memory footprint (a database)…
pol lol
  • 261
  • 1
  • 2
  • 5
1
2 3
11 12