[PATCH v3 3/5] malloc: replace _int_free by _int_free_chunk in sysmalloc.
Florian Weimer
fweimer@redhat.com
Fri Jan 3 08:51:40 GMT 2025
* Cupertino Miranda:
> sysmalloc calls to _int_free should not allow the freed chunks to be
> taken by tcache. These internal calls to free do not reflect any of the
> needs of the application, but rather chunk management.
> This code replaces those calls to _int_free by calls to _int_free_chunk.
> ---
> malloc/malloc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 77593ca0b2..9b2e04bfbf 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -2646,7 +2646,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
> CHUNK_HDR_SZ | PREV_INUSE);
> set_foot (chunk_at_offset (old_top, old_size), CHUNK_HDR_SZ);
> set_head (old_top, old_size | PREV_INUSE | NON_MAIN_ARENA);
> - _int_free (av, old_top, 1);
> + _int_free_chunk (av, old_top, chunksize (old_top), 1);
> }
> else
> {
> @@ -2912,7 +2912,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
> /* If possible, release the rest. */
> if (old_size >= MINSIZE)
> {
> - _int_free (av, old_top, 1);
> + _int_free_chunk (av, old_top, chunksize (old_top), 1);
> }
> }
> }
The code change looks okay.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
I don't think there's a missed chunk merging opportunity here. As the
commit message indicates, there's merely a possiblity that this
particular size class is never used by the application, so putting it
into tcache may prevent its allocation completely. If it's in the main
allocator, the chunk can bit split to satisfy smaller allocations. I
see why this can be beneficial with an extended tcache size range.
Thanks,
Florian
More information about the Libc-alpha
mailing list