Return to BSD News archive
Newsgroups: comp.unix.bsd Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!wupost!uunet!mcsun!news.funet.fi!hydra!klaava!torvalds From: torvalds@klaava.Helsinki.FI (Linus Torvalds) Subject: Re: Shared lib benchmarks, and experiences Message-ID: <1992Dec9.233940.5174@klaava.Helsinki.FI> Organization: University of Helsinki References: <1992Dec3.071056.27426@ntuix.ntu.ac.sg> Date: Wed, 9 Dec 1992 23:39:40 GMT Lines: 129 In article <1992Dec3.071056.27426@ntuix.ntu.ac.sg> othman@ntrc25.ntrc.ntu.ac.sg (othman (EEE/Div 4)) writes: > >I've installed Joerg's shared lib with little problem. > >The improvement in code size is significant for small programs but can be >worse for larger programs such as cc1. cc1 using shared lib is actually >larger than static lib, but SysV manual warns of this problem. > There is little hard-disk that I manage to save even after installing >the compressed man pages. > At most 20 megabytes. That is too little but then there is still the >X386 with xview3, which takes up 32Mbyte. No wonder the linux guys refused to >give me figures for comparison. A couple of comments here: - the linux way of doing shared libraries is different from the Joerg type, which seems to follow sysvr4 and SunOS. Under linux, shared binaries are *never* bigger than their unshared counterparts, as linux binaries don't have to contain any linking information at all. It's handled by a jump-table in the shared library image itself. This is one reason I prefer the linux way, although others seem to feel it's less dynamic and thus worse. Linux shared binaries are probably smaller than 386bsd's in all cases due to this. - The reason "the linux guys" "refused" to give you the information you wanted was probably due to nobody caring either due to your attitude or due to the fact that shared libraries under linux are by now the standard thing, and nobody much uses static binaries any more. - did you try X11 binaries? The difference is dramatic. Just to clarify: shared libraries do indeed save *a lot* of disk-space if done right. And it's been tested: the linux rootdisk relies on shared libraries to pack in as many programs as it does into 1.2MB. I didn't find any static binaries on my system (expect for some uninteresting ones like "update" which is dated from last year..), so just to show an example, I made one. The binary in question is the openlook virtual window manager (olvwm), and here are the sizes (both are stripped): # ll olvwm olvwm.static -rwxr-xr-x 1 root root 209920 Dec 5 17:36 olvwm -rwxr-xr-x 1 root root 427012 Dec 10 00:43 olvwm.static As you can see, there is a doubling in size when linking statically, and you can guess which I want to use on my system with 2 40MB harddisks (I'm not kidding you). I'd like to point out that 'olvwm' is not an extreme case: quite the reverse. It was just a binary that I could easily re-link, as I had the object files from a couple of days ago (as can be seen from the dates). With other binaries the savings are usually even more apparent: many X binaries contain mostly X library code when compiled statically, and can shrink to about 5-10% or their static size when recompiled to use shared libraries. Just for fun I just checked my /usr/bin/X11 directory: it contains 75 binaries, of which 21 have the minimal linux binary size of 9220: this is 1kB of binary header, one page of code, and one page of data. They could be shrunk yet more by linking them with the -N flag which packs all the data together, but they haven't (it's not the default gcc option under linux, as it means the binary won't get demand-loaded). Of the rest, 12 or 13 have a size of 13316 (one page more for either code or data), 6 more are yet another page bigger, and only 6 are more than 100kB in size. I'd be willing to bet that that isn't true under 386bsd without shared libraries: X11 binaries without shared libraries have a tendency to be >300kB in size regardless of what they do. Thus the shared libraries mean that I can have a pretty good complement of the standard small X utilities without worrying about disk space. In case somebody wants to actually check the sizes against the 386bsd binaries, here are a couple of examples (more or less randomly picked from the X binaries). I can't say how big the static versions are: I don't have them. -rwxr-xr-x 1 root root 9220 Oct 2 03:58 xclock -rwxr-xr-x 1 root root 13316 Oct 2 04:40 xsetroot -rwxr-xr-x 1 root root 21508 Oct 2 03:40 puzzle -rwxr-xr-x 1 root root 21508 Oct 2 03:56 xcalc -rwxr-xr-x 1 root root 37892 Oct 2 03:36 ico -rwxr-xr-x 1 root root 111620 Oct 2 03:51 twm Feel free to come to your own conclusions. And yes, it's most obvious with X binaries, but it shows clearly even on normal binaries too.. A couple of small examples (yes, here I've used the -N flag to press them under the 9220 mark): -rwxr-xr-x 1 root root 4376 Sep 8 05:35 cat -rwxr-xr-x 1 root root 3888 Nov 9 19:12 printf -rwxr-xr-x 1 root root 3636 Nov 9 19:12 id Note that the above are GNU binaries, not something that I've hacked up to be as small as possible. How big are they with static libs? I don't know, and I'm just as happy that way. > Anyone uses shared-lib for X applications or even server? >I'll do it later but it will help a lot if someone can share with me their >experiences. > However there is some saving in virtual memory size, about 20Kbyte. Right now, running X11 with a couple of clients (3 xterms, xeyes, oclock, xgas), /proc/meminfo gives me (pasted from another xterm): # cat /proc/meminfo total: used: free: shared: buffers: Mem: 15355904 14942208 413696 2629632 6291456 Swap: 5521408 0 5521408 As you can see, out of 15+MB (16MB minus kernel memory) 6MB is used for buffers (it's dynamic, and I put a upper limit of 6MB on it so that it never grows to any more than that). About 9MB is used by user-level binaries: 3.6MB of this the the X-server itself (probably much of it due to the background 1024x768 pixmap of Calvin & Hobbes). And due to page sharing, I have 2.5MB more virtual memory than the amount of memory actually used. Not all of it is shared libraries (the shell binaries are probably sharing normal code pages as well), but most of it probably is. The above aren't doctored numbers: I've seen more than 3MB shared, but I've also seen less. Anyway, for me the disk-space saved is more important. As to the timing checks you made: yes, shared libraries may slow things down. On the other hand, they can also speed things up: less memory used, less need to load in pages from disk etc.. I don't think the speed difference is much of an issue, but I haven't actually tested it at all. Linus