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) and I want to correlate paging with the accesses to the large data structures (such as tables, indexes which are allocated using mmap()). The mappings of the process are easy to retrieve from /proc//maps. Now, if I have the memory accesses that cause page faults I can track how many page faults are caused when accessing each data structure.
I think perf or systemtap could do the job. Any ideas?
Page faults are generated when an application tries to use memory that is part of its working set, but can't find it. Page faults can be either hard or soft: Hard page faults occur when the page is found in the page file on the hard disk. Soft page faults happen when the page is found somewhere else in memory.
Most page faults happen when a program attempts to access information that has been placed into the virtual memory file on the hard drive. This is a normal function of virtual memory, and the computer will respond by loading the appropriate information into physical memory.
A major page fault is an exception that occurs when a process attempts to access memory in a way that exceeds its permissions. For example, if the program attempts to access data from an unmapped region of physical memory, or if it writes beyond the end of allocated virtual address space, a major page fault occurs.
In computing, a page fault (sometimes called PF or hard fault) is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space.
A minor fault means the page is in memory but not allocated to the requesting process or not marked as present in the memory management unit. A major fault means the page in no longer in memory.
See what is available at the probe point:
% stap -L vm.pagefault
vm.pagefault name:string write_access:long address:long $mm:struct mm_struct* \
$vma:struct vm_area_struct* $address:long unsigned int $flags:unsigned int
Log, attempting to map addresses to symbol names
# stap -e 'probe vm.pagefault { if (execname()=="foo") { printf("%p (%s)\n", address, usymdata(address)) } }' -d /bin/foo --ldd
See also: http://sourceware.org/systemtap/examples/#memory/pfaults.stp
Your guess is right. You can use perf tool to track the number of page faults that your application has caused.
I recommend you to read this tutorial to learn to use the tool.
To install just use:
You are looking for the event page-fault. You can install (in ubuntu or other apt distribution) by:
sudo apt-get install linux-tools-common linux-base
sudo apt-get install linux-tools-YOUR-KERNEL number
You can obtain your kernel number with: uname -r
As an example, this command runs the perf tool on the "ls" command:
perf record -e page-faults:u -F 250 ls
and then you can look at the results (the binary of "ls" has no debug information, so don't expect a pretty output) with:
perf report
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With