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
3
votes
1 answer

Restarting instruction after page fault

I'm developing an operating system in C and I'm struggling on paging. I'm testing my kernel heap in a loop by allocating memory and outputting the low level memory allocation output that handles physical and virtual page allocation. When PDE 0,…
Eino T
  • 131
  • 2
  • 10
3
votes
1 answer

Page fault with newlib functions

I've been porting newlib to my very small kernel, and I'm stumped: whenever I include a function that references a system call, my program will page fault on execution. If I call a function that does not reference a system call, like rand(), nothing…
user513638
3
votes
1 answer

First Step in Understanding Paged Virtual Memory: Creating Page Table Entry upon Initial Page Fault

I am trying to understand virtual memory paging. I have the following code snippet that represents the first step in the process. Here search_tbl is called from the main program for each logical address in order to check if the page table already…
moejoe
  • 145
  • 2
  • 11
3
votes
1 answer

Dynamic expansion of the Linux stack

I've noticed the Linux stack starts small and expands with page faults caused by recursion/pushes/vlas up to size getrlimit(RLIMIT_STACK,...), give or take (defaults to 8MiB on my system). Curiously though, if I cause page faults by addressing bytes…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
3
votes
1 answer

`mmap()` manual concurrent prefaulting / paging

I'm trying to fine tune mmap() to perform fast writes or reads (generally not both) of a potentially very large file. The writes and reads will be mostly sequential on one pass and then likely very sparse on future passes. No region of memory needs…
Navneeth
  • 373
  • 3
  • 15
3
votes
2 answers

Calling printk in a simple IRQ handler crashes the kernel

I'm new to kernel programming and I couldn't find enough information to know why this happens. Basically I'm trying to replace the page fault handler in the kernel's IDT with something simple that calls the original handler in the end. I just want…
Awais Chishti
  • 395
  • 2
  • 19
3
votes
2 answers

Maximum number of page faults a read instruction can cause?

A machine-language instruction to load a 32-bit word into a register contains the 32-bit address of the word to be loaded. What is the maximum number of page faults this instruction can cause? (Tanenbaum, OS, Q 44) It looks like no brainer,…
Neer
  • 203
  • 4
  • 13
3
votes
2 answers

How does OS locate contents on disk that have not been loaded into memory when page fault exception is raised?

When a page fault exception is raised because the content CPU is trying to access have not been loaded in to memory, how does the OS locate the missing content on the secondary storage (e.g. hard disk)? Thanks for your explanation in advance. -ivan
3
votes
3 answers

Which (OS X) dtrace probe fires when a page is faulted in from disk?

I'm writing up a document about page faulting and am trying to get some concrete numbers to work with, so I wrote up a simple program that reads 12*1024*1024 bytes of data. Easy: int main() { FILE*in = fopen("data.bin", "rb"); int i; int…
Sniggerfardimungus
  • 11,583
  • 10
  • 52
  • 97
3
votes
0 answers

When a page fault happens in user application, what is current pid when kernel handler this fault

I run a user app simply like this: char *buf = malloc(sizeof(int) * 100000); int *a = (int *)buf; int i = 0; for(; i < 100000; i++) { a[i] = i; } I think it surely triggers page fault since malloc will not alloc a real physical space until we…
procr
  • 583
  • 1
  • 5
  • 14
3
votes
0 answers

Memory mapped files and "soft" page faults. Unavoidable?

I have two applications (processes) running under Windows XP that share data via a memory mapped file. Despite all my efforts to eliminate per iteration memory allocations, I still get about 10 soft page faults per data transfer. I've tried every…
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
3
votes
1 answer

read() system call page fault doesn't depend on file size

I am reading different sized files (1KB - 1GB) using read() in C. But everytime I check the page-faults using perf-stat, it always gives me the same (almost) values. My machine: (fedora 18 on a Virtual Machine, RAM - 1GB, Disk space - 20 GB) uname…
brokenfoot
  • 11,083
  • 10
  • 59
  • 80
3
votes
1 answer

How can I use the vm_operations struct to intercept page faults to a particular set of pages?

I would like to create a kernel module that is when given an id of a process can lookup its task struct and then its memory map. When it finds that it should attach a function that will serve page faults to a particular set of pages (namely the heap…
3
votes
1 answer

Get Process Total Page Faults

Both Task Manager and SysInternals Process Explorer show the total amount of a process's page-fault, but all Performance Counters and WMI objects I found show only Page-Faults per second, Is there a different API or some obscure performance counter…
Quazy
  • 33
  • 2
2
votes
1 answer

How can I use perf to measure page fault time during program execution?

I'm using perf to analyze the performance of a program, and I want to measure the time of page fault events that occur during program execution. However, I can't find an appropriate option or command to do so. I have already tried using perf record…
ray
  • 43
  • 3
1 2
3
12 13