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

Dev Jain dev.jain@arm.com
Thu Oct 23 06:43:40 GMT 2025


On 21/10/25 8:16 pm, Wilco Dijkstra wrote:
> Hi Cupertino,
>
>> Wilco: Would the patch below be a better solution, performance wise?
>> I would assume so, since all those functions would get inline anyway,
>> but maybe I am missing the reason for the performance degradation.
>>      if ((mangled && REVEAL_PTR (*entry) == NULL)
>> -      || (!mangled && *entry == NULL))
>> +      || (!mangled && *entry == NULL)
>> +      || (nb != chunksize (mem2chunk (te))))
>>          return NULL;
> That should be te == NULL || nb != chunksize (mem2chunk (te)).
> With that the optimized difference is 1% rather than 4.5%, which is much
> better. We can still do better but it requires simplifying these functions
> by inlining them into each other.

I also tried doing:

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 3db0f65f37..66f7391104100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3280,6+3280,8@@ tcache_location_large (size_tnb, size_ttc_idx, 
bool*mangled)
*mangled = true;
}
+ if(te != NULL&& chunksize (mem2chunk (te)) != nb)
+ returnNULL;
returntep;

}
But this gives a huge regression, any idea why is that? I thought checking
this condition in tcache_location_large itself should be the fastest.

>
> Cheers,
> Wilco
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251023/797e01a7/attachment.htm>


More information about the Libc-alpha mailing list