{"id":2175490,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2175490/?format=json","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.0/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<22984336264c0cb2bad3c2459631ac14d4a890ac.1766051058.git.fweimer@redhat.com>","date":"2025-12-18T10:17:52","name":"[2/3] malloc: Only fill half of the tcache during batch allocation","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"41f4563beb42a866cf360de8f8b2d596fa825c85","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/1.0/people/14312/?format=json","name":"Florian Weimer","email":"fweimer@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/22984336264c0cb2bad3c2459631ac14d4a890ac.1766051058.git.fweimer@redhat.com/mbox/","series":[{"id":485815,"url":"http://patchwork.ozlabs.org/api/1.0/series/485815/?format=json","date":"2025-12-18T10:17:02","name":"malloc: batched frees","version":1,"mbox":"http://patchwork.ozlabs.org/series/485815/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2175490/checks/","tags":{},"headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=bvYa+Bul;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=bvYa+Bul","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dX68G13nPz1y2F\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 18 Dec 2025 21:18:54 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 3DA384BA2E2B\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 18 Dec 2025 10:18:52 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 900A54BA2E25\n for <libc-alpha@sourceware.org>; Thu, 18 Dec 2025 10:17:58 +0000 (GMT)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-389-sw9u239PMHqXlP_LQimw0Q-1; Thu,\n 18 Dec 2025 05:17:56 -0500","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 11A661956050\n for <libc-alpha@sourceware.org>; Thu, 18 Dec 2025 10:17:56 +0000 (UTC)","from fweimer-oldenburg.csb.redhat.com (unknown [10.44.33.94])\n by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 5ACE71953986\n for <libc-alpha@sourceware.org>; Thu, 18 Dec 2025 10:17:55 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 3DA384BA2E2B","OpenDKIM Filter v2.11.0 sourceware.org 900A54BA2E25"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 900A54BA2E25","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 900A54BA2E25","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766053078; cv=none;\n b=C1CzxTkuf4z7cr2UoHidLrG5dg7IaHzOl18aSj+PJhGUnBC8s4SPBsxAOjtW4Ea4loF0jmlhI89K5JW2spxQo0YnkI6RMmS/Bb7OcxfRcsQAQw3l0BhbOfA6ZE397ipfJ6q3QFj6EImVpbrTYKG0IfgM1dVh5/rp73WKimB5FzM=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1766053078; c=relaxed/simple;\n bh=goYBhFxyiIXci6huuIfSbxWZnhEUaEuUto1PqvmI/YM=;\n h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version;\n b=MV3JGodplascz96Krdrd1me0v4atyrUTZ9AGa4GhBuHvUSFBpzEt1h8cALU4KkzFfLhyHso+f7uzBYBPfFgoC75kTiJPMbBfm+V9bpF43nhyw7YIePNigVFuh8pw1jB09IFe8Bp+722iVs+LLz4rkww2XoKWuCud1RrDzIVBLzA=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1766053078;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=8QaJkGFaQhr+gicLSON/F0BqcIL5HHIdj/oqO+VKk9g=;\n b=bvYa+BulGHWLqboOPYAbeK+8RKdWLznKmn7CBWRqWSaJ30S9EA4tUaybGq4VMO7i5Y7Z4R\n s2vSu4l7Xos4haLdoTpPaopFQoy0L/+OOJ4Hc7Bc4LWRFEnfyjppveOJK5pV9ckn+dMKI7\n bgJY1vJN8XRMPhbcyCSIlLw/K9yvd20=","X-MC-Unique":"sw9u239PMHqXlP_LQimw0Q-1","X-Mimecast-MFC-AGG-ID":"sw9u239PMHqXlP_LQimw0Q_1766053076","From":"Florian Weimer <fweimer@redhat.com>","To":"libc-alpha@sourceware.org","Subject":"[PATCH 2/3] malloc: Only fill half of the tcache during batch\n allocation","In-Reply-To":"<cover.1766051058.git.fweimer@redhat.com>","Message-ID":"\n <22984336264c0cb2bad3c2459631ac14d4a890ac.1766051058.git.fweimer@redhat.com>","References":"<cover.1766051058.git.fweimer@redhat.com>","X-From-Line":"22984336264c0cb2bad3c2459631ac14d4a890ac Mon Sep 17 00:00:00 2001","Date":"Thu, 18 Dec 2025 11:17:52 +0100","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"1l6-RAO_GNsVOQcXNmFKq_blCrC0H_V1sdFH-MHqBE8_1766053076","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"},"content":"This leaves room for subsequent frees.\n---\n malloc/malloc.c | 14 ++++++++++----\n 1 file changed, 10 insertions(+), 4 deletions(-)","diff":"diff --git a/malloc/malloc.c b/malloc/malloc.c\nindex d2184c8d7a..d42f0183e3 100644\n--- a/malloc/malloc.c\n+++ b/malloc/malloc.c\n@@ -3940,8 +3940,11 @@ _int_malloc (mstate av, size_t bytes)\n \t      if (__glibc_unlikely (tcache_inactive ()))\n \t\ttcache_init (av);\n \n-\t      /* While bin not empty and tcache not full, copy chunks over.  */\n-\t      while (tcache->num_slots[tc_idx] != 0\n+\t      /* While bin not empty and tcache not full, copy chunks over.\n+\t\t Only fill half of the tcache, so that subsequent frees\n+\t\t do not immediately flush the tcache.  */\n+\t      unsigned int tcache_target_count = mp_.tcache_count / 2;\n+\t      while (tcache->num_slots[tc_idx] > tcache_target_count\n \t\t     && (tc_victim = last (bin)) != bin)\n \t\t{\n \t\t  if (tc_victim != NULL)\n@@ -3988,6 +3991,7 @@ _int_malloc (mstate av, size_t bytes)\n   if (tc_idx < mp_.tcache_small_bins)\n     tcache_nb = nb;\n   int return_cached = 0;\n+  unsigned int tcache_target_count = mp_.tcache_count / 2;\n \n   tcache_unsorted_count = 0;\n #endif\n@@ -4066,9 +4070,11 @@ _int_malloc (mstate av, size_t bytes)\n \t      if (__glibc_unlikely (tcache_inactive ()))\n \t\ttcache_init (av);\n \t      /* Fill cache first, return to user only if cache fills.\n-\t\t We may return one of these chunks later.  */\n+\t\t We may return one of these chunks later.  Only fill\n+\t\t half of tcache, so that subsequent frees do not flush\n+\t\t it immediately.  */\n \t      if (tcache_nb > 0\n-\t\t  && tcache->num_slots[tc_idx] != 0)\n+\t\t  && tcache->num_slots[tc_idx] > tcache_target_count)\n \t\t{\n \t\t  tcache_put (victim, tc_idx);\n \t\t  return_cached = 1;\n","prefixes":["2/3"]}