From patchwork Thu Aug 29 06:27:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Wangyang" X-Patchwork-Id: 96649 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 25D8E385EC59 for ; Thu, 29 Aug 2024 06:31:05 +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 2D431385DDCA for ; Thu, 29 Aug 2024 06:30:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D431385DDCA 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 2D431385DDCA 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=1724913008; cv=none; b=XfSodDqRTYUtGO4oF7xHRwXVtse09ec9LVtjuKgUyIrY7YbyM7Bmjie1tmJHSK7hpneLlLliqM1O7urxnQgm6FSN4YI/aqQHXccPEA9eA1xxI9wSxJfgyH+XQ7Rai4fGU9wU8BoO9BGxNWFyQ1IdjGxBikigM/OXKIbZs8d66P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724913008; c=relaxed/simple; bh=t/hVu67XZli0Y0uJbiws1v6w4im9tZrtQe/nQawI/v8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IHBiKL8RpJUbQKQP0KP11XiPKahgy1VbjVRXr8ycbR6/Q41xlcH7OLWn+reZOFyBw1uPjNkGJOkQ6Oro3PyeRU+APQEU2B4jAuQMDzeGDmzz2kIDZlU6fGoC/VaCHOP4HqQcvZbZrTiwpQGlJyElsdK9ypi9TPZrZI0ucJ7qq1s= 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=1724913006; x=1756449006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t/hVu67XZli0Y0uJbiws1v6w4im9tZrtQe/nQawI/v8=; b=TzLLfSU75073Jiz9JXwSX+8lV+iB7XPJUh4q4OjAO7GRJGMomgR0EUIi PPnCu5ruH4zJpFwf4MGimBKDaL6nkOkygBYwViYffb/SezjRaIif7TRxa Iwpn1zUo/fCu4v8jN563OI6ZpQBdPNuAXdql03kKhcUH1v3iT1sP6X76n C5depm/zJf9aH5nynTVQhdlXde3K853HEBiCraN9nVLN5LJnDrsPsHt81 SsWvZ0ryqugxsosjDR65wHA7W9fAI6MwUK1ECEaA2yy/9bVayUjykGsUu +zMHFwQCtV4vfXKnEh2YOomhtq6/zOHywiQye99+L7PNg/2ku9qNnZ28V w==; X-CSE-ConnectionGUID: Mss6SumjR7+1cnbi8ZYZCw== X-CSE-MsgGUID: +GuFZ8vWQxOPJ9rA90QuTQ== X-IronPort-AV: E=McAfee;i="6700,10204,11178"; a="22998375" X-IronPort-AV: E=Sophos;i="6.10,185,1719903600"; d="scan'208";a="22998375" 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:05 -0700 X-CSE-ConnectionGUID: NH9r/iZ5Q+qWPjkFTDSkhA== X-CSE-MsgGUID: cTUuCaVPSImufjJJvwRBrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,185,1719903600"; d="scan'208";a="63539168" 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:04 -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 3/5] malloc: Arena is not needed for tcache path in free() Date: Thu, 29 Aug 2024 14:27:30 +0800 Message-ID: <20240829062732.1663342-4-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 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. --- Changes in v2: - _int_free_check() should be put outside of USE_TCACHE. - Link to v1: https://sourceware.org/pipermail/libc-alpha/2024-August/159360.html --- malloc/malloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 264f35e1a3..efb5292e9f 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)) @@ -3447,9 +3450,10 @@ __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); - _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 USE_TCACHE if (tcache_free (p, size)) @@ -3458,6 +3462,8 @@ __libc_free (void *mem) return; } #endif + + ar_ptr = arena_for_chunk (p); _int_free_chunk (ar_ptr, p, size, 0); }