malloc: avoid need for tcache == NULL checks
Florian Weimer
fweimer@redhat.com
Fri Aug 8 06:37:05 GMT 2025
* DJ Delorie:
> @@ -3413,7 +3450,7 @@ __libc_malloc (size_t bytes)
> if (nb < mp_.tcache_max_bytes)
> {
> size_t tc_idx = csize2tidx (nb);
> - if(__glibc_unlikely (tcache == NULL))
> + if(__glibc_unlikely (TCACHE_INACTIVE ()))
> return tcache_malloc_init (bytes);
>
> if (__glibc_likely (tc_idx < TCACHE_SMALL_BINS))
I would have expected for this null check to go away completely and
happen off the fast path, before we replenish tcache. I think the right
place to check for tcache initialization would be here:
/* While we're here, if we see other chunks of the same size,
stash them in the tcache. */
size_t tc_idx = csize2tidx (nb);
if (tcache != NULL && tc_idx < mp_.tcache_small_bins)
{
mchunkptr tc_victim;
Wilco, what do you think about this change? It seems worthwhile to me
to move the null check off the fast path. But it means that off the
fast path, we no longer check against a null pointer, but a data
address.
Thanks,
Florian
More information about the Libc-alpha
mailing list