blog dds

2004.12.11

Measuring the Effect of Shared Objects

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 NameTimes Shared
/usr/libexec/ld-elf.so.1165
/usr/lib/libc.so.4164
/usr/lib/libcrypt.so.2112
/usr/lib/libutil.so.3102
/usr/lib/libz.so.294
/usr/lib/libcrypto.so.394
/usr/lib/libssh.so.291
/usr/lib/libmd.so.286
/usr/lib/libwrap.so.385
/usr/lib/libroken.so.583
/usr/lib/libkrb5.so.583
/usr/lib/libcom_err.so.283
/usr/lib/libasn1.so.583
/usr/lib/libpam.so.181
/usr/lib/libopie.so.281
/usr/lib/pam_unix.so80
/usr/lib/pam_skey.so80
/usr/lib/pam_permit.so80
/usr/lib/pam_opie.so80
/usr/lib/pam_krb5.so80
/usr/lib/libskey.so.280
/usr/lib/libgssapi.so.580
/usr/lib/libncurses.so.520
/usr/local/libexec/apache/mod_vhost_alias.so18
/usr/local/libexec/apache/mod_usertrack.so18
/usr/local/libexec/apache/mod_userdir.so18
/usr/local/libexec/apache/mod_unique_id.so18
/usr/local/libexec/apache/mod_status.so18
/usr/local/libexec/apache/mod_speling.so18
/usr/local/libexec/apache/mod_setenvif.so18
/usr/local/libexec/apache/mod_rewrite.so18
/usr/local/libexec/apache/mod_negotiation.so18
/usr/local/libexec/apache/mod_mime_magic.so18
/usr/local/libexec/apache/mod_mime.so18
/usr/local/libexec/apache/mod_log_config.so18
/usr/local/libexec/apache/mod_info.so18
/usr/local/libexec/apache/mod_include.so18
/usr/local/libexec/apache/mod_imap.so18
/usr/local/libexec/apache/mod_headers.so18
/usr/local/libexec/apache/mod_expires.so18
/usr/local/libexec/apache/mod_env.so18
/usr/local/libexec/apache/mod_dir.so18
/usr/local/libexec/apache/mod_digest.so18
/usr/local/libexec/apache/mod_cgi.so18
/usr/local/libexec/apache/mod_cern_meta.so18
/usr/local/libexec/apache/mod_autoindex.so18
/usr/local/libexec/apache/mod_auth_anon.so18
/usr/local/libexec/apache/mod_auth.so18
/usr/local/libexec/apache/mod_asis.so18
/usr/local/libexec/apache/mod_alias.so18
/usr/local/libexec/apache/mod_actions.so18
/usr/local/libexec/apache/mod_access.so18
/usr/local/libexec/apache/libproxy.so18
/usr/lib/libm.so.212
/usr/local/lib/libreadline.so.511
/usr/local/lib/libhistory.so.511
/usr/local/lib/compat/pkg/libmm.so.1110
/usr/lib/compat/libssl.so.210
/usr/lib/compat/libcrypto.so.210
/c/www/apache-modssl/libexec/mod_vhost_alias.so10
/c/www/apache-modssl/libexec/mod_usertrack.so10
/c/www/apache-modssl/libexec/mod_userdir.so10
/c/www/apache-modssl/libexec/mod_unique_id.so10
/c/www/apache-modssl/libexec/mod_status.so10
/c/www/apache-modssl/libexec/mod_speling.so10
/c/www/apache-modssl/libexec/mod_setenvif.so10
/c/www/apache-modssl/libexec/mod_rewrite.so10
/c/www/apache-modssl/libexec/mod_negotiation.so10
/c/www/apache-modssl/libexec/mod_mmap_static.so10
/c/www/apache-modssl/libexec/mod_mime_magic.so10
/c/www/apache-modssl/libexec/mod_mime.so10
/c/www/apache-modssl/libexec/mod_log_config.so10
/c/www/apache-modssl/libexec/mod_info.so10
/c/www/apache-modssl/libexec/mod_include.so10
/c/www/apache-modssl/libexec/mod_imap.so10
/c/www/apache-modssl/libexec/mod_headers.so10
/c/www/apache-modssl/libexec/mod_expires.so10
/c/www/apache-modssl/libexec/mod_env.so10
/c/www/apache-modssl/libexec/mod_dir.so10
/c/www/apache-modssl/libexec/mod_digest.so10
/c/www/apache-modssl/libexec/mod_define.so10
/c/www/apache-modssl/libexec/mod_cgi.so10
/c/www/apache-modssl/libexec/mod_cern_meta.so10
/c/www/apache-modssl/libexec/mod_autoindex.so10
/c/www/apache-modssl/libexec/mod_auth_db.so10
/c/www/apache-modssl/libexec/mod_auth_anon.so10
/c/www/apache-modssl/libexec/mod_auth.so10
/c/www/apache-modssl/libexec/mod_asis.so10
/c/www/apache-modssl/libexec/mod_alias.so10
/c/www/apache-modssl/libexec/mod_actions.so10
/c/www/apache-modssl/libexec/mod_access.so10
/c/www/apache-modssl/libexec/libssl.so10
/c/www/apache-modssl/libexec/libproxy.so10
/usr/local/lib/zsh/libzsh-4.2.1.so7
/usr/local/lib/zsh/4.2.1/zsh/zle.so7
/usr/local/lib/zsh/4.2.1/zsh/complete.so6
/usr/local/lib/zsh/4.2.1/zsh/zutil.so4
/usr/local/lib/zsh/4.2.1/zsh/parameter.so4
/usr/lib/libssl.so.33
/usr/X11R6/lib/libXThrStub.so.62
/usr/X11R6/lib/libXt.so.62
/usr/X11R6/lib/libXmu.so.62
/usr/X11R6/lib/libXext.so.62
/usr/X11R6/lib/libX11.so.62
/usr/X11R6/lib/libSM.so.62
/usr/X11R6/lib/libICE.so.62
/usr/local/lib/zsh/4.2.1/zsh/computil.so2
/usr/local/lib/zsh/4.2.1/zsh/compctl.so2
/usr/X11R6/lib/X11/locale/lib/common/xlcDef.so.21
/usr/X11R6/lib/X11/locale/lib/common/ximcp.so.21
/usr/X11R6/lib/libXrender.so.11
/usr/X11R6/lib/libXpm.so.41
/usr/X11R6/lib/libXcursor.so.11
/usr/X11R6/lib/libXaw.so.71
/usr/X11R6/lib/libXaw.so.61
/usr/local/lib/zsh/4.2.1/zsh/rlimits.so1
/usr/lib/libperl.so.31
/usr/lib/libkvm.so.21
/usr/lib/libipsec.so.11
/usr/lib/libgnuregex.so.21
/usr/lib/libc_r.so.41
/usr/lib/compat/libxpg4.so.21

Read and post comments, or share through   


Creative Commons License Last modified: Saturday, December 11, 2004 9:54 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.