http://perlmonks.org/?node=Corion asked about measuring memory allocation in IRC but I was reminded of something I've poked at recently which is measuring how much memory is copy-on-write shared between forked mod_perl processes. Thus far, when on Linux the only answer I know of is to use the exmap kernel module. The main page is http://www.berthels.co.uk/exmap/ but Dave Olszewski wrote some bug fixes for it at http://github.com/cxreg/exmap. exmap uses a kernel module to add a new /proc/exmap file. To read physical page stats, write the PID to this file, then read the results. The exmap distribution comes with a C++ and perl GTK program to interpret the kernel data. Below is what I know of the format for the kernel data.
To use:
$ echo $pid > /proc/exmap
$ cat /proc/exmap
VMA 400000 87
1 0 1c6e7
1 0 1c6e8
1 0 1d328
...
$ grep 400000 /proc/$pid/maps
00400000-00457000 r-xp 00000000 08:01 722755 /usr/bin/screen
The sections provided by /proc/exmap correspond to each of the chunks in /proc/$pid/maps. Each line then details a page, whether it is swapped, and whether it is writable.
(
VMA $address $page_count
( $resident $writable $page_id )+
)+
Anyway, just thought I'd share. If you know a better trick, I'd love to hear of it. When I next get around to improving my search servers I'll likely actually try to use this but for now this is just a tool I think I plan to use but haven't done serious work with yet.