]> git.ipfire.org Git - thirdparty/glibc.git/commit
malloc: add tcache support for large chunk caching
authorCupertino Miranda <cupertino.miranda@oracle.com>
Fri, 13 Jun 2025 15:29:59 +0000 (15:29 +0000)
committerWilco Dijkstra <wilco.dijkstra@arm.com>
Mon, 16 Jun 2025 12:05:22 +0000 (12:05 +0000)
commitcbfd7988107b27b9ff1d0b57fa2c8f13a932e508
tree493012f5326272060e5b6db2ce237ffafa0df2c8
parent5b7c8d1cd44048d6fbf10ad80e0d94dd90848a0d
malloc: add tcache support for large chunk caching

Existing tcache implementation in glibc seems to focus in caching
smaller data size allocations, limiting the size of the allocation to
1KB.

This patch changes tcache implementation to allow to cache any chunk
size allocations.  The implementation adds extra bins (linked-lists)
which store chunks with different ranges of allocation sizes. Bin
selection is done in multiples in powers of 2 and chunks are inserted in
growing size ordering within the bin.  The last bin contains all other
sizes of allocations.

This patch although by default preserves the same implementation,
limitting caches to 1KB chunks, it now allows to increase the max size
for the cached chunks with the tunable glibc.malloc.tcache_max.

It also now verifies if chunk was mmapped, in which case __libc_free
will not add it to tcache.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
malloc/malloc.c