[patch v3] malloc: avoid need for tcache == NULL checks
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Sep 3 10:15:34 GMT 2025
Hi,
> @@ -3510,8 +3550,11 @@ __libc_free (void *mem)
> return malloc_printerr_tail ("free(): invalid pointer");
>
> #if USE_TCACHE
> - if (__glibc_likely (size < mp_.tcache_max_bytes && tcache != NULL))
> + if (__glibc_likely (size < mp_.tcache_max_bytes))
> {
> + if (__glibc_unlikely (tcache_inactive ()))
> + tcache_init (NULL);
> +
Adding calls to the fast path causes significant performance regressions.
Previously we agreed not to initialize tcache on the free path, and instead let
the first malloc initialize tcache. If we want to add initialization, it has to be
a no-inline tailcall and should be placed after the tcache accesses as Florian
points out.
All this complexity is also why we should think of a way to completely get rid
of this initialization. It continues to create performance and correctness issues
only because we want to save ~512 bytes per thread...
Cheers,
Wilco
More information about the Libc-alpha
mailing list