[PATCH] malloc: Move mmap code out of __libc_free hotpath

Wilco Dijkstra Wilco.Dijkstra@arm.com
Mon Mar 24 21:15:44 GMT 2025


Hi Florian,

>> Currently __libc_free checks for a freed mmap chunk in the fast path.
>> Also errno is always saved and restored to preserve it.  Since mmap chunks
>> are larger than the largest tcache chunk, it is safe to delay this and
>> handle tcache, smallbin and medium bin blocks first.  Move saving of errno
>> to cases that actually need it.
>
> I think the “Since mmap chunks are larger than the largest tcache
> chunk” part is not correct.  We can fall back to performing mmap for a
> smallish allocation.  But I think it's still fine to put such chunks
> into tcache.  Maybe add a comment to this effect?

Well assuming minimum page size is 4KB it should not currently be possible
for the smallest mmap chunk to get into tcache. However the available size
of an mmap chunk is different, so it would go wrong unless we make the
chunk layouts compatible (that would be a simplification that removes the
special cases in memsize and musable).

Cheers,
Wilco


More information about the Libc-alpha mailing list