glibc’s malloc implementation supports ‘malloc_trim()’ call that lets an application program release unused(ie freed memory chunks) back to the system(implementation detail: the data segment of the program is reduced by calling sbrk() with a negative argument). However, this function only works with the main arena. In multithreaded programs, there are multiple arenas that hold freed chunks. Why does this call not release memory from the other arenas as well?
glibc’s malloc implementation supports ‘malloc_trim()’ call that lets an application program release unused(ie freed
Share
Arenas other than the main one are probably allocated from the system using
mmapsosbrkcannot be used to return that memory to the system. It could be possible to make glibc usemremapto shrink these other arenas. Note also thatmalloc_trimcan only return memory at the end of the arena, if there are empty blocks in the middle of the arena there’s no way to release that memory.