This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: malloc_trim() behaviour
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Frank Meerkötter <frank dot meerkoetter at basyskom dot com>
- Cc: libc-help at sourceware dot org
- Date: Thu, 14 May 2015 11:41:12 +0200
- Subject: Re: malloc_trim() behaviour
- Authentication-results: sourceware.org; auth=none
- References: <54E50474 dot 2020101 at basyskom dot com>
On Wed, Feb 18, 2015 at 10:30:28PM +0100, Frank Meerkötter wrote:
> Hello,
>
> I've got a question about the actual behaviour of malloc_trim().
>
> man malloc_trim says:
> [...]
> malloc_trim - release free memory from the top of the heap
> [...]
> This function cannot release free memory located at places other than
> the top of the heap.
> [...]
>
> Today I've looked that the implementation of malloc_trim()
> malloc/malloc.c and I am a bit puzzled now as its (as far)
> as I can see not the behaviour described in its man page.
>
> __malloc_trim() calls mtrim which makes use of
> __madvise (paligned_mem, size & ~psm1, MADV_DONTNEED);
>
> My understanding is that madvise(MADV_DONTNEED) would allow
> me to release a range of memory back to the OS. This range
> wouldn't need to be at the top of the heap.
>
> Is the man-page outdated? Am I looking at the wrong place?
> What is the actual behaviour of malloc_trim()?
>
No, manual is correct and current malloc only frees top of heap.
Current allocator is very old and its quite memory intensive.
You should use tcmalloc/jemalloc until somebody rewrites it to decent
allocator.