From patchwork Thu Aug 22 02:59:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Wangyang" X-Patchwork-Id: 1975215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=c9GxLj5c; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wq7Ld5ZVHz1ybW for ; Thu, 22 Aug 2024 13:03:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC97E3870C17 for ; Thu, 22 Aug 2024 03:03:19 +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.13]) by sourceware.org (Postfix) with ESMTPS id 4BE0D385DDEE for ; Thu, 22 Aug 2024 03:02:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4BE0D385DDEE 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 4BE0D385DDEE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724295756; cv=none; b=N+Yp9lCV7Sx+jVFExXLktFBvOnCLia/w36S3GUetYCAGqU4/hDI+l2ODvovI9u0EtALmemcjhju2TxoXgE/NKpZDuz/9i6uZu9J8We1OuInO/oRXWYPz5ie7P19nJNSwRWu4wYteeNme/MGB4oG7QbBFZN8JbAo7W1btkkHaWxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724295756; c=relaxed/simple; bh=cj0E5I2ipJf9gMrQDmYhXCyp7Nv43nQ3OCA3aCy537o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oDOmw/2lYfp7huddOb8uZWpVTwD4uk7BcjpL8S03dE/tQ9UfwNBamGqvbKWIwHgdGUr8wzjiaoWiyJVcnmcev0nWpeV/h5oO7zmJQBBLoQXcfTimsqjyPkhBDHAwZPrNfVM0ZQiERo6Eo24cZFKpZ7psaD5pSr+EQXaiyuaRT2I= 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=1724295754; x=1755831754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cj0E5I2ipJf9gMrQDmYhXCyp7Nv43nQ3OCA3aCy537o=; b=c9GxLj5cO8RmkVzRYiz99oiIVakkVcdcvkphWY/g5V8gc1teJ8/AYUYq zDJqzKQvwVW5Dsyl59Aig+7M2UdEMb5qvLEvHT+fNGzLrjykz9Kx0VCSl J/ut2ifq1DxgJctH7vKTlZPnoTcWDW4n0uyhROUY9Yo7oDGikyG1brK+a 9Qabm/or3bn9y7211gaxDKVRRBK09uGzQobDvnmIGhrbYqNXnX+yJxq7L 49Da6KyT8RnIi+ADM6Bwy7eDWnk29US2frEarR4GfeBLZHZUIMtj/r7J5 uhRdQ5TgfC/+/xuFvkpsk9DfIBvndKWo6c1kYkuKZRoqwiYa4DmzSqF07 w==; X-CSE-ConnectionGUID: XSYcvOb5R6OI+2MdyIEXmA== X-CSE-MsgGUID: 7pOTecp7Qf6uN+FlABYguQ== X-IronPort-AV: E=McAfee;i="6700,10204,11171"; a="25581825" X-IronPort-AV: E=Sophos;i="6.10,165,1719903600"; d="scan'208";a="25581825" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2024 20:02:34 -0700 X-CSE-ConnectionGUID: HQDPSdkWQQ+JvqZ96IhQXg== X-CSE-MsgGUID: luyTBhHJR4abdO1JD4xO1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,165,1719903600"; d="scan'208";a="66181825" Received: from linux-pnp-server-11.sh.intel.com ([10.239.176.178]) by orviesa005.jf.intel.com with ESMTP; 21 Aug 2024 20:02:32 -0700 From: Wangyang Guo To: libc-alpha@sourceware.org Cc: Noah Goldstein , Tianyou Li , Wangyang Guo Subject: [PATCH 3/6] malloc: Arena is not needed for tcache path in free() Date: Thu, 22 Aug 2024 10:59:18 +0800 Message-ID: <20240822025921.3120998-4-wangyang.guo@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240822025921.3120998-1-wangyang.guo@intel.com> References: <20240822025921.3120998-1-wangyang.guo@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 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~incoming=patchwork.ozlabs.org@sourceware.org Arena is not needed for _int_free_check() in non-DEBUG mode. This commit defers arena deference to _int_free_chunk() thus accelerate tcache path. When DEBUG enabled, arena can be obtained from p in do_check_inuse_chunk(). Result of bench-malloc-thread benchmark Test Platform: Xeon-8380 Ratio: New / Original time_per_iteration (Lower is Better) Threads# | Ratio -----------|------ 1 thread | 0.994 4 threads | 0.968 The data shows it can brings 3% performance gain in multi-thread scenario. Signed-off-by: Wangyang Guo --- malloc/malloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 4ec6c5db35..030aff093b 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -2143,6 +2143,9 @@ do_check_inuse_chunk (mstate av, mchunkptr p) { mchunkptr next; + if (av == NULL) + av = arena_for_chunk (p); + do_check_chunk (av, p); if (chunk_is_mmapped (p)) @@ -3439,17 +3442,20 @@ __libc_free (void *mem) /* Mark the chunk as belonging to the library again. */ (void)tag_region (chunk2mem (p), memsize (p)); - ar_ptr = arena_for_chunk (p); INTERNAL_SIZE_T size = chunksize (p); #if USE_TCACHE - _int_free_check (ar_ptr, p, size); + /* av is not needed for _int_free_check in non-DEBUG mode, + in DEBUG mode, av will fetch from p in do_check_inuse_chunk. */ + _int_free_check (NULL, p, size); if (tcache_free (p, size)) { __set_errno (err); return; } #endif + + ar_ptr = arena_for_chunk (p); _int_free_chunk (ar_ptr, p, size, 0); }