Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jul 1999 14:52:55 -0400
From:      "Kelly Yancey" <kbyanc@alcnet.com>
To:        "Dag-Erling Smorgrav" <des@flood.ping.uio.no>
Cc:        <freebsd-hackers@freebsd.org>
Subject:   RE: Overcommit and calloc()
Message-ID:  <002201bed217$e94beae0$291c453f@kbyanc.alcnet.com>
In-Reply-To: <xzpyagclhl8.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help

> -----Original Message-----
> From: Dag-Erling Smorgrav [mailto:des@flood.ping.uio.no]
> Sent: Monday, July 19, 1999 12:39 PM
> To: Kelly Yancey
> Cc: Dag-Erling Smorgrav; freebsd-hackers@freebsd.org
> Subject: Re: Overcommit and calloc()
>
>
> "Kelly Yancey" <kbyanc@alcnet.com> writes:
> >   Ahh...but wouldn't the bzero() touch all of the memory just allocated
> > functionally making it non-overcommit?
>
> No. If it were an "non-overcomitting malloc", it would return NULL and
> set errno to ENOMEM, instead of dumping core.
>

  I guess I was looking at it from the commitment of memory point-of-view.
Calloc() calls malloc() to get the memory (which will overcommit); calloc()
then touches every page of the memory using bzero(). The memory itself will
be committed. The only aspect of non-overcommit that it doesn't do is kindly
tell the process if it couldn't touch every page, instead the overcommit
model kills a process to reclaim pages so the bzero() will succeed (assuming
we're not the unfortunate process :) ).
  You are absolutely right, calloc() doesn't act like a non-overcommit
calloc() would, but it does in fact commit the memory.

  I don't know how many programs make use of calloc() but would not a more
efficient algorithm be to better integrate it with malloc() such that if
there is a fragment on the heap which can be used, bzero() it and return
that, otherwise, simply call sbrk() and return that (since it is already
zero'ed). Currently, in the event that malloc() simply returns newly
sbrk()'ed memory, we unnecessarily zero it again.
  And yes, if the majority of people think this is worthwhile and I'm not
just complete wrong here, then I'm glad to submit the patches.

  Kelly
 ~kbyanc@posi.net~
  FreeBSD - The Power To Serve - http://www.freebsd.org/
  Join Team FreeBSD - http://www.posi.net/freebsd/Team-FreeBSD




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?002201bed217$e94beae0$291c453f>