From owner-freebsd-hackers Thu Dec 7 10: 2: 8 2000 From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 7 10:02:05 2000 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from earth.backplane.com (placeholder-dcat-1076843399.broadbandoffice.net [64.47.83.135]) by hub.freebsd.org (Postfix) with ESMTP id D9D6637B401 for ; Thu, 7 Dec 2000 10:01:57 -0800 (PST) Received: (from dillon@localhost) by earth.backplane.com (8.11.1/8.9.3) id eB7I1OF10367; Thu, 7 Dec 2000 10:01:24 -0800 (PST) (envelope-from dillon) Date: Thu, 7 Dec 2000 10:01:24 -0800 (PST) From: Matt Dillon Message-Id: <200012071801.eB7I1OF10367@earth.backplane.com> To: Dag-Erling Smorgrav Cc: remy@boostworks.com, phk@critter.freebsd.dk, freebsd-hackers@FreeBSD.ORG Subject: Re: free() not freing pagedirs pages. References: <200012071200.NAA35634@luxren2.boostworks.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG : :Dag-Erling Smorgrav writes: :> Remy Nonnenmacher writes: :> > Well, I may think using this solution if it remains portable between :> > Unixes. :> It's perfectly portable, with one small variation - on BSD systems, :> you pass -1 instead of a file descriptor, while on SysV systems, you :> pass a descriptor to /dev/zero (or was it /dev/null?) : :FWIW, I just did some tests - mmap()'ing /dev/zero works on FreeBSD as :well, and mapping the same fd multiple times gives you separate areas, :so you don't need a new fd for each. : :DES :-- :Dag-Erling Smorgrav - des@ofug.org There are three ways to use mmap() to allocate memory: #1 MAP_ANON, when supported, should be used. #2 /dev/zero, when supported, should be used (tends to be more portable then MAP_ANON). #3 Create a temporary file, hold the descriptor, remove() the file, ftruncate() to the proper length, then mmap using MAP_PRIVATE. And then you can close the descriptor. This actually takes up *NO* filesystem space, since it's a private map. You can also keep the descriptor around and allocate/free chunks using mmap()/munmap() out of it. Just remember that you have to ftruncate() the file to be big enough to 'hold' your mmap ranges. This tends to be the most portable. Which of the three one uses depends on the OS. -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message