[PATCH v7 1/2] malloc: add tcache support for large chunk caching
Cupertino Miranda
cupertino.miranda@oracle.com
Wed May 28 16:37:51 GMT 2025
Hi Wilco,
Just seen this request.
What would you say to fix this with ?
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 4cd0f728d2..5c51769ffd 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3287,7 +3287,7 @@ tcache_index (size_t bytes)
if (__glibc_likely (tc_idx < mp_.tcache_bins))
return tc_idx;
}
- else
+ else if (bytes < mp_.tcache_max_bytes)
{
tc_idx = large_csize2tidx (bytes);
if (tc_idx < mp_.tcache_bins)
The function large_csize2tidx is only called by tcache_index.
There is also another detail, that the value in mp_.tcache_max_bytes
needs to become the chunk size and not allocation size.
mp_.tcache_max_bytes is not used anywhere else, either.
Cheers,
Cupertino
On 28-05-2025 00:27, Wilco Dijkstra wrote:
> Hi Cupertino,
>
> Another thing, 64-bit targets may malloc over 4GB, so this will fail:
>
>>> + - __builtin_clz (nb);
>
> You need to ensure it works for 32-bit and 64-bit size_t - clzl won't work
> since unsigned long is not always the same size as size_t, and while clzll
> should work, it has to be efficient on 32-bit targets (ie. not becoming a
> call when clz isn't a call). The new stdbit.h is type generic, so could be
> used, but we need to confirm that it results in good code.
>
> Cheers,
> Wilco
More information about the Libc-alpha
mailing list