[PATCH] malloc: Remove unused tcache code from unsorted bin scan
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu Dec 18 23:06:48 GMT 2025
Hi DJ,
> Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
>> Now that fastbins have been removed, there is no need to add chunks
>> to tcache during an unsorted scan. Small blocks can only be added
>> to unsorted as a result of a remainder chunk split off a larger block,
>
> My memory said "long string of frees" but the comments in malloc.c no
> longer reflect reality. At least, I couldn't find where anything in the
> free chain uses the unsorted bucket like it used to.
Only large blocks are placed in the unsorted bin by free() - the remaining
case is due to splitting off a remainder of a large block. If we stop doing
that (and as discussed before, splitting off tiny fragments from large blocks
increases fragmentation), you never have to scan the unsorted bin for small
blocks since there won't be any!
> How close are we to removing the unsorted bin completely?
There is a benefit in that the unsorted bin contains recently freed blocks
which allows for quick reuse. Another benefit is allowing merges to happen
during a deallocation phase and only sort freed blocks into their free lists
during an allocation phase. The issue was that all blocks, including fast
bins, were all just added to unsorted which meant it could contain many
thousands of blocks. So it's not obvious removing it completely is better
overall.
But now we are close to being able to have completely separate paths for small
and large blocks. That means even simpler code and ability to use better
strategies and optimizations. We could start that split from tcache onwards and
more tightly integrate tcache with smallbins. Improve locality by reserving a
large block to be used for allocating small blocks. Smallbins could use separate
locks to reduce contention and allow for fewer arenas.
Cheers,
Wilco
More information about the Libc-alpha
mailing list