From owner-freebsd-hackers Fri Mar 21 8:55:28 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6414637B401 for ; Fri, 21 Mar 2003 08:55:25 -0800 (PST) Received: from relay.cigital.com (relay.cigital.com [64.80.176.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id B970B43F85 for ; Fri, 21 Mar 2003 08:55:22 -0800 (PST) (envelope-from bhope@cigital.com) Received: by relay.cigital.com (Postfix, from userid 103) id 6B56ABB9F; Fri, 21 Mar 2003 11:55:22 -0500 (EST) Received: from va-mail.cigital.com (va-mail.cigital.com [10.1.20.12]) by relay.cigital.com (Postfix) with ESMTP id 20048BBA8 for ; Fri, 21 Mar 2003 11:55:21 -0500 (EST) thread-index: AcLvyqiM/xjJTL4vQAO4gNBo4i9cgQ== Received: from va-mail.cigital.com ([10.1.20.12]) by va-mail.cigital.com with Microsoft SMTPSVC(5.0.2195.5329); Fri, 21 Mar 2003 11:55:20 -0500 Received: from cigital.com ([10.1.100.83]) by va-mail.cigital.com with Microsoft SMTPSVC(5.0.2195.5329); Fri, 21 Mar 2003 11:55:20 -0500 Message-ID: <3E7B43F8.6070405@cigital.com> Date: Fri, 21 Mar 2003 11:55:20 -0500 Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 From: "Paco Hope" User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.0.1) Gecko/20021005 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Subject: ld.so and hard links Content-Type: text/plain; format=flowed; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 21 Mar 2003 16:55:20.0848 (UTC) FILETIME=[A8753100:01C2EFCA] X-Spam-Status: No, hits=-49.9 required=5.0 tests=AWL,SPAM_PHRASE_03_05,USER_AGENT,USER_AGENT_MOZILLA_UA, X_ACCEPT_LANG version=2.41 X-Spam-Level: Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi. This is a really specific, technical question (and I think it's=20 fascinating to those of us who don't know the answer) about how the text = (code) segment of a program gets loaded into memory. I'm hoping hackers=20 is the right place for this. If not, please forgive and suggest another=20 venue. Here's my baseline assumption. If I'm wrong here, I'm only going to get=20 wronger as I go: If I have two different programs that both use a shared library,=20 libfoo.so, the system memory maps the object code they need into the=20 processes' address spaces. There's only one copy of libfoo.so in memory, = and the two processes each have handles into it (or maybe just to the=20 pieces of it that they use?). Step 2 of my question. This gets closer to my real query: Ok now consider a hard link (not a symlink) from libfoo.so to libbar.so. = One inode, two directory entries. Consider my two programs again, one=20 linked against libfoo.so and the other linked against libbar.so. When=20 they run, how many copies of the lib{foo,bar}.so object code are in RAM? = My current hypothesis is 1. Isn't it mmapped off the disk? The inode=20 matters, not the file name, right? With me so far? Great. Now consider jail(8). Let's say I have two jail environments (If you=20 think I mean chroot here, go read jail(8), it's not the same. I'm=20 assuming folks on hackers know jail.). To make my first jail, I make a=20 copy of the FreeBSD stuff that my jail needs. To make the second jail, I = create a directory hiearachy, but I *hard link* all the binaries and=20 libraries and stuff to the same inodes that the first jail uses. Is that = clear? Let's pick a specific example: 'ln /jail1/usr/sbin/sshd=20 /jail2/usr/sbin/sshd'. Now, sshd uses /usr/lib/libz.so.2. In my example, = I have (effectively) done 'ln /jail1/usr/lib/libz.so.2=20 /jail2/usr/lib/libz.so.2'. These are not symlinks, so this works across=20 jails. Now I launch both jails. Two sshd processes are running, one in=20 each jail. Now the $64K question: How many instances of, for example, the libz.so.2 = object code are in memory? Did my use of jail(8) make any difference? My = intuition is that only one copy of the code is in memory for the same=20 reason as in step 2 above. This is the real question I am interested in. I'm also interested in a broader question. Consider instantiating many=20 jails this way--say 50 or 100 all hard linked to the same base set of=20 files. Can we characterize in some general hand-waving way how much=20 memory (RAM) I would save doing it this way as opposed to the naive way=20 of 50 or 100 copies of the files? I am assuming that if I have 50 copies = of the files and I run 50 processes in 50 jails, then I will use more=20 RAM than if I had 50 hard links to the same inode and ran 50 processes=20 in 50 jails from that one inode. The naive copy method will use more=20 RAM, but not 50 times more than the hard linking way. Thank you to any who respond. I hope I'm not completely out to lunch on=20 this. Regards, Paco -- Consultant, Cigital, Inc. http://www.cigital.com/ -------------------------------------------------------------------------= --- This electronic message transmission contains information that may be confidential or privileged. The information contained herein is = intended solely for the recipient and use by any other party is not authorized. = If you are not the intended recipient (or otherwise authorized to receive = this message by the intended recipient), any disclosure, copying, = distribution or use of the contents of the information is prohibited. If you have = received this electronic message transmission in error, please contact the sender = by reply email and delete all copies of this message. Cigital, Inc. = accepts no responsibility for any loss or damage resulting directly or indirectly = from the use of this email or its contents. Thank You. -------------------------------------------------------------------------= --- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message