public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nix <nix@esperi.org.uk>
To: "linux-os \(Dick Johnson\)" <linux-os@analogic.com>
Cc: <tachades@cecs.pdx.edu>, <linux-kernel@vger.kernel.org>,
	Wolfram.Gloger@dent.med.uni-muenchen.de
Subject: Re: kernel 2.6.13 - space not freed to kernel
Date: Mon, 05 Sep 2005 10:10:50 +0100	[thread overview]
Message-ID: <87wtlvhobp.fsf@amaterasu.srvr.nix> (raw)
In-Reply-To: <Pine.LNX.4.61.0509021520140.4285@chaos.analogic.com> (linux-os@analogic.com's message of "2 Sep 2005 20:30:03 +0100")

On 2 Sep 2005, linux-os@analogic.com murmured woefully:
> The usual malloc() never resets the break address or remaps memory
> because it is an expensive operation. This means that when new
> data space needs to be allocated, malloc() doesn't have to get
> anything from the kernel because it already has, probably, all
> that it needs.
> 
> The only way memory will be 'returned' is when your program
> calls exit() or otherwise ceases to exist.

This is wrong and has been wrong for a very long time (at least
throughout the glibc2 and libc5 eras).

As the comments at the top of
<http://sourceware.org/cgi-bin/cvsweb.cgi/libc/malloc/malloc.c?rev=1.148&content-type=text/x-cvsweb-markup&cvsroot=glibc>
make clear, and as even the malloc documentation in glibc
says in less detail, glibc malloc() suballocates the brk area
for small chunks only, and shrinks that area when possible;
for large allocations, it uses mmap(). In that situation,
the memory can indeed be freed immediately.

(Why can't malloc allocate suballocatable heaps out of mmap() space? Why
does it use the brk area at all? I hear some of the BSDs are doing this
already, it wouldn't complicate malloc() much that I can see and might
even simplify it in some areas... is it that this would break apps? If
so, those apps are already broken if they're relying on the brk area
being used for allocations, and are definitely far too fragile to
live... I might see if I can modify malloc appropriately and do some
benchmarking.)

-- 
`... published last year in a limited edition... In one of the
 great tragedies of publishing, it was not a limited enough edition
 and so I have read it.' --- James Nicoll

  reply	other threads:[~2005-09-05  9:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-02 19:10 kernel 2.6.13 - space not freed to kernel tachades
2005-09-02 19:29 ` linux-os (Dick Johnson)
2005-09-05  9:10   ` Nix [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-09-02 19:19 tachades

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wtlvhobp.fsf@amaterasu.srvr.nix \
    --to=nix@esperi.org.uk \
    --cc=Wolfram.Gloger@dent.med.uni-muenchen.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-os@analogic.com \
    --cc=tachades@cecs.pdx.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox