This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
malloc_trim() behaviour
- From: Frank MeerkÃtter <frank dot meerkoetter at basyskom dot com>
- To: libc-help at sourceware dot org
- Date: Wed, 18 Feb 2015 22:30:28 +0100
- Subject: malloc_trim() behaviour
- Authentication-results: sourceware.org; auth=none
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()?
Kind Regards,
Frank