[PATCH] malloc: Use correct C11 atomics for fastbin
Florian Weimer
fweimer@redhat.com
Fri Dec 2 11:24:14 GMT 2022
* Wilco Dijkstra:
> Hi,
>
>>> Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org> writes:
>>>> +/* Atomically pop from the fastbin list. The arena lock must be held to
>>>> + block other threads removing entries, avoiding the ABA issue. */
>>>
>>> If the arena lock must be held anyway, why go through the compare and
>>> exchange overhead? We know we're the only thread accessing it.
>>
>> Other threads are adding entries without the arena lock.
>
> 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.
Thanks,
Florian
More information about the Libc-alpha
mailing list