[PATCH 8/9] malloc: remove fastbin comments

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


Now that all the fastbin code is gone, remove the remaining comments
referencing fastbins.
---
 malloc/malloc.c | 97 +++----------------------------------------------
 1 file changed, 6 insertions(+), 91 deletions(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 0f9677a792..620527c9c6 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -190,7 +190,7 @@
 
     Tuning options that are also dynamically changeable via mallopt:
 
-    DEFAULT_MXFAST             64 (for 32bit), 128 (for 64bit)
+    DEFAULT_MXFAST (deprecated)            64 (for 32bit), 128 (for 64bit)
     DEFAULT_TRIM_THRESHOLD     128 * 1024
     DEFAULT_TOP_PAD            0
     DEFAULT_MMAP_THRESHOLD     128 * 1024
@@ -323,7 +323,7 @@
 
 /* Safe-Linking:
    Use randomness from ASLR (mmap_base) to protect single-linked lists
-   of Fast-Bins and TCache.  That is, mask the "next" pointers of the
+   of TCache.  That is, mask the "next" pointers of the
    lists' chunks, and also perform allocation alignment checks on them.
    This mechanism reduces the risk of pointer hijacking, as was done with
    Safe-Unlinking in the double-linked lists of Small-Bins.
@@ -773,7 +773,7 @@ int      __posix_memalign(void **, size_t, size_t);
   configurations).
 
   Symbol            param #   default    allowed param values
-  M_MXFAST          1         64         0-80  (0 disables fastbins)
+  M_MXFAST           1         64         0-80  (0 was used to disable fastbins, now deprecated)
   M_TRIM_THRESHOLD -1         128*1024   any   (-1U disables trimming)
   M_TOP_PAD        -2         0          any
   M_MMAP_THRESHOLD -3         128*1024   any   (or 0 if no MMAP support)
@@ -786,32 +786,6 @@ libc_hidden_proto (__libc_mallopt)
 
 /* mallopt tuning options */
 
-/*
-  M_MXFAST is the maximum request size used for "fastbins", special bins
-  that hold returned chunks without consolidating their spaces. This
-  enables future requests for chunks of the same size to be handled
-  very quickly, but can increase fragmentation, and thus increase the
-  overall memory footprint of a program.
-
-  This malloc manages fastbins very conservatively yet still
-  efficiently, so fragmentation is rarely a problem for values less
-  than or equal to the default.  The maximum supported value of MXFAST
-  is 80. You wouldn't want it any higher than this anyway.  Fastbins
-  are designed especially for use with many small structs, objects or
-  strings -- the default handles structs/objects/arrays with sizes up
-  to 8 4byte fields, or small strings representing words, tokens,
-  etc. Using fastbins for larger objects normally worsens
-  fragmentation without improving speed.
-
-  M_MXFAST is set in REQUEST size units. It is internally used in
-  chunksize units, which adds padding and alignment.  You can reduce
-  M_MXFAST to 0 to disable all use of fastbins.  This causes the malloc
-  algorithm to be a closer approximation of fifo-best-fit in all cases,
-  not just for larger requests, but will generally cause it to be
-  slower.
-*/
-
-
 /* M_MXFAST is a standard SVID/XPG tuning option, usually listed in malloc.h */
 #ifndef M_MXFAST
 #define M_MXFAST            1
@@ -1227,10 +1201,6 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 	to a freed chunk).  The M bit is also used for chunks which
 	originally came from a dumped heap via malloc_set_state in
 	hooks.c.
-
-     3. Chunks in fastbins are treated as allocated chunks from the
-	point of view of the chunk allocator.  They are consolidated
-	with their neighbors only in bulk, in malloc_consolidate.
 */
 
 /*
@@ -1725,23 +1695,6 @@ unlink_chunk (mstate av, mchunkptr p)
 #define unmark_bin(m, i)  ((m)->binmap[idx2block (i)] &= ~(idx2bit (i)))
 #define get_binmap(m, i)  ((m)->binmap[idx2block (i)] & idx2bit (i))
 
-/*
-   Fastbins
-
-    An array of lists holding recently freed small chunks.  Fastbins
-    are not doubly linked.  It is faster to single-link them, and
-    since chunks are never removed from the middles of these lists,
-    double linking is not necessary. Also, unlike regular bins, they
-    are not even processed in FIFO order (they use faster LIFO) since
-    ordering doesn't much matter in the transient contexts in which
-    fastbins are normally used.
-
-    Chunks in fastbins keep their inuse bit set, so they cannot
-    be consolidated with other free chunks. malloc_consolidate
-    releases all chunks in fastbins and consolidates them with
-    other free chunks.
- */
-
 /*
    FASTBIN_CONSOLIDATION_THRESHOLD is the size of a chunk in free()
    that triggers automatic consolidation of possibly-surrounding
@@ -1770,29 +1723,10 @@ unlink_chunk (mstate av, mchunkptr p)
 #define set_noncontiguous(M)   ((M)->flags |= NONCONTIGUOUS_BIT)
 #define set_contiguous(M)      ((M)->flags &= ~NONCONTIGUOUS_BIT)
 
-/*
-   Set value of max_fast.
-   Use impossibly small value if 0.
-   Precondition: there are no existing fastbin chunks in the main arena.
-   Since do_check_malloc_state () checks this, we call malloc_consolidate ()
-   before changing max_fast.  Note other arenas will leak their fast bin
-   entries if max_fast is reduced.
- */
-
 /*
    ----------- Internal state representation and initialization -----------
  */
 
-/*
-   have_fastchunks indicates that there are probably some fastbin chunks.
-   It is set true on entering a chunk into any fastbin, and cleared early in
-   malloc_consolidate.  The value is approximate since it may be set when there
-   are no fastbin chunks, or it may be clear even if there are fastbin chunks
-   available.  Given it's sole purpose is to reduce number of redundant calls to
-   malloc_consolidate, it does not affect correctness.  As a result we can safely
-   use relaxed atomic accesses.
- */
-
 
 struct malloc_state
 {
@@ -2149,10 +2083,6 @@ do_check_inuse_chunk (mstate av, mchunkptr p)
     do_check_free_chunk (av, next);
 }
 
-/*
-   Properties of chunks recycled from fastbins
- */
-
 static void
 do_check_remalloced_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T s)
 {
@@ -2195,8 +2125,7 @@ do_check_malloced_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T s)
      chunk borders either a previously allocated and still in-use
      chunk, or the base of its memory arena. This is ensured
      by making all allocations from the `lowest' part of any found
-     chunk.  This does not necessarily hold however for chunks
-     recycled via fastbins.
+     chunk.
    */
 
   assert (prev_inuse (p));
@@ -3913,17 +3842,6 @@ _int_malloc (mstate av, size_t bytes)
         }
     }
 
-  /*
-     If this is a large request, consolidate fastbins before continuing.
-     While it might look excessive to kill all fastbins before
-     even seeing if there is space available, this avoids
-     fragmentation problems normally associated with fastbins.
-     Also, in practice, programs tend to have runs of either small or
-     large requests, but less often mixtures, so consolidation is not
-     invoked all that often in most programs. And the programs that
-     it is called frequently in otherwise tend to fragment.
-   */
-
   else
     {
       idx = largebin_index (nb);
@@ -4553,11 +4471,8 @@ _int_free_create_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T size,
 static void
 _int_free_maybe_consolidate (mstate av, INTERNAL_SIZE_T size)
 {
-  /* Unless max_fast is 0, we don't know if there are fastbins
-     bordering top, so we cannot tell for sure whether threshold has
-     been reached unless fastbins are consolidated.  But we don't want
-     to consolidate on each free.  As a compromise, consolidation is
-     performed if FASTBIN_CONSOLIDATION_THRESHOLD is reached.  */
+  /* We don't want to consolidate on each free.  As a compromise, consolidation
+     is performed if FASTBIN_CONSOLIDATION_THRESHOLD is reached.  */
   if (size >= FASTBIN_CONSOLIDATION_THRESHOLD)
     {
       if (av == &main_arena)
-- 
2.43.0



More information about the Libc-alpha mailing list