[PATCH] malloc: Count tcache entries downwards
Carlos O'Donell
carlos@redhat.com
Fri Apr 11 12:22:07 GMT 2025
On 4/11/25 6:52 AM, 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
>
> 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.
... and less complex is better.
The implementation should be simple enough to debug, and obvious to
understand when reading the code.
It may not always easy to keep all the parts straight in your head,
but it should be possible to write top-level documents like:
https://sourceware.org/glibc/wiki/MallocInternals
And keep them updated so anyone using or developing glibc can
understand the top-level heuristics.
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list