From patchwork Wed Jul 1 13:38:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 138211 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BDB64BA2E3C for ; Wed, 1 Jul 2026 13:41:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BDB64BA2E3C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hFbtOuEy X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 954B94BA543C for ; Wed, 1 Jul 2026 13:39:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 954B94BA543C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 954B94BA543C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782913155; cv=none; b=uvr4jra5v3KCmD1kKpnDo0W2MQapXkGfMO6X7thMNiyl6LZG71O9aTDSccLWEtMITqFyrOPck9vH1VJDe23zeTSinpBFIj8BjKZp/kyD6ZAWjRHgYDcbLONhkMoFdY3+RCZkhu0BuESbpiiWFh8FMPtUTpFB7rjWVoVf0l5eXL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782913155; c=relaxed/simple; bh=PTJU7W77cTOzz30SpXT6B56WOdsNsSE8MCyZtm6Yw4c=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=d/9r8PodU2AnBp6TtfDU6y0XJ9AEwr/wAKHx+Cqso4l3xi0vifyVOasgaGB486UcwwIqguoXcx9lQM2BR/kGhuRPurA5aQa5HLaAmVPzvVWXMa7HK5qsPCZ0Kus7g+UCD/ErpfRb5lYl9TXOJMnzw14oa3rn9RwbwXU7mRnhlh8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hFbtOuEy DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 954B94BA543C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782913155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=buo887RN8Y+JB2EhVbQX+AOsTK9Uj8EV6P9Z7v6Qd8g=; b=hFbtOuEyO9eT8ML7WpRGECTKjurMHBRrtPJtqklPrjKaaaWq0TxCFf/XQwTSVyK/t9Rbn1 3MRiWmwuixtpynX4zpaj3o1chD1G0//VwrY/5vlP8dDL6EBYKDOvWyNraRFyH0nsPfFz8H wAJzRRRi+YysslMQngabe+fKqOq5vYk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-RGeZKrdFN8Kv5f7Ksne-DQ-1; Wed, 01 Jul 2026 09:39:12 -0400 X-MC-Unique: RGeZKrdFN8Kv5f7Ksne-DQ-1 X-Mimecast-MFC-AGG-ID: RGeZKrdFN8Kv5f7Ksne-DQ_1782913152 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F40D0184B09D for ; Wed, 1 Jul 2026 13:39:11 +0000 (UTC) Received: from fweimer-oldenburg.csb.redhat.com (unknown [10.44.32.220]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 478E0195E486 for ; Wed, 1 Jul 2026 13:39:11 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 2/4] malloc: Only fill half of the tcache during batch allocation In-Reply-To: Message-ID: References: X-From-Line: daf953123dfc904910820bb4266c8ccc21ca1ecc Mon Sep 17 00:00:00 2001 Date: Wed, 01 Jul 2026 15:38:59 +0200 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: s7EGkb-9_EZje2KHtgIQHjeWpgAHXJFJVG2Hytfas90_1782913152 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This leaves room for subsequent frees. --- malloc/malloc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)