From owner-freebsd-stable@FreeBSD.ORG Tue Aug 14 16:42:00 2007 Return-Path: Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E0BA16A46B for ; Tue, 14 Aug 2007 16:42:00 +0000 (UTC) (envelope-from jdc@parodius.com) Received: from mx01.sc1.parodius.com (mx01.sc1.parodius.com [72.20.106.3]) by mx1.freebsd.org (Postfix) with ESMTP id 151ED13C45D for ; Tue, 14 Aug 2007 16:41:54 +0000 (UTC) (envelope-from jdc@parodius.com) Received: by mx01.sc1.parodius.com (Postfix, from userid 1000) id E2C511CC01C; Tue, 14 Aug 2007 09:41:54 -0700 (PDT) Date: Tue, 14 Aug 2007 09:41:54 -0700 From: Jeremy Chadwick To: Pete French Message-ID: <20070814164154.GA39532@eos.sc1.parodius.com> Mail-Followup-To: Pete French , freebsd-stable@FreeBSD.ORG References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) Cc: freebsd-stable@FreeBSD.ORG Subject: Re: Static linking and memory usage X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Aug 2007 16:42:00 -0000 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 |