[2/4] malloc: Only fill half of the tcache during batch allocation

Message ID daf953123dfc904910820bb4266c8ccc21ca1ecc.1782911956.git.fweimer@redhat.com (mailing list archive)
State New
Headers
Series malloc: Batched frees, tcache hysteresis behavior |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Florian Weimer July 1, 2026, 1:38 p.m. UTC
  This leaves room for subsequent frees.
---
 malloc/malloc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Patch

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 99ba94454e..3505158ac0 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -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)