[PATCH] malloc: fix large tcache code to check for exact size match

Wilco Dijkstra Wilco.Dijkstra@arm.com
Tue Sep 30 13:49:51 GMT 2025


Hi Dev,

> GLIBC_TUNABLES=glibc.malloc.tcache_max=65536 ./bench-malloc-tcache 2048. There are
> two values for time_per_iteration:
>
> without patch - 7.6, 7.12
> with patch - 7.99, 7.41
>
> so that's a regression; I am not sure if this is the correct benchmark. My patch
> will *not* retrieve from the tcache (which is the fastest path in the malloc code)
> if there is a size mismatch, but will stop fragmentation. I suppose we have to run
> a longer benchmark so that we can see the memory benefits.

I see a 1.7% and 4.5% regression. Getting a block is split across 3 separate functions,
so the compiler is not able to CSE it, and thus it repeats a bunch of instructions.

Since this is off by default, it shouldn't hold up your patch - but we'll need to refactor
these functions before increasing default tcache size.

Cheers,
Wilco


More information about the Libc-alpha mailing list