[PATCH 7/9] malloc: Remove fastbin infrastructure

Dev Jain dev.jain@arm.com
Fri Oct 17 09:07:05 GMT 2025


Now that all users of the fastbin code are gone, remove the fastbin
infrastructure.
---
 malloc/malloc.c | 53 ++-----------------------------------------------
 1 file changed, 2 insertions(+), 51 deletions(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index a20662731c..0f9677a792 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -817,10 +817,6 @@ libc_hidden_proto (__libc_mallopt)
 #define M_MXFAST            1
 #endif
 
-#ifndef DEFAULT_MXFAST
-#define DEFAULT_MXFAST     (64 * SIZE_SZ / 4)
-#endif
-
 
 /*
   M_TRIM_THRESHOLD is the maximum amount of unused top-most memory
@@ -1746,19 +1742,6 @@ unlink_chunk (mstate av, mchunkptr p)
     other free chunks.
  */
 
-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)
-
 /*
    FASTBIN_CONSOLIDATION_THRESHOLD is the size of a chunk in free()
    that triggers automatic consolidation of possibly-surrounding
@@ -1787,9 +1770,6 @@ typedef struct malloc_chunk *mfastbinptr;
 #define set_noncontiguous(M)   ((M)->flags |= NONCONTIGUOUS_BIT)
 #define set_contiguous(M)      ((M)->flags &= ~NONCONTIGUOUS_BIT)
 
-/* Maximum size of memory handled in fastbins.  */
-static uint8_t global_max_fast;
-
 /*
    Set value of max_fast.
    Use impossibly small value if 0.
@@ -1799,24 +1779,6 @@ static uint8_t global_max_fast;
    entries if max_fast is reduced.
  */
 
-#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;
-}
-
 /*
    ----------- Internal state representation and initialization -----------
  */
@@ -1837,12 +1799,9 @@ struct malloc_state
   /* Serialize access.  */
   __libc_lock_define (, mutex);
 
-  /* Flags (formerly in max_fast).  */
+  /* Flags  */
   int flags;
 
-  /* Fastbins */
-  mfastbinptr fastbinsY[NFASTBINS];
-
   /* Base of the topmost chunk -- not otherwise kept in a bin */
   mchunkptr top;
 
@@ -1974,8 +1933,6 @@ malloc_init_state (mstate av)
   if (av != &main_arena)
 #endif
   set_noncontiguous (av);
-  if (av == &main_arena)
-    set_max_fast (DEFAULT_MXFAST);
 
   av->top = initial_top (av);
 }
@@ -5219,13 +5176,7 @@ do_set_tcache_unsorted_limit (size_t value)
 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;
 }
 
 static __always_inline int
-- 
2.43.0



More information about the Libc-alpha mailing list