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

Cupertino Miranda cupertino.miranda@oracle.com
Wed Oct 22 10:49:06 GMT 2025


Hi Wilco,

Thanks for the feedback.

On 21-10-2025 3:46 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.
Right, not worth it IMO.

Dev Jain: Do you want to send a new version with that patch instead 
fixed or should I do it.
Either case is good for me, credit for finding the bug is yours and 
should be recognized. ;-)

I will later contribute a test to avoid the same kind of mistakes in the 
future.

Cheers,
Cupertino



More information about the Libc-alpha mailing list