malloc: Trim unused arenas on thread exit

Florian Weimer fweimer@redhat.com
Tue Nov 14 12:13:00 GMT 2017


On 11/14/2017 08:20 AM, Siddhesh Poyarekar wrote:
> On Tuesday 14 November 2017 12:43 PM, Florian Weimer wrote:
>> But in these cases, the application will generally use a thread pool, so
>> glibc will not see the thread exit anyway.
> 
> We kinda emulate thread pools with our thread stack cache and arena
> cache; the only thing we don't cache is the actual threads.  If your
> premise is that it is not important enough then the premise will likely
> extend to the utility of this optimization.

Well, I just double-checked, and the optimization completely avoids 
unmap on thread exit, so it is likely still a win.  Unmapping memory can 
be ridiculously expensive, so I can see the argument that we should not 
do that on thread exit.

Maybe I misspoke further up the thread.  What I wanted to suggest was 
consolidation for the current arena on thread exit, and trimming for the 
arena at the start of the free list.  My patch did not implement that, 
but a more aggressive scheme.  It still did not have an impact on RSS, 
which might be a bug somewhere in the allocator.

Thanks,
Florian



More information about the Libc-alpha mailing list