From patchwork Tue Nov 26 07:33:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wangyang Guo X-Patchwork-Id: 101869 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E3B53858C50 for ; Tue, 26 Nov 2024 07:41:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E3B53858C50 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=VD0XXFWN X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by sourceware.org (Postfix) with ESMTPS id 1D7D83858D33 for ; Tue, 26 Nov 2024 07:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D7D83858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D7D83858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732606633; cv=none; b=ZHkzVDMiXbS2xWCYQ/PNIqUJzGr9sVRsAXfcGsOPhB7F18Xhb3ufbJ3CArBxEHQpyEaKL8PG+Lvg5NpqaK53DZ5IsNKtJWS1X4icPmwVhhCatxOnme4O/EIlPRpzLmUXx5s+GRUbWspPXSPVUC5wJ1/ItF1Splyevnn4TfZVqrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732606633; c=relaxed/simple; bh=7nVQthnMJpQepJ8n+yLFdCjpjeWIy6mcheWNzs3z0yg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XKciEADfQqNn43b0LF4hgsHkcn/eL7JSJOWJ7wZkEZ8qdRWr/egG46LrqZ7Pyx9X66qlbzUJ0Q/PeFcgfwvSYufU+gtflTu7oEB2mqCIowmViKb8KiysMxijOKzcP82mlUiNUf8Au2/j6xXuz2ooPLc5X3vQ+rdqkCcfTQtxbZ8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D7D83858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732606634; x=1764142634; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7nVQthnMJpQepJ8n+yLFdCjpjeWIy6mcheWNzs3z0yg=; b=VD0XXFWNUSXDM3XLJq0fLiL76rloT4oDaYa0set+6M5Np/tojnmAczZA IL1BnLgdY8IQw+oQO1BD1SYdFhcAaPW/h0A4TZKzY/uh8mjD+WmNK4X9Z 50yBIsWiRmnZzZIms1RK3Fj1X5bI5wqoHSbRqA9/2Xr50x5YXPePODlWm te/OLIk1jRuFP+0y/do0dftKGKvtB0mF+h94MTwekPlh2sSdkTysrdy5R Smc/qrlbwzXiB+kkhe1U4viAuAF+pBcNTJjcVS8Qe1HU+3IdKLEAbgO/y yY99hotO+58GatbAhqNca13cWh0gDXnAlX1GYsDYLlwraJaCotG6cQl7o w==; X-CSE-ConnectionGUID: STW7hFjIT4CastSS0++JNw== X-CSE-MsgGUID: j6q4g2LeSIusn3JvvN4njw== X-IronPort-AV: E=McAfee;i="6700,10204,11267"; a="43816019" X-IronPort-AV: E=Sophos;i="6.12,185,1728975600"; d="scan'208";a="43816019" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2024 23:37:13 -0800 X-CSE-ConnectionGUID: lKYFVb7GSduVWKx/awUIOg== X-CSE-MsgGUID: UlMPqtEBQaSZcl7Z/S+CZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,185,1728975600"; d="scan'208";a="95950752" Received: from linux-pnp-server-11.sh.intel.com ([10.239.176.178]) by fmviesa005.fm.intel.com with ESMTP; 25 Nov 2024 23:37:10 -0800 From: Wangyang Guo To: fweimer@redhat.com, hjl.tools@gmail.com Cc: libc-alpha@sourceware.org, goldstein.w.n@gmail.com, tianyou.li@intel.com, Wangyang Guo Subject: [PATCH v4 1/3] malloc: Avoid func call for tcache quick path in free() Date: Tue, 26 Nov 2024 15:33:38 +0800 Message-ID: <20241126073340.3724382-2-wangyang.guo@intel.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241126073340.3724382-1-wangyang.guo@intel.com> References: <20241126073340.3724382-1-wangyang.guo@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 Tcache is an important optimzation to accelerate memory free(), things within this code path should be kept as simple as possible. This commit try to remove the function call when free() invokes tcache code path by inlining _int_free(). Result of bench-malloc-thread benchmark Test Platform: Xeon-8380 Ratio: New / Original time_per_iteration (Lower is Better) Threads# | Ratio -----------|------ 1 thread | 0.879 4 threads | 0.874 The performance data shows it can improve bench-malloc-thread benchmark by ~12% in both single thread and multi-thread scenario. Reviewed-by: H.J. Lu --- Changes in v4: - inline _int_free instead of manual inlining. - Link to v3: https://sourceware.org/pipermail/libc-alpha/2024-August/159505.html No Changes in v3 Changes in v2: - _int_free_check() should be put outside of USE_TCACHE. - Link to v1: https://sourceware.org/pipermail/libc-alpha/2024-August/159359.html --- malloc/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 32dbc272a8..81ddd2c3a8 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -4677,7 +4677,7 @@ _int_free_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T size, int have_lock) P has already been locked. It will perform sanity check, then try the fast path to free into tcache. If the attempt not success, free the chunk to arena. */ -static void +static inline void _int_free (mstate av, mchunkptr p, int have_lock) { INTERNAL_SIZE_T size; /* its size */