[PATCH] malloc: Use correct C11 atomics for fastbin

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Dec 2 10:56:30 GMT 2022


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.

Cheers,
Wilco


More information about the Libc-alpha mailing list