[PATCH 7/9] malloc: Remove fastbin infrastructure

DJ Delorie dj@redhat.com
Wed Nov 12 22:15:40 GMT 2025


Dev Jain <dev.jain@arm.com> writes:
> Now that all users of the fastbin code are gone, remove the fastbin
> infrastructure.
> ---
>  malloc/malloc.c | 53 ++-----------------------------------------------

I must admit, that line makes me a bit nervous... and pleased ;-)

> diff --git a/malloc/malloc.c b/malloc/malloc.c

> -#ifndef DEFAULT_MXFAST
> -#define DEFAULT_MXFAST     (64 * SIZE_SZ / 4)
> -#endif
> -

Ok.

I note that there's mxfast support in arena.c for tunables that this
patch series doesn't touch.  We don't need to keep unsupported tunables
around, do we?  IIRC they're silently ignored if not recognized.

> -typedef struct malloc_chunk *mfastbinptr;
> -#define fastbin(ar_ptr, idx) ((ar_ptr)->fastbinsY[idx])
> -
> -/* offset 2 to use otherwise unindexable first 2 bins */
> -#define fastbin_index(sz) \
> -  ((((unsigned int) (sz)) >> (SIZE_SZ == 8 ? 4 : 3)) - 2)
> -
> -
> -/* The maximum fastbin request size we support */
> -#define MAX_FAST_SIZE     (80 * SIZE_SZ / 4)
> -
> -#define NFASTBINS  (fastbin_index (request2size (MAX_FAST_SIZE)) + 1)
> -

Ok.

> -/* Maximum size of memory handled in fastbins.  */
> -static uint8_t global_max_fast;
> -

Ok.

> -#define set_max_fast(s) \
> -  global_max_fast = (((size_t) (s) <= MALLOC_ALIGN_MASK - SIZE_SZ)	\
> -                     ? MIN_CHUNK_SIZE / 2 : ((s + SIZE_SZ) & ~MALLOC_ALIGN_MASK))
> -
> -static __always_inline INTERNAL_SIZE_T
> -get_max_fast (void)
> -{
> -  /* Tell the GCC optimizers that global_max_fast is never larger
> -     than MAX_FAST_SIZE.  This avoids out-of-bounds array accesses in
> -     _int_malloc after constant propagation of the size parameter.
> -     (The code never executes because malloc preserves the
> -     global_max_fast invariant, but the optimizers may not recognize
> -     this.)  */
> -  if (global_max_fast > MAX_FAST_SIZE)
> -    __builtin_unreachable ();
> -  return global_max_fast;
> -}
> -

Ok.

> -  /* Flags (formerly in max_fast).  */
> +  /* Flags  */
>    int flags;

Ok.

> -  /* Fastbins */
> -  mfastbinptr fastbinsY[NFASTBINS];
> -

Ok.

> -  if (av == &main_arena)
> -    set_max_fast (DEFAULT_MXFAST);

Ok.

>  static __always_inline int
>  do_set_mxfast (size_t value)
>  {
> -  if (value <= MAX_FAST_SIZE)
> -    {
> -      LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ());
> -      set_max_fast (value);
> -      return 1;
> -    }
> -  return 0;
> +  return 1;
>  }

For tunables; ok.

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



More information about the Libc-alpha mailing list