[PATCH] malloc: Count tcache entries downwards

Cupertino Miranda cupertino.miranda@oracle.com
Fri Apr 11 12:49:07 GMT 2025


Hi Wilco,

On 11-04-2025 11:52, Wilco Dijkstra wrote:
> Hi Cupertino,
> 
>> -      && tcache->counts[tc_idx] > 0)
>> +      && tcache->entries[tc_idx] != NULL)
>> This will not be Ok for the pointer sizzling, which sizzles the entries.
>> Why not check for:
>>     tcache->counts[tc_idx] != 0
Right sorry, then maybe different from the value it should be when empty ?
I mean it should always be better to compare with a constant value. 
Sizzling the entries will make it more complex, I think.

> 
> That checks for tcache not full rather than not empty, so it won't work.
> Pointer swizzling would need an extra swizzle here.
> 
>>> -      if (tcache->counts[tc_idx] < mp_.tcache_count)
>>> +      if (tcache->counts[tc_idx] != 0)
>> You do it here.
> 
> This checks whether tcache is not full.
> 
> There are alternative schemes possible, eg. using combined
> dual counters that can give a zero for both full and empty,
> but those are more complex than this.
> 
> Cheers,
> Wilco

Cheers,
Cupertino


More information about the Libc-alpha mailing list