[PATCH] malloc: Use correct C11 atomics for fastbin
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri Dec 2 12:02:21 GMT 2022
Hi Florian,
>> Yes, malloc is blocking but free isn't and accesses the freelist
>> concurrently. It's a really weird design. Splitting the free list
>> into a local one and a shared one would be far better - no atomics
>> when you have the malloc lock, and if the local free list is empty it
>> takes one atomic to copy all shared entries.
>
> The local free list is in the tcache. I think DJ said that removing the
> fastbins still resulted in a performance loss.
>
> The tcache has also the benefit that the chain length is bounded.
That's because tcache has hardly any effect on programs with a high rate
of (de)allocations. It's so small that you usually end up using the fastbin
code anyway. All the singlethreaded optimizations in fastbins are absolutely
essential - that's the code that shows up in profiles.
If we want to make tcache actually work, it will have to support far more
allocations, particularly for smaller sizes.
Cheers,
Wilco
More information about the Libc-alpha
mailing list