From patchwork Thu Aug 29 06:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Wangyang" X-Patchwork-Id: 96651 X-Patchwork-Delegate: fweimer@redhat.com 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 35F5C385EC57 for ; Thu, 29 Aug 2024 06:31:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by sourceware.org (Postfix) with ESMTPS id 2312A3858289 for ; Thu, 29 Aug 2024 06:30:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2312A3858289 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 2312A3858289 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724913006; cv=none; b=JBzrMk6nJPFClh/0PQ+8BYNQQMml0z7e+aYHnq/F5o1yXFE2cTUHPWH03sq8fhxVHQAG0LbA8LCsPu2TSDUt8+MMg/mkvUULWAod9NXh4swxKGym/qtDHnp+xcLzj80yZnweT1lmo5M3rk0Mx2BPo5ViGxHnRqUISg4ZJWcrjsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724913006; c=relaxed/simple; bh=Cv/Dx6UpnlcnsI0OYKK3ior3yWu1wX3XERApypGMNUQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rQ9Wll+/4bexBMsCs80hTlxE6QI8Yy3xVKcrNkl974w1C25nsBkSwsxMNKkL5L+IOFONorr0JptKOh5ettoZHcLYIn6BkiCcaNDjtH3G+1acahPe1rDRkmbXIVayk+BXbd7rXoWR16ncO8/all3HsFhxktwZS0YNZGf9HyPuZCc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724913004; x=1756449004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cv/Dx6UpnlcnsI0OYKK3ior3yWu1wX3XERApypGMNUQ=; b=RLUtuBVmbalzkF/CWJOsXKKcOOHdoFD+FTRBhxAqCFIECJSf2RusJNLD tOpEjSftrCKllXkg+mnOgheMd/5fme5Ic+vXGZu6hVzi13zzrp7VdMeho uPlNrmUw1Vy3xxzVpOOF0gEC6MhFBNcU1PGncly+HuLjxankgvMdBKI2E TaEtAxDWYRzbw8Ne6otBVySBx1o7yGWMhr/Wj4KG2BPlIogeK+hJWTxdH CH+c6ijWQwEmL4zsuY2ysE9t4vVnOq0ITVYM8Uy9OxFLBFYuAEEu8Dz4k JkaEAvIXVtlKpDkgQUCDPrcLQlxdqfaUrMd5xWW6z0Efp5XsTYf87InvA g==; X-CSE-ConnectionGUID: HKMYq/baTmO6r/W2nx4h1A== X-CSE-MsgGUID: gfoJtg/sR6+Yb1fDJZI/SQ== X-IronPort-AV: E=McAfee;i="6700,10204,11178"; a="22998346" X-IronPort-AV: E=Sophos;i="6.10,185,1719903600"; d="scan'208";a="22998346" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Aug 2024 23:30:04 -0700 X-CSE-ConnectionGUID: 31V8xl9qRRqCQTiiy8Vy7w== X-CSE-MsgGUID: OILMay/wQqSLUZtZDA84DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,185,1719903600"; d="scan'208";a="63539140" Received: from linux-pnp-server-11.sh.intel.com ([10.239.176.178]) by fmviesa009.fm.intel.com with ESMTP; 28 Aug 2024 23:30:02 -0700 From: Wangyang Guo To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, goldstein.w.n@gmail.com, tianyou.li@intel.com, Wangyang Guo Subject: [PATCH v3 2/5] malloc: Avoid func call for tcache quick path in free() Date: Thu, 29 Aug 2024 14:27:29 +0800 Message-ID: <20240829062732.1663342-3-wangyang.guo@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240829062732.1663342-1-wangyang.guo@intel.com> References: <20240829062732.1663342-1-wangyang.guo@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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, T_SCC_BODY_TEXT_LINE 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. Result of bench-malloc-thread benchmark Test Platform: Xeon-8380 Ratio: New / Original time_per_iteration (Lower is Better) Threads# | Ratio -----------|------ 1 thread | 0.904 4 threads | 0.919 The performance data shows it can improve bench-malloc-thread benchmark by ~10% in single thread and ~8% in multi-thread scenario. --- 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index ef49a13ea7..264f35e1a3 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3448,7 +3448,17 @@ __libc_free (void *mem) (void)tag_region (chunk2mem (p), memsize (p)); ar_ptr = arena_for_chunk (p); - _int_free (ar_ptr, p, 0); + INTERNAL_SIZE_T size = chunksize (p); + _int_free_check (ar_ptr, p, size); + +#if USE_TCACHE + if (tcache_free (p, size)) + { + __set_errno (err); + return; + } +#endif + _int_free_chunk (ar_ptr, p, size, 0); } __set_errno (err);