*BSD News Article 86902


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.mel.connect.com.au!news.mel.aone.net.au!grumpy.fl.net.au!news.webspan.net!ix.netcom.com!enews.sgi.com!arclight.uoregon.edu!news.bc.net!nntp.portal.ca!van-bc!n1van.istar!van.istar!west.istar!ott.istar!istar.net!gateway.qnx.com!not-for-mail
From: doug@qnx.com (Doug Santry)
Newsgroups: comp.unix.bsd.freebsd.misc,comp.lang.c,comp.sys.sun.apps
Subject: Re: Alternative malloc ?
Date: 16 Jan 1997 09:01:41 -0500
Organization: QNX Software Systems
Lines: 39
Message-ID: <5blcc5$krn@qnx.com>
References: <5bjh02$j64@chronicle.concentric.net>
NNTP-Posting-Host: qnx.com
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:34126 comp.lang.c:185639 comp.sys.sun.apps:14728

In article <5bjh02$j64@chronicle.concentric.net>,
Daniel Ts'o <dantso@cris.com> wrote:
>	I am running a big program on FreeBSD 2.1. It is 66Mb and wants to 
>grow a bit and malloc is failing. I presume that it is because, as I recall, 
>the behavior of the BSD default malloc is to allocate in powers of two and the 

That is correct.

>next step would be 130Mb, which is bigger than free swap at the moment.

Not sure.  BSD I think over-commits and doesn't care about the size of the
swap.  I think you have outgrown your data segment size of 128M.  You need
to build a kernel with a bigger data segment size for programs.  I *think*
this is the case but am not %100 sure.  Somebody will set me straight
if I'm wrong.  I don't have a access to a FreeBSD machine this exact instant
so cannot verify this for certain by checking the source.

malloc uses sbrk(obreak) which merely extends your address space by the
requested size.  The vm system won't actually allocate a single page of
memory till you reference the new memory.  Basically sbrk simply extends
the valid address range of your process and when you start referencing 
the memory you fault in your new anon pages.

>	Can someone recommend an alternative malloc() that is fast (the 
>program does a lot of malloc() calls, it is an interactive interpreted 
>language), and yet does not have this power of two behavior ?

Well, I have a malloc which does use the power of 2 algorithm except for
requests greater than 16k.  Requests greater than 16k are mmap'ed in as
the exact requested size. 

Another feature of my malloc/free is free actually releases memory back to
the OS, not just the malloc pool of memory for the process.  This is handy
for servers that hang around and exhibit bursty behaviour(from bursts of
requests).

Lemme know if ya want it and I'll email it you.

DJS