From owner-freebsd-questions@FreeBSD.ORG Sun Mar 15 16:25:27 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 346341065672 for ; Sun, 15 Mar 2009 16:25:27 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [220.233.188.227]) by mx1.freebsd.org (Postfix) with ESMTP id A2E498FC18 for ; Sun, 15 Mar 2009 16:25:26 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id n2FGOpSD062129; Mon, 16 Mar 2009 03:24:52 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Mon, 16 Mar 2009 03:24:51 +1100 (EST) From: Ian Smith To: cpghost In-Reply-To: <20090315120024.E004210656DB@hub.freebsd.org> Message-ID: <20090316023903.T95588@sola.nimnet.asn.au> References: <20090315120024.E004210656DB@hub.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: Wojciech Puchar , freebsd-questions@freebsd.org Subject: Re: Speeding up exit(2)? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Mar 2009 16:25:27 -0000 On Sun, 15 Mar 2009 11:01:41 +0100 cpghost wrote: > On Sun, Mar 15, 2009 at 10:27:53AM +0100, Wojciech Puchar wrote: > > > Not sure what's really going on there, but apparently, the process > > > reads in pages from swap that have been paged out previously > > > (according to top(1)). > > > > is it your program and you are sure it's on exit? > > Every memory hungry program is concerned; and yes: it happens exactly > on exit. > > > it's because the program is writted the way it's doing a lot of things > > (probably unneeded) on exit. > > Have a look at what happens during exit: > /usr/src/sys/kern/kern_exit.c:exit1() > > especially at the call to vm_waitproc(): > /usr/src/sys/vm/vm_glue.c:vm_waitproc > > which calls vmspace_exitfree(): > /usr/src/sys/vm/vm_map.c:vmspace_exitfree() > > Now, vmspace_exit() and vmspace_exitfree() ultimately call: > /usr/src/sys/vm/vm_map.c:vmspace_dofree() > > It then goes deep into the bowels of vm amd pmap, > and that's the place where the pages are paged in > again (I think). Sounds right. This is easy to demonstrate on a laptop with 160MB RAM, running a bunch of servers + X + KDE, then running Mozilla, then opening about 30 tabs of pages, many of which run vast and buggy javascript .. By this stage mozilla is about 150MB with about 60MB resident, and swap is pushing 200MB. *seriously* paging, just on flipping to another tab. Now close mozilla and watch top while it's shutting down. Go and pour yourself a cuppa, there's no hurry .. Apart from having to close each tab/window, freeing all its resources, bits of the executable itself need to be paged in to do various things, which may need to page out some more. What's amazing is that it can do that for several minutes, coming out unscathed when it finally quits! (extreme example, but a true story from a wild ebay session yesterday :) > > not exit(2) itself Well that just starts that big VM ball rolling, so to speak .. so it's a tad more complex than a program that fills memory (+ swap) then exits. cheers, Ian