Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Aug 2007 09:41:54 -0700
From:      Jeremy Chadwick <koitsu@FreeBSD.org>
To:        Pete French <petefrench@ticketswitch.com>
Cc:        freebsd-stable@FreeBSD.ORG
Subject:   Re: Static linking and memory usage
Message-ID:  <20070814164154.GA39532@eos.sc1.parodius.com>
In-Reply-To: <E1IKxQG-0001oe-3M@dilbert.ticketswitch.com>
References:  <E1IKxQG-0001oe-3M@dilbert.ticketswitch.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 14, 2007 at 03:31:04PM +0100, Pete French wrote:
> If I have an executable which is staticly linked with many copies
> of it running (a CGI script in fact), will all those copies share
> the text segment of the executable on the disc, or will it actually
> use up real memory resource with many copies of the executable ? I
> have been assuming the former, but possibly that is not correct.

How I understand it:

A statically-linked binary contains portions/copies of the text, data,
and bss segments of .a library.  These are part of the actual binary
itself, thus become part of the memory space of the program when run.
Only the text segment gets shared; the data and bss segments, as far as
I know, do not get shared.

With a statically-linked binary, when the binary forks, the text segment
is kept intact between the parent and child -- that is, there is only 1
in-memory copy of that segment.

However, *different parents* will have their own copy of that library in
their memory space.

This reminds me: it sure would be useful if we had something like
Solaris's pmap(1) on FreeBSD.

-- 
| Jeremy Chadwick                                    jdc at parodius.com |
| Parodius Networking                           http://www.parodius.com/ |
| UNIX Systems Administrator                      Mountain View, CA, USA |
| Making life hard for others since 1977.                  PGP: 4BD6C0CB |




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070814164154.GA39532>