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

Wilco Dijkstra Wilco.Dijkstra@arm.com
Mon Sep 29 17:49:06 GMT 2025


Hi Dev,

> The tcache is used for allocation only if an exact match is found. In the
> large tcache code added in commit cbfd7988107b, we currently extract a
> chunk of size greater than or equal to the size we need, but don't check
> strict equality. This patch fixes that behaviour.

Good find!

> Signed-off-by: Dev Jain <dev.jain@arm.com>

You don't need to add this.

> I couldn't get a visible perf improvement on running the largetcache
> versions of the tests in the malloc testsuite, for example,
> ./tst-aligned-alloc-random-malloc-largetcache.

Those are testcases and not suitable as benchmarks. bench-malloc-tcache
can be used to test tcache performance of large blocks if you run it with
GLIBC_TUNABLES=glibc.malloc.tcache_max=65536 and pass a larger size.

It may be interesting to run SPECINT with this setting (or a larger size) to see
whether it has any effect.

>+  e = mangled ? REVEAL_PTR (*entry) : *entry;
>+  if (e == NULL)
>+    return NULL;
>
>+  e_size = chunksize (mem2chunk (e));
>+  if (e_size != nb)
>     return NULL;

Why not write it like:

tcache_entry *e = mangled ? REVEAL_PTR (*entry) : *entry;
if (e == NULL || chunksize (mem2chunk (e)) != nb)
  return NULL;

Cheers,
Wilco


More information about the Libc-alpha mailing list