[patch v4] malloc: avoid need for tcache == NULL checks
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Mon Sep 22 20:56:53 GMT 2025
Hi,
> Florian Weimer <fweimer@redhat.com> writes:
>>>> +#if USE_TCACHE
>>>
>>> Note we are already in a USE_TCACHE block here...
>>
>> ^^^ DJ, I think you should remove that #if.
>
> Yup, I had already updated my local copy but was waiting for the rest of
> the feedback before sending a v5.
I still have it on my list to benchmark it, but it's busy before the Cauldron...
> We could complete the call and then initialize tcache for the next call.
> But I think we really should IFUNC malloc in total or just the front end
> routines, compile in tcache for __libc_initial only, and put tcache
> directly into the TCB. For !__libc_initial, we don't use tcache at all.
> That avoids a bunch of indirections and data loads.
They don't need to use tcache indeed. But there is a 'thread_arena' which
could be grouped with the tcache one. Basically the idea would be for the
entry points to get the address of the thread-local malloc struct and pass it on.
This is more efficient than accessing multiple thread-local variables in various
malloc functions (even if using initial-exec).
> What's the performance impact of adding IFUNC jumps/calls in every fast
> path?
Since it can be overridden, calls to malloc already go via the PLT. So there
is no cost if you add ifuncs for performance critical entry points. Only static
linked binaries might get extra PLT calls.
Cheers,
Wilco
More information about the Libc-alpha
mailing list