]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Only fill half of the tcache during batch allocation
authorFlorian Weimer <fweimer@redhat.com>
Fri, 7 Nov 2025 09:27:20 +0000 (10:27 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 30 Jun 2026 07:07:19 +0000 (09:07 +0200)
This leaves room for subsequent frees.

malloc/malloc.c

index 99ba94454e40566eb566c8d3e8c64d55375ee634..3505158ac0f0c9ab3547d5886992853851eed60e 100644 (file)
@@ -3570,8 +3570,11 @@ _int_malloc (mstate av, size_t bytes)
              if (__glibc_unlikely (tcache_inactive ()))
                tcache_init (av);
 
-             /* While bin not empty and tcache not full, copy chunks over.  */
-             while (tcache->num_slots[tc_idx] != 0
+             /* While bin not empty and tcache not full, copy chunks over.
+                Only fill half of the tcache, so that subsequent frees
+                do not immediately flush the tcache.  */
+             unsigned int tcache_target_count = mp_.tcache_count / 2;
+             while (tcache->num_slots[tc_idx] > tcache_target_count
                     && (tc_victim = last (bin)) != bin)
                {
                  if (tc_victim != NULL)