From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 954B7429E5 for ; Tue, 25 Apr 2023 07:37:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 69CE340A7E; Tue, 25 Apr 2023 07:37:40 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 938CC400D7; Tue, 25 Apr 2023 07:37:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682401058; x=1713937058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jl3x5IcYR6MPcrZm7nA6Usky2ptTNsHbUKIHhujRv9M=; b=MtztEmgITc5GWCrky7sqwKxfzZ1mF0ZWOpz6m/+5BEsOaM+VUCPD9ThQ Jsb5SYiUO54+dr1izCeha2vXTEbgfQ9+u6lnii9fWkFlWfvjefzD9uYhr dFFU7vTgRcGO69HBWJnxHeWlb2pEivYWoe551RlXTsLcmEnBSb+VFqsy9 VBPoEBcTbVvhXWNNDL7QVCG8QvJEkWKzcabH2p29TSHlRdC7xlDr0UFbp o31xDfKeW6bI+nZlaI6VMXS23CMAMxLsBK4osrBjNgHHmuBVWPapkPszv ZQldr17edrnnIMnx8nPspOyik2snACK7hmSHFNUHme9bXKQbsupYMm2fM Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="349462220" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="349462220" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:37:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10690"; a="757977921" X-IronPort-AV: E=Sophos;i="5.99,224,1677571200"; d="scan'208";a="757977921" Received: from unknown (HELO localhost.localdomain) ([10.239.252.104]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2023 22:37:33 -0700 From: Kaisen You To: dev@dpdk.org Cc: yidingx.zhou@intel.com, thomas@monjalon.net, david.marchand@redhat.com, olivier.matz@6wind.com, ferruh.yigit@amd.com, anatoly.burakov@intel.com, Kaisen You , stable@dpdk.org Subject: [PATCH v6] enhance NUMA affinity heuristic Date: Tue, 25 Apr 2023 13:16:49 +0800 Message-Id: <20230425051649.1109428-1-kaisenx.you@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230201122048.1283392-1-kaisenx.you@intel.com> References: <20230201122048.1283392-1-kaisenx.you@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Trying to allocate memory on the first detected numa node,it has less chance to find some memory actually available rather than on the main lcore numa node (especially when the DPDK application is started only on one numa node). Fixes: 8b0a1b8cb481 ("eal: stop using pthread for lcores and control threads") Fixes: 770d41bf3309 ("malloc: fix allocation with unknown socket ID") Cc: stable@dpdk.org Signed-off-by: David Marchand Signed-off-by: Kaisen You --- Changes since v5: - Add comments to the code, Changes since v4: - mod the patch title, Changes since v3: - add the assignment of socket_id in thread initialization, Changes since v2: - add uncommitted local change and fix compilation, Changes since v1: - accomodate for configurations with main lcore running on multiples physical cores belonging to different numa, --- lib/eal/common/eal_common_thread.c | 4 ++++ lib/eal/common/malloc_heap.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 079a385630..d65bfe251b 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -252,6 +252,10 @@ static int ctrl_thread_init(void *arg) struct rte_thread_ctrl_params *params = arg; __rte_thread_init(rte_lcore_id(), cpuset); + /* set the value of the per-core variable _socket_id. + * Convenient for threads to find memory. + */ + RTE_PER_LCORE(_socket_id) = SOCKET_ID_ANY; params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset); if (params->ret != 0) { __atomic_store_n(¶ms->ctrl_thread_status, diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index d25bdc98f9..a624f08cf7 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -716,6 +716,12 @@ malloc_get_numa_socket(void) if (conf->socket_mem[socket_id] != 0) return socket_id; } + /* Trying to allocate memory on the main lcore numa node. + * especially when the DPDK application is started only on one numa node. + */ + socket_id = rte_lcore_to_socket_id(rte_get_main_lcore()); + if (socket_id != (unsigned int)SOCKET_ID_ANY) + return socket_id; return rte_socket_id_by_idx(0); } -- 2.25.1