pagein tool

Ulrich Drepper
2007-4-21

The source of the pagein tool is available here. It only supports x86 and x86-64 so far. Building it is trivial, just type make and the make install as root.

Just like any other valgrind-based tool the --tool option of valgrind must be used. E.g.:

$ valgrind --tool=pagein echo hello
==9321== Pagein-1.0, determine page-in order.
==9321== Copyright (C) 2005, 2006, 2007 and GNU GPL'd, by Ulrich Drepper.
==9321== Using LibVEX rev 1658, a library for dynamic binary translation.
==9321== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==9321== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==9321== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==9321== For more details, rerun with: -v
==9321== 
hello
==9321== 

The result of the run is a file named pagein.PID with PID replaced by the process' process ID. In the above case that would be 9321.

The content of the file looks like this:

   0 0x        3000000000 C            0 0x3000000B50: (within /lib64/ld-2.5.so)
   1 0x         7FF000000 D         3320 0x3000000B53: (within /lib64/ld-2.5.so)
   2 0x        3000001000 C        58270 0x3000001080: _dl_start (in /lib64/ld-2.5.so)
   3 0x        3000219000 D       128020 0x30000010AE: _dl_start (in /lib64/ld-2.5.so)
   4 0x        300021A000 D       132170 0x30000010B5: _dl_start (in /lib64/ld-2.5.so)
   5 0x        3000008000 C     10489930 0x3000008B20: _dl_setup_hash (in /lib64/ld-2.5.so)
   6 0x        3000012000 C     13880830 0x3000012CC0: _dl_sysdep_start (in /lib64/ld-2.5.so)
   7 0x        3000013000 C     18091130 0x3000013440: brk (in /lib64/ld-2.5.so)
   8 0x        3000014000 C     19123850 0x3000014020: strlen (in /lib64/ld-2.5.so)
   9 0x        3000002000 C     23772480 0x3000002450: dl_main (in /lib64/ld-2.5.so)
  10 0x        3000009000 C     31508540 0x3000009D10: _dl_new_object (in /lib64/ld-2.5.so)
  11 0x         7FEFFF000 D     33155470 0x30000132B4: __libc_memalign (in /lib64/ld-2.5.so)
  12 0x           4800000 D     36368060 0x3000009DAA: _dl_new_object (in /lib64/ld-2.5.so)
  13 0x        3000003000 C     45583300 0x3000003070: dl_main (in /lib64/ld-2.5.so)
  14 0x        3000004000 C     49145990 0x3000004696: dl_main (in /lib64/ld-2.5.so)
  15 0x        3000007000 C     55539520 0x3000007360: _dl_init_paths (in /lib64/ld-2.5.so)
  16 0x        300000D000 C     75948190 0x300000D7D0: _dl_debug_initialize (in /lib64/ld-2.5.so)
  17 0x            604000 D     79900270 0x3000003261: dl_main (in /lib64/ld-2.5.so)
  18 0x        300000C000 C     88672960 0x300000CCC0: _dl_catch_error (in /lib64/ld-2.5.so)
  19 0x        3000005000 C    104607410 0x3000005290: open_verify (in /lib64/ld-2.5.so)
  20 0x           4801000 D    115800710 0x3000014793: memcpy (in /lib64/ld-2.5.so)
  21 0x        300000A000 C    121946020 0x300000A001: _dl_new_object (in /lib64/ld-2.5.so)
  22 0x        3000006000 C    132708780 0x30000060A7: _dl_map_object_from_fd (in /lib64/ld-2.5.so)
  23 0x           4A02000 D    139481490 0x300000659A: _dl_map_object_from_fd (in /lib64/ld-2.5.so)
  24 0x        300000B000 C    151728630 0x300000B570: _dl_map_object_deps (in /lib64/ld-2.5.so)
  25 0x        300000E000 C    164881910 0x300000E002: _dl_sysdep_read_whole_file (in /lib64/ld-2.5.so)
  26 0x        300000F000 C    183839940 0x300000F440: _dl_next_tls_modid (in /lib64/ld-2.5.so)
  27 0x        3001348000 D    212023730 0x3000014560: memset (in /lib64/ld-2.5.so)
  28 0x           4A1E000 D    265512900 0x3000014560: memset (in /lib64/ld-2.5.so)
  29 0x        3001344000 D    301636060 0x300000A6F5: _dl_relocate_object (in /lib64/ld-2.5.so)
  30 0x        3001347000 D    301750740 0x300000A6F5: _dl_relocate_object (in /lib64/ld-2.5.so)
  31 0x        300101D000 C    340076390 0x300101D8B0: _init (in /lib64/libc-2.5.so)
  32 0x        300134C000 D    341197790 0x300101D911: _init (in /lib64/libc-2.5.so)
  33 0x        300134A000 D    341210400 0x300101D91F: _init (in /lib64/libc-2.5.so)
  34 0x        30010CD000 C    341215860 0x30010CD300: __init_misc (in /lib64/libc-2.5.so)
  35 0x        3001075000 C    341867810 0x30010758A0: rindex (in /lib64/libc-2.5.so)
  36 0x        3001074000 C    342153430 0x3001074D80: index (in /lib64/libc-2.5.so)
  37 0x            400000 C    346380860 0x400F30: (within /bin/echo)
[...]

The first column is just a running counter. The second column (well, the spaces divide it into two columns) is the address of the page which is paged in. The third column is the number of cycles since the first page fault. The fourth column is C for code access and D for data access. The rest of the line is valgrind's attempt to describe the code address which caused the page fault. The address is always correct but the name is not always the right one since this cannot be done in all cases if no debug information is available.

The sequence of functions and variables shown allows one to rearrange code and data to minimize the number of pages which are touched. This is no simple process, it will require in most cases trial and error. At some point maybe the process will be automated.