From owner-freebsd-stable@FreeBSD.ORG Tue Aug 14 17:37:19 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 36A6816A421; Tue, 14 Aug 2007 17:37:19 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2001:1b20:1:3::1]) by mx1.freebsd.org (Postfix) with ESMTP id A53E313C45E; Tue, 14 Aug 2007 17:37:18 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (cncvkb@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id l7EHbCNX098056; Tue, 14 Aug 2007 19:37:17 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id l7EHbC8b098055; Tue, 14 Aug 2007 19:37:12 +0200 (CEST) (envelope-from olli) Date: Tue, 14 Aug 2007 19:37:12 +0200 (CEST) Message-Id: <200708141737.l7EHbC8b098055@lurza.secnetix.de> From: Oliver Fromme To: freebsd-stable@FreeBSD.ORG, koitsu@FreeBSD.ORG, petefrench@ticketswitch.com In-Reply-To: <20070814164154.GA39532@eos.sc1.parodius.com> X-Newsgroups: list.freebsd-stable User-Agent: tin/1.8.2-20060425 ("Shillay") (UNIX) (FreeBSD/4.11-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Tue, 14 Aug 2007 19:37:17 +0200 (CEST) Cc: Subject: Re: Static linking and memory usage X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-stable@FreeBSD.ORG, koitsu@FreeBSD.ORG, petefrench@ticketswitch.com 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 17:37:19 -0000 Jeremy Chadwick wrote: > 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. Upon a fork() the data and bss segments are also shared, but marked copy-on-write. That is, as soon as the child tries to modify something, a copy of the page is made and assigned to the child process in place of the parent's page. Of course, unrelated processes (i.e. which ave no parent- child relationship) never share data segments. > 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. Are you sure? I _think_ (but I'm not 100% sure) that the mapped text pages of a binary are associated with the vnode of the executable file, but not with a particular process. That means that unrelated processes running from the same binary file (vnode) will share the same text pages in memory. Please, someone correct me if I'm wrong. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "Emacs ist für mich kein Editor. Für mich ist das genau das gleiche, als wenn ich nach einem Fahrrad (für die Sonntagbrötchen) frage und einen pangalaktischen Raumkreuzer mit 10 km Gesamtlänge bekomme. Ich weiß nicht, was ich damit soll." -- Frank Klemm, de.comp.os.unix.discussion