For the Code Quality book I am writing I wanted to measure the memory savings of shared libraries. On a lightly loaded web server these amounted to 80MB, on a more heavilly loaded shell access machine these ammounted to 300MB.
Here is the Perl script I used for measuring the effect on two FreeBSD systems.
#!/usr/bin/perl
# Map from .so inodes to fnames
open(IN, q{locate .so | grep -v obj | xargs ls -li | grep -v -e '->'|}) || die;
while (<IN>) {
@F = split;
$fname{$F[0]} = $F[9];
}
# Get a list of all shared objects
open(IN, q{fstat -m | grep mmap | sed 's/rw$/ r/' | sort -u|}) || die;
while (<IN>) {
@F = split;
if (defined($fname{$F[5]})) {
$used{$fname{$F[5]}}++;
$size{$fname{$F[5]}} = $F[7];
$unshared += $F[7];
$mmap++;
}
}
for $fname (keys %size) {
$ssize += $size{$fname};
$nobj++;
}
print "$nobj shared objects sharing $ssize bytes of memory with $mmap mappings. Memory required without sharing: $unshared bytes.\n";
Here is a list of the objects shared on the shell access machine, ordered by the number of times each was shared.
File Name | Times Shared |
---|---|
/usr/libexec/ld-elf.so.1 | 165 |
/usr/lib/libc.so.4 | 164 |
/usr/lib/libcrypt.so.2 | 112 |
/usr/lib/libutil.so.3 | 102 |
/usr/lib/libz.so.2 | 94 |
/usr/lib/libcrypto.so.3 | 94 |
/usr/lib/libssh.so.2 | 91 |
/usr/lib/libmd.so.2 | 86 |
/usr/lib/libwrap.so.3 | 85 |
/usr/lib/libroken.so.5 | 83 |
/usr/lib/libkrb5.so.5 | 83 |
/usr/lib/libcom_err.so.2 | 83 |
/usr/lib/libasn1.so.5 | 83 |
/usr/lib/libpam.so.1 | 81 |
/usr/lib/libopie.so.2 | 81 |
/usr/lib/pam_unix.so | 80 |
/usr/lib/pam_skey.so | 80 |
/usr/lib/pam_permit.so | 80 |
/usr/lib/pam_opie.so | 80 |
/usr/lib/pam_krb5.so | 80 |
/usr/lib/libskey.so.2 | 80 |
/usr/lib/libgssapi.so.5 | 80 |
/usr/lib/libncurses.so.5 | 20 |
/usr/local/libexec/apache/mod_vhost_alias.so | 18 |
/usr/local/libexec/apache/mod_usertrack.so | 18 |
/usr/local/libexec/apache/mod_userdir.so | 18 |
/usr/local/libexec/apache/mod_unique_id.so | 18 |
/usr/local/libexec/apache/mod_status.so | 18 |
/usr/local/libexec/apache/mod_speling.so | 18 |
/usr/local/libexec/apache/mod_setenvif.so | 18 |
/usr/local/libexec/apache/mod_rewrite.so | 18 |
/usr/local/libexec/apache/mod_negotiation.so | 18 |
/usr/local/libexec/apache/mod_mime_magic.so | 18 |
/usr/local/libexec/apache/mod_mime.so | 18 |
/usr/local/libexec/apache/mod_log_config.so | 18 |
/usr/local/libexec/apache/mod_info.so | 18 |
/usr/local/libexec/apache/mod_include.so | 18 |
/usr/local/libexec/apache/mod_imap.so | 18 |
/usr/local/libexec/apache/mod_headers.so | 18 |
/usr/local/libexec/apache/mod_expires.so | 18 |
/usr/local/libexec/apache/mod_env.so | 18 |
/usr/local/libexec/apache/mod_dir.so | 18 |
/usr/local/libexec/apache/mod_digest.so | 18 |
/usr/local/libexec/apache/mod_cgi.so | 18 |
/usr/local/libexec/apache/mod_cern_meta.so | 18 |
/usr/local/libexec/apache/mod_autoindex.so | 18 |
/usr/local/libexec/apache/mod_auth_anon.so | 18 |
/usr/local/libexec/apache/mod_auth.so | 18 |
/usr/local/libexec/apache/mod_asis.so | 18 |
/usr/local/libexec/apache/mod_alias.so | 18 |
/usr/local/libexec/apache/mod_actions.so | 18 |
/usr/local/libexec/apache/mod_access.so | 18 |
/usr/local/libexec/apache/libproxy.so | 18 |
/usr/lib/libm.so.2 | 12 |
/usr/local/lib/libreadline.so.5 | 11 |
/usr/local/lib/libhistory.so.5 | 11 |
/usr/local/lib/compat/pkg/libmm.so.11 | 10 |
/usr/lib/compat/libssl.so.2 | 10 |
/usr/lib/compat/libcrypto.so.2 | 10 |
/c/www/apache-modssl/libexec/mod_vhost_alias.so | 10 |
/c/www/apache-modssl/libexec/mod_usertrack.so | 10 |
/c/www/apache-modssl/libexec/mod_userdir.so | 10 |
/c/www/apache-modssl/libexec/mod_unique_id.so | 10 |
/c/www/apache-modssl/libexec/mod_status.so | 10 |
/c/www/apache-modssl/libexec/mod_speling.so | 10 |
/c/www/apache-modssl/libexec/mod_setenvif.so | 10 |
/c/www/apache-modssl/libexec/mod_rewrite.so | 10 |
/c/www/apache-modssl/libexec/mod_negotiation.so | 10 |
/c/www/apache-modssl/libexec/mod_mmap_static.so | 10 |
/c/www/apache-modssl/libexec/mod_mime_magic.so | 10 |
/c/www/apache-modssl/libexec/mod_mime.so | 10 |
/c/www/apache-modssl/libexec/mod_log_config.so | 10 |
/c/www/apache-modssl/libexec/mod_info.so | 10 |
/c/www/apache-modssl/libexec/mod_include.so | 10 |
/c/www/apache-modssl/libexec/mod_imap.so | 10 |
/c/www/apache-modssl/libexec/mod_headers.so | 10 |
/c/www/apache-modssl/libexec/mod_expires.so | 10 |
/c/www/apache-modssl/libexec/mod_env.so | 10 |
/c/www/apache-modssl/libexec/mod_dir.so | 10 |
/c/www/apache-modssl/libexec/mod_digest.so | 10 |
/c/www/apache-modssl/libexec/mod_define.so | 10 |
/c/www/apache-modssl/libexec/mod_cgi.so | 10 |
/c/www/apache-modssl/libexec/mod_cern_meta.so | 10 |
/c/www/apache-modssl/libexec/mod_autoindex.so | 10 |
/c/www/apache-modssl/libexec/mod_auth_db.so | 10 |
/c/www/apache-modssl/libexec/mod_auth_anon.so | 10 |
/c/www/apache-modssl/libexec/mod_auth.so | 10 |
/c/www/apache-modssl/libexec/mod_asis.so | 10 |
/c/www/apache-modssl/libexec/mod_alias.so | 10 |
/c/www/apache-modssl/libexec/mod_actions.so | 10 |
/c/www/apache-modssl/libexec/mod_access.so | 10 |
/c/www/apache-modssl/libexec/libssl.so | 10 |
/c/www/apache-modssl/libexec/libproxy.so | 10 |
/usr/local/lib/zsh/libzsh-4.2.1.so | 7 |
/usr/local/lib/zsh/4.2.1/zsh/zle.so | 7 |
/usr/local/lib/zsh/4.2.1/zsh/complete.so | 6 |
/usr/local/lib/zsh/4.2.1/zsh/zutil.so | 4 |
/usr/local/lib/zsh/4.2.1/zsh/parameter.so | 4 |
/usr/lib/libssl.so.3 | 3 |
/usr/X11R6/lib/libXThrStub.so.6 | 2 |
/usr/X11R6/lib/libXt.so.6 | 2 |
/usr/X11R6/lib/libXmu.so.6 | 2 |
/usr/X11R6/lib/libXext.so.6 | 2 |
/usr/X11R6/lib/libX11.so.6 | 2 |
/usr/X11R6/lib/libSM.so.6 | 2 |
/usr/X11R6/lib/libICE.so.6 | 2 |
/usr/local/lib/zsh/4.2.1/zsh/computil.so | 2 |
/usr/local/lib/zsh/4.2.1/zsh/compctl.so | 2 |
/usr/X11R6/lib/X11/locale/lib/common/xlcDef.so.2 | 1 |
/usr/X11R6/lib/X11/locale/lib/common/ximcp.so.2 | 1 |
/usr/X11R6/lib/libXrender.so.1 | 1 |
/usr/X11R6/lib/libXpm.so.4 | 1 |
/usr/X11R6/lib/libXcursor.so.1 | 1 |
/usr/X11R6/lib/libXaw.so.7 | 1 |
/usr/X11R6/lib/libXaw.so.6 | 1 |
/usr/local/lib/zsh/4.2.1/zsh/rlimits.so | 1 |
/usr/lib/libperl.so.3 | 1 |
/usr/lib/libkvm.so.2 | 1 |
/usr/lib/libipsec.so.1 | 1 |
/usr/lib/libgnuregex.so.2 | 1 |
/usr/lib/libc_r.so.4 | 1 |
/usr/lib/compat/libxpg4.so.2 | 1 |
Last modified: Saturday, December 11, 2004 8:54 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.