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
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
  • 834
  • 4
  • 9
  • 20
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
  • 281
  • 1
  • 2
  • 5
6
votes
1 answer

How to Disable Copy-on-write and zero filled on demand for mmap()

I am implementing cp(file copy) command using mmap(). For that I mapped the source file in MAP_PRIVATE (As I just want to read)mode and destination file in MAP_SHARED mode(As I have to writeback the changed content of destination file). While doing…
Harish
  • 63
  • 1
  • 4
6
votes
1 answer

major page fault handler in Linux kernel

I am wondering where is the major page fault handler. I wrote an algorithm to minimize page faults in the kernel. So I need to record something whenever a page fault happens. I currently record a page fault happen at do_page_fault(...) in…
Alfred Zhong
  • 6,773
  • 11
  • 47
  • 59
5
votes
1 answer

Why does malloc() cause minor page fault?

I'm trying to learn about memory and page fault, so I wrote the code below to check my understanding. I don't understand why calling malloc caused MINFL to increase since malloc() shouldn't affect physical memory (from what I understand). This is my…
Cabbage
  • 53
  • 1
  • 4
5
votes
5 answers

What may cause page fault at C++ level

I'm a C++ developer and I'm wondering what may cause Page Fault at the C++ level. I've read some articles about Page Fault and I think fork() and malloc/new can cause Page Fault. Are there other reasons which can cause Page Fault? Does an executable…
Yves
  • 11,597
  • 17
  • 83
  • 180
5
votes
2 answers

Disabling Paging in x86 32bit

I am trying to write directly to a physical memory location, so I am using an assembly function to first disable paging, write the value, and then re-enable paging, but for some reason a page fault is still triggered when trying to write the value.…
4
votes
1 answer

Does thread creation trigger page faults in Linux? How does it relate to soft-dirty PTEs?

The reason why I ask this question is that, when testing the behavior of the Linux soft-dirty bit, I found that if I create a thread without touching any memory, the soft-dirty bit of all pages will be set to 1 (dirty). For example, malloc(100MB) in…
4
votes
1 answer

Why Do Page Faults and Unrecoverable Errors Need to be Unmaskable?

Looking for a quick clarification on why unrecoverable errors and page faults must be non-maskable interrupts? What happens when they aren't?
coderboy99
  • 103
  • 8
4
votes
2 answers

Can a page fault handler generate more page faults?

I'm a bit confused about what happens when we're in user-mode and a page fault occurs. IIRC, a page fault will be generated when the TLB is attempting to map my (user-space) virtual address into a physical address and it fails. It then generates…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
4
votes
1 answer

Twice as many page faults when reading from a large malloced array instead of just storing?

I am doing a simple test on monitoring page faults with the code below, What I don't know is how a simple one line of code below doubled my page fault count. if I use ptr[i+4096] = 'A' I got 25,722 page-faults with perf tool, which is what I…
Yunzhou Wu
  • 71
  • 4
4
votes
1 answer

Identifying Major Page Fault cause

I've been asked to look at an internal application written in C++ and running on Linux thats having some difficulties. Periodically it will have a large amount of major page faults (~200k), which cause the wall clock run time to increase by x10+,…
matt
  • 243
  • 1
  • 7
4
votes
1 answer

Why is this piece of code in linux kernel NOT causing dead loop?

I'm reading the linux source code(4.4.45, but should be same in other version) about the page table initialization when booting, and the code below has confused me. Specifically, I'm reading about how the early_level4_pgt is initialized. Here is…
Tgn Yang
  • 330
  • 3
  • 16
4
votes
3 answers

40 million page faults. How to fix this?

I have an application that loads 170 files (let’s say they are text files) from disk in individual objects and kept in memory all the time. The memory is allocated once when I load those files from disk. So, there is no memory fragmentation…
Gabriel
  • 20,797
  • 27
  • 159
  • 293
4
votes
1 answer

Dirty Cache lines and Page eviction

What happens to dirty cache lines which are not yet written back (assuming write-back cache), when the page it is part of is chosen for eviction by the Operating System. In other words what happens to the cache lines of the page, when a page is…
1
2
3
12 13