Linus on the "cost of a page fault" on x86

1,268 views
Skip to first unread message

Martin Thompson

unread,
May 2, 2014, 7:21:34 AM5/2/14
to mechanica...@googlegroups.com

Dan Eloff

unread,
May 2, 2014, 9:13:52 AM5/2/14
to mechanica...@googlegroups.com
Quite a high cost at a minimum of 1050 cycles per fault, and by default you pay it on all new memory allocated from Linux with mmap. Using huge pages (2MB) you would have 512 fewer page faults. Also MAP_POPULATE can be used to prefault allocated memory, avoiding the cost all together.

Cheers,
Dan

Jan Kotek

unread,
May 5, 2014, 2:44:38 AM5/5/14
to mechanica...@googlegroups.com

Could someone please explain how to measure page fault rate?

I wrote database engine with memory mapped store and this probably plays huge role in performance.

 

Jan

 

On Friday, May 02, 2014 04:21:34 Martin Thompson wrote:

https://plus.google.com/app/basic/stream/z12fybdg3uqeh5nhu04cj1yx1py4xrsb1ps0k

--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Michael Barker

unread,
May 5, 2014, 3:25:14 AM5/5/14
to mechanica...@googlegroups.com
I use ftrace/trace-cmd on linux.  One you have linux debug files system set up (seems to be the default on redhat distros) and installed trace-cmd, as root you can do*:

$ trace-cmd start -p function_graph -l do_page_fault -P <pid>

Then you call look at the results:

$ cat /sys/kernel/debug/tracing/trace_pipe

I wrote a simple Java program that will read from that file and parse out the results.  Each line will have a time stamp, you will just need to group them appropriately to figure out page fault rate.  Ftrace will also report latency to perform the supplied action so that could be useful information as well.

* on some older kernel versions the page fault handler is __do_page_fault.  You can find out the name by grepping for "page_fault" in /sys/kernel/debug/tracing/available_filter_functions.

Mike.

Francis Stephens

unread,
May 6, 2014, 5:16:55 AM5/6/14
to mechanica...@googlegroups.com, dis...@kotek.net
I use the perf command. Running perf version 3.8.13.19 the command

    perf stat <<thing to run here>>

Will give you the number of page faults by default.

I have found it awkward to use perf on java applications though, as they are often executed very indirectly. I am using perf on smallish simple binary executables.

On Monday, 5 May 2014 07:44:38 UTC+1, Jan Kotek wrote:

Could someone please explain how to measure page fault rate?

I wrote database engine with memory mapped store and this probably plays huge role in performance.

 

Jan

 

On Friday, May 02, 2014 04:21:34 Martin Thompson wrote:

https://plus.google.com/app/basic/stream/z12fybdg3uqeh5nhu04cj1yx1py4xrsb1ps0k

--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.

To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.

Michael Barker

unread,
May 6, 2014, 5:41:10 AM5/6/14
to mechanica...@googlegroups.com, dis...@kotek.net
I also find it useful to run against a specific thread rather than the whole JVM process.  If you have a running application you can the get the native thread id from jstack (nid=) and convert it from hex to decimal.  Most of the profiling tools (perf, ftrace, etc.) can attach to a running process.

Mike.


To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.

Jean-Philippe BEMPEL

unread,
May 6, 2014, 7:40:16 AM5/6/14
to mechanica...@googlegroups.com, dis...@kotek.net
To avoid profiling the whole process you can insert Hardware Counters directly where you want to measure (recompiling or using AOP) in Java with overseer library.
You can setup the counters to use Page Faults from the OS (minors as well as majors), and many more.
I cover this subject in the following posts:

Cheers
Jean-Philippe
Reply all
Reply to author
Forward
0 new messages