[PATCH v2] malloc: move tcache_init out of hot tcache paths
Cupertino Miranda
cupertino.miranda@oracle.com
Tue Apr 15 15:58:03 GMT 2025
Hi Wilco,
On 15-04-2025 16:32, Wilco Dijkstra wrote:
> Hi Cupertino,
>
>> @@ -3433,6 +3434,8 @@ __libc_malloc (size_t bytes)
>>
>> if (tcache_available (tc_idx))
>> return tag_new_usable (tcache_get (tc_idx));
>> + else
>> + MAYBE_INIT_TCACHE ();
>> #endif
>>
>> return __libc_malloc2 (bytes);
>
> It still has this which slows down malloc by adding a call. There is another issue with
> moving tcache initialization earlier: malloc is initialized in __libc_malloc2, so tcache
> will now be initialized before it - however tcache assumes malloc has been initialized
> before it...
Right, I understand better now the benefits of the tailcall.
That move of the call from __libc_malloc2 to __libc_malloc is clearly
wrong. Sorry for that.
>
>> @@ -3474,8 +3477,6 @@ __libc_free (void *mem)
>> }
>> else
>> {
>> - MAYBE_INIT_TCACHE ();
>> -
>
> On latest trunk this has now moved to _int_free_chunk. We could also remove the errno
> save/restore from tcache_init since it's only there because of the above line.
Ok, will update the patch! Thanks for the hint on the errno.
Cheers,
Cupertino
More information about the Libc-alpha
mailing list