[PATCH 2/9] malloc: remove malloc_consolidate

DJ Delorie dj@redhat.com
Wed Nov 12 03:25:37 GMT 2025


Dev Jain <dev.jain@arm.com> writes:
> diff --git a/malloc/malloc.c b/malloc/malloc.c
>  
> -  /* Set if the fastbin chunks contain recently inserted free blocks.  */
> -  /* Note this is a bool but not all targets support atomics on booleans.  */
> -  int have_fastchunks;
> -

Ok.

>    set_noncontiguous (av);
>    if (av == &main_arena)
>      set_max_fast (DEFAULT_MXFAST);
> -  atomic_store_relaxed (&av->have_fastchunks, false);

Ok.

> -static void     malloc_consolidate (mstate);

Ok.

>      {
>        idx = largebin_index (nb);
> -      if (atomic_load_relaxed (&av->have_fastchunks))
> -        malloc_consolidate (av);
>      }

Ok.

>  
> -      /* When we are using atomic ops to free fast chunks we can get
> -         here for all block sizes.  */
> -      else if (atomic_load_relaxed (&av->have_fastchunks))
> -        {
> -          malloc_consolidate (av);
> -          /* restore original bin index */
> -          if (in_smallbin_range (nb))
> -            idx = smallbin_index (nb);
> -          else
> -            idx = largebin_index (nb);
> -        }
> -

Ok.

>      free_perturb (chunk2mem(p), size - CHUNK_HDR_SZ);
>  
> -    atomic_store_relaxed (&av->have_fastchunks, true);

Ok.

>    if (size >= FASTBIN_CONSOLIDATION_THRESHOLD)

I notice that none of these patches remove this macro...  Perhaps it
should be renamed later to better reflect its new purpose (trimming) ?

>      {
> -      if (atomic_load_relaxed (&av->have_fastchunks))
> -	malloc_consolidate(av);
> -

Ok.

> -/*
> -  ------------------------- malloc_consolidate -------------------------
> -
> -  malloc_consolidate is a specialized version of free() that tears
> -  down chunks held in fastbins.  Free itself cannot be used for this
> -  purpose since, among other things, it might place chunks back onto
> . . .
> -  } while (fb++ != maxfb);
> -}
> -

Ok.

>  static int
>  mtrim (mstate av, size_t pad)
>  {
> -  /* Ensure all blocks are consolidated.  */
> -  malloc_consolidate (av);
> -

Ok.

> -  /* We must consolidate main arena before changing max_fast
> -     (see definition of set_max_fast).  */
> -  malloc_consolidate (av);
> -

Ok.

LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>



More information about the Libc-alpha mailing list