This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc_trim() behaviour


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. 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]