From owner-freebsd-ports@FreeBSD.ORG Sun Oct 7 10:22:19 2007 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 21E9716A41A for ; Sun, 7 Oct 2007 10:22:19 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-20-82.belrs4.nsw.optusnet.com.au [220.239.20.82]) by mx1.freebsd.org (Postfix) with ESMTP id 9ADD913C45A for ; Sun, 7 Oct 2007 10:22:18 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.14.1/8.14.1) with ESMTP id l97ALok1071312; Sun, 7 Oct 2007 20:21:50 +1000 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.14.1/8.14.1/Submit) id l97ALn1s071311; Sun, 7 Oct 2007 20:21:49 +1000 (EST) (envelope-from peter) Date: Sun, 7 Oct 2007 20:21:49 +1000 From: Peter Jeremy To: Diomidis Spinellis Message-ID: <20071007102149.GI67571@turion.vk2pj.dyndns.org> References: <20071004190304.GA9491@hades.panopticon> <20071006150207.GA19775@amilo.cenkes.org> <4707D1E8.5000103@aueb.gr> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline In-Reply-To: <4707D1E8.5000103@aueb.gr> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.16 (2007-06-09) Cc: freebsd-ports@freebsd.org Subject: Re: Idea: static builds X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Oct 2007 10:22:19 -0000 --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2007-Oct-06 21:20:24 +0300, Diomidis Spinellis wrote: >I can give you quantitative data on the benefits of shared objects. On a= =20 >web server running FreeBSD 6.2 I found 98 shared objects sharing 16,790,90= 1=20 >bytes of memory through 1,002 mappings. >Without shared libraries the corresponding binaries would require=20 >198,815,270 bytes - an order of magnitude more. Unfortunately, your perl script is overly simplistic and you have vastly over-estimateed the unshared size. The major inaccuracies are: - Text segments are shared so multiple instances of the same executable=20 (eg shells) all share the one copy of memory. - All of a .so is mapped into every process that references it whereas a statically linked executable will only link in the required bits of the corresponding .a. It's extremely unlikely that any executable uses every function in a library so a static executable will normally be much smaller than the size of the dynamic executable plus all the .so's it maps. - rw mappings are not normally shared The size differences between static and dynamic linking are not clearcut and will depend on the process mix. For a server running multiple copies of a small number of distinct executables, static linking is likely to use less memory (because the unused parts of the libraries are not mapped). For a desktop running a single copy of a variety of different executables - which themselves share large .so's (eg X applications) then shared libraries are a win. >These are not just memory savings, but, more importantly on a modern=20 >system, they contribute to improved locality in the code cache. It's not clear that a random collection of executables that all load a common .so will actually have any code locality benefits. Code locality is a very large can of worms... Since most of this thread has stressed the advantages of dynamic loading, it might be worthwhile pointing out some of the benefits of static linking: - Static executables start faster because there's no RTLD step - On some architectures (eg i386) static executables run faster because PIC code needed in the .so's is less efficient. - It can be easier to secure the fewer inodes associated with a static executable than a dynamic one. To expand on this last point, loading a static /bin/sh accesses 3 inodes. A dynamic /bin/sh on FreeBSD accesses 7 inodes (plus any dynamically loaded .so's). On Solaris, /bin/sh accesses something like 20 inodes. --=20 Peter Jeremy --82I3+IH0IqGh5yIs Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFHCLM9/opHv/APuIcRAvYyAJ9SeJZ1k7EHPfrwURQY0jJ1TJTgUgCgqT4G KeuJluwSqLZp/gfHjxnjMas= =D0QP -----END PGP SIGNATURE----- --82I3+IH0IqGh5yIs--