From owner-freebsd-questions@FreeBSD.ORG Mon Dec 1 23:38:03 2008 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 AB021106564A for ; Mon, 1 Dec 2008 23:38:02 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id 71A058FC08 for ; Mon, 1 Dec 2008 23:38:02 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id mB1Nc0iq009842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 1 Dec 2008 17:38:00 -0600 (CST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id mB1NbwJN009837; Mon, 1 Dec 2008 17:37:58 -0600 (CST) (envelope-from dan) Date: Mon, 1 Dec 2008 17:37:58 -0600 From: Dan Nelson To: Yuri Message-ID: <20081201233758.GD53570@dan.emsphone.com> References: <49345710.9070403@rawbw.com> <874p1njz3l.fsf@kobe.laptop> <49346BD3.5080506@rawbw.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qDbXVdCdHGoSgWSk" Content-Disposition: inline In-Reply-To: <49346BD3.5080506@rawbw.com> X-OS: FreeBSD 7.1-PRERELEASE User-Agent: Mutt/1.5.18 (2008-05-17) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Giorgos Keramidas , freebsd-questions@freebsd.org Subject: Re: Why process memory starts so high up in virtual space with FreeBSD malloc? 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: Mon, 01 Dec 2008 23:38:03 -0000 --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In the last episode (Dec 01), Yuri said: > Giorgos Keramidas wrote: > > The FreeBSD malloc(3) implementation can use either mmap() or > > sbrk() to obtain memory from the system. It does not 'waste a high > > percentage of memory' but it simply maps only high addresses (with > > an unmapped 'hole' in lower addresses). > > But the hole it leaves with MALLOC_OPTIONS='dM' is way larger than > the one left by 'Dm' option. Usually malloc will keep allocating > addresses higher than this initial value and will never come back and > fill some parts of this gap. Therefore "wasting" this space. Have you actually verified that space is wasted? Note that the default for malloc is "DM", which lets malloc use both break- and mmap-based memory. Depending on the libc version, one or the other will be preferred, but both will be used if necessary. Also, unless you have tuned your kernel, you may only be able to allocate 512MB of memory via break() (the kern.maxdsize tunable lets you adjust this). Here's what I get with a simple test program on a month-old 7.1-PRE (before the preference got switched to mmap): $ MALLOC_OPTIONS=Dm ./malloctest Malloced 535822336 bytes. First: 0x8080000, Last: 0x27e80000 $ MALLOC_OPTIONS=dM ./malloctest Malloced 2542796800 bytes. First: 0x28200000, Last: 0xbfa00000 $ MALLOC_OPTIONS=DM ./malloctest Malloced 3078619136 bytes. First: 0x8080000, Last: 0xbfa00000 $ ./malloctest Malloced 3078619136 bytes. First: 0x8080000, Last: 0xbfa00000 So using only break(), I can allocate 511 MB. Using only mmap(), I can allocate 2.36 GB. Using both (the default) I can allocate 2.86 GB. -- Dan Nelson dnelson@allantgroup.com --qDbXVdCdHGoSgWSk--