From patchwork Tue Sep 12 08:20:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13381036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A976CA0EC3 for ; Tue, 12 Sep 2023 08:21:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 234A76B00C6; Tue, 12 Sep 2023 04:21:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BEA56B00C7; Tue, 12 Sep 2023 04:21:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05FA06B00C8; Tue, 12 Sep 2023 04:21:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E5CBD6B00C6 for ; Tue, 12 Sep 2023 04:21:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B5333B3F76 for ; Tue, 12 Sep 2023 08:21:32 +0000 (UTC) X-FDA: 81227251224.08.3F5D106 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by imf17.hostedemail.com (Postfix) with ESMTP id AB1634001E for ; Tue, 12 Sep 2023 08:21:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="HC/3EHTc"; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694506890; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ji7FdGjH6794Aq0s2VqnYa3aFeZerXInbOHUuNecxlM=; b=dfDGJjcGJmu5BXxiaVjW6IplPphbG9EDhEP1L+EF6ZiIJ5+LJzSreZiUNzrT1cxDKoaR16 hsL7S6deW/wGdYQ988Po7crG1xiw0lSo01zKi5UPJc1T7cw+a9KKPPDS1QGBd8BpIr8YdK s8lr7MHhmrjeeS1qMHzr+tgLZlYkP/o= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="HC/3EHTc"; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694506890; a=rsa-sha256; cv=none; b=6M3PwBn6eP9RhoNtiapKupnowrW3cdFE4kuWI7cn2C55LX8VrwOrOlozud6j3VZyxW+USA 0fDLq4AbhtZpMOHRvqUBNCfSwM8vSeF408U5xl6o0l+I1UdrSU321rEhTgn9LBwabvLHsO zO+842LmHhdAa7WnwFsdZhUUcAv6xIw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694506890; x=1726042890; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K9eyz/1vX8ET5OccsB4EUKb5BEUHSB2vczhawrkoKN4=; b=HC/3EHTcByPvk8QQgFIcboQNxBuEiKZQPbxB/OCNxRdMPho0SQ6njTMu 7IuZK18HW5meYy9wazXxZODfB9ZybiI1c/YWm8b+Lq/HyS0QS4XGc4ENx QHOPL++FyWqM8ied0izu+SAeKyyshitfe1V0PfkjheL/gAom/S+J+Si/k ylkEAIO6+HM3uKue4s56aB1BExas7FHTFvxbTzCnfAmYJkRZWO2105NkD nSIDKm18DWiaGcE/KhXHIvzvSOoc+B5+3MJwr/vKGUJ7PGmM+Ld+H3p8U ZYDy+AgKJVMUpo3ypER7B7A6y9yyhrM0Sc/FdyuETyxDJErVAsrQQlnid g==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="442323002" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="442323002" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="746787604" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="746787604" Received: from shicha9x-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.213]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:23 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Dave Jiang , Rafael J Wysocki Subject: [PATCH -V3 1/4] memory tiering: add abstract distance calculation algorithms management Date: Tue, 12 Sep 2023 16:20:58 +0800 Message-Id: <20230912082101.342002-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912082101.342002-1-ying.huang@intel.com> References: <20230912082101.342002-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AB1634001E X-Rspam-User: X-Stat-Signature: f9hwozsgh18usoh1q88b5xemimkgba9n X-Rspamd-Server: rspam01 X-HE-Tag: 1694506890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5d/dlT74IFvGetfFASMmX0C6+iXGY+Bh2rhz3t8ZsKmVftUA1+9mQW4WpjNgvPLRVQG8Ard+L5bCr6GZNNoTjPbhus//G9PxMLN1C5UrtHjMAsI5NY4rm6ysbbFCNGz//OxByaLqsRaxFhPZLMb8VRkcXWjDAirX8hoXWd1iab7mtLiUy4fmCKcEbm2yGmcwWATfyvwckG9qBgO3SJh+Zz4Zhe4GN8IDkjh2legRb47yqkKNbuDbP3JbeYlAx02Vnf+Tt6dza/JCdWJSICfQ5FsubcvkHnFL4SP3NwA1SdzNLkKDAIU0rmpwJ6pt/arQnR8vA+uqeC3pQdZr5fS8Or96/V07jqfO0dOGIf/KvkWeTiM7A+FFtxNZAHhbapMFfOzjEQbU1wo0uvKSz7UiM40Hd19 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The abstract distance may be calculated by various drivers, such as ACPI HMAT, CXL CDAT, etc. While it may be used by various code which hot-add memory node, such as dax/kmem etc. To decouple the algorithm users and the providers, the abstract distance calculation algorithms management mechanism is implemented in this patch. It provides interface for the providers to register the implementation, and interface for the users. Multiple algorithm implementations can cooperate via calculating abstract distance for different memory nodes. The preference of algorithm implementations can be specified via priority (notifier_block.priority). Signed-off-by: "Huang, Ying" Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Dave Jiang Cc: Rafael J Wysocki Reviewed-by: Dave Jiang Reviewed-by: Alistair Popple --- include/linux/memory-tiers.h | 19 ++++++++++++ mm/memory-tiers.c | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 437441cdf78f..c8382220cced 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -6,6 +6,7 @@ #include #include #include +#include /* * Each tier cover a abstrace distance chunk size of 128 */ @@ -36,6 +37,9 @@ struct memory_dev_type *alloc_memory_type(int adistance); void put_memory_type(struct memory_dev_type *memtype); void init_node_memory_type(int node, struct memory_dev_type *default_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype); +int register_mt_adistance_algorithm(struct notifier_block *nb); +int unregister_mt_adistance_algorithm(struct notifier_block *nb); +int mt_calc_adistance(int node, int *adist); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -97,5 +101,20 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int mt_calc_adistance(int node, int *adist) +{ + return NOTIFY_DONE; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 37a4f59d9585..76c0ad47a5ad 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "internal.h" @@ -105,6 +106,8 @@ static int top_tier_adistance; static struct demotion_nodes *node_demotion __read_mostly; #endif /* CONFIG_MIGRATION */ +static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms); + static inline struct memory_tier *to_memory_tier(struct device *device) { return container_of(device, struct memory_tier, dev); @@ -592,6 +595,62 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +/** + * register_mt_adistance_algorithm() - Register memory tiering abstract distance algorithm + * @nb: The notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + * + * Every memory tiering abstract distance algorithm provider needs to + * register the algorithm with register_mt_adistance_algorithm(). To + * calculate the abstract distance for a specified memory node, the + * notifier function will be called unless some high priority + * algorithm has provided result. The prototype of the notifier + * function is as follows, + * + * int (*algorithm_notifier)(struct notifier_block *nb, + * unsigned long nid, void *data); + * + * Where "nid" specifies the memory node, "data" is the pointer to the + * returned abstract distance (that is, "int *adist"). If the + * algorithm provides the result, NOTIFY_STOP should be returned. + * Otherwise, return_value & %NOTIFY_STOP_MASK == 0 to allow the next + * algorithm in the chain to provide the result. + */ +int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(register_mt_adistance_algorithm); + +/** + * unregister_mt_adistance_algorithm() - Unregister memory tiering abstract distance algorithm + * @nb: the notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + */ +int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(unregister_mt_adistance_algorithm); + +/** + * mt_calc_adistance() - Calculate abstract distance with registered algorithms + * @node: the node to calculate abstract distance for + * @adist: the returned abstract distance + * + * Return: if return_value & %NOTIFY_STOP_MASK != 0, then some + * abstract distance algorithm provides the result, and return it via + * @adist. Otherwise, no algorithm can provide the result and @adist + * will be kept as it is. + */ +int mt_calc_adistance(int node, int *adist) +{ + return blocking_notifier_call_chain(&mt_adistance_algorithms, node, adist); +} +EXPORT_SYMBOL_GPL(mt_calc_adistance); + static int __meminit memtier_hotplug_callback(struct notifier_block *self, unsigned long action, void *_arg) { From patchwork Tue Sep 12 08:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13381037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1355FCA0EC3 for ; Tue, 12 Sep 2023 08:21:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4BC46B00C8; Tue, 12 Sep 2023 04:21:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FB6B6B00C9; Tue, 12 Sep 2023 04:21:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89C946B00CA; Tue, 12 Sep 2023 04:21:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 742666B00C8 for ; Tue, 12 Sep 2023 04:21:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 42DC6160D58 for ; Tue, 12 Sep 2023 08:21:42 +0000 (UTC) X-FDA: 81227251644.02.E0DD118 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by imf06.hostedemail.com (Postfix) with ESMTP id 27492180005 for ; Tue, 12 Sep 2023 08:21:39 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CfIynwp2; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694506900; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4Fz4vk3QHijuZxzVETRChGkk6iO78maGqNxNvgVL9CY=; b=3PfSZDLXH4Dqv/XUoT3wNefaNekh1JqAO2ed25QnRotW2Z0jLNE2sxLOOR/cxxdJofpalh E4LG8l5MT8TUie9zLRm7yw+H+I/9lSrt1A/9YmxN+GcmRE3yFk2xU3vvZUNXaYbd7B1eHV adMOFM/0jsMbM0tBg+fLjkQ/OwgaiDQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CfIynwp2; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694506900; a=rsa-sha256; cv=none; b=6ZX2VppK4ukhwTnXzhMj8YhzfBdlc4sILIt2pcCpMRJMBJupdGU3Tim+7hPdkLMHEJ15hc UhXPLx89f3PFExlZLJzPjRPJvvTU2WmX3P+djg1LS1exMqdkENCSz28MDwvqMoc12YsFoJ faJWclHE5OsyF+lbVXHY1xMJ8pZ14pE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694506900; x=1726042900; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3k4HDKCDGdHFd+DzNOtZ0O6HlG4Fjz1fR7N6rjdBsuw=; b=CfIynwp2eq6AEW6Lqx9a8BKp+vncalC3ZejgmI80MDKTE59rXmXK5tU6 9MSWHRmr/Q5Deb++cZF4vqXm/X8owt7NQOyNpBEBwZYpBsiwSKyq4aC4A Ox/o4QfbIJwmWSsu2yELVbcIVCu7nkMYZYjif2NM10lI8VPs2C1DtB6ii 4zPcyGKkllP+AyrEF3Fjm9l62la2UqFRagbzKV+Bgf7Hntxxu2hsV3Lb9 pwoRrXsgu9g9v2Fq/qYbeiKqRD5u8D76v9cLmryseYrGxFUlD4g+y36Ck YRszNuLTl6CTq9YPHPBqFo+drxUXRSTQLlo1O9K0BU95zRGu3nUkgwtH3 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="442323025" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="442323025" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="746787634" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="746787634" Received: from shicha9x-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.213]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:29 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Alistair Popple , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Dave Jiang , Rafael J Wysocki Subject: [PATCH -V3 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Tue, 12 Sep 2023 16:20:59 +0800 Message-Id: <20230912082101.342002-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912082101.342002-1-ying.huang@intel.com> References: <20230912082101.342002-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 768r41rymc1uo7sbf9pg1ejsetr57ifb X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 27492180005 X-HE-Tag: 1694506899-240970 X-HE-Meta: U2FsdGVkX19TNst3w1HXlRopwUlScvqeHSBfEPnWZog/OMBqHJ5M5Y5x4CelRJC0G+qiFfTR0Z/LzI6coxFdzyGm9FVMBSyz8EZLPdF1INcG4vTMQbCOW6/cwzHNKD//Y1euNLtqXcFh5pFMm96W7WuM0JBA6WJ6OarL6dFceI/vVXCUeekSkAQVvRxpepcvreDsX9G1w6shVFDNRI2Dy4OM+7tl5L0x/eLG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Ma1Rc50Snil0C83CyKcfWX7zDUaGoUR6K/Z46y+RORf/iU+uGYDsBtAbZt2b1mIGBH/gEMIwafBGqQOvq+IR3EGDUUeiZzPH4H6kDTJ/TpL/8Hgo+dHXKmqdWSasFAMUbo0JIs/vexJEEXXqhAWJFvpYhYIUmTzKGiOgf0G7QA5Q6/+gEAcYzej7zw0Xx1IiLeqGqx0g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Previously, in hmat_register_target_initiators(), the performance attributes are calculated and the corresponding sysfs links and files are created too. Which is called during memory onlining. But now, to calculate the abstract distance of a memory target before memory onlining, we need to calculate the performance attributes for a memory target without creating sysfs links and files. To do that, hmat_register_target_initiators() is refactored to make it possible to calculate performance attributes separately. Signed-off-by: "Huang, Ying" Reviewed-by: Alistair Popple Tested-by: Alistair Popple Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Dave Jiang Cc: Rafael J Wysocki Reviewed-by: Dave Jiang --- drivers/acpi/numa/hmat.c | 81 +++++++++++++++------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index bba268ecd802..2dee0098f1a9 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -582,28 +582,25 @@ static int initiators_to_nodemask(unsigned long *p_nodes) return 0; } -static void hmat_register_target_initiators(struct memory_target *target) +static void hmat_update_target_attrs(struct memory_target *target, + unsigned long *p_nodes, int access) { - static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); struct memory_initiator *initiator; - unsigned int mem_nid, cpu_nid; + unsigned int cpu_nid; struct memory_locality *loc = NULL; u32 best = 0; - bool access0done = false; int i; - mem_nid = pxm_to_node(target->memory_pxm); + bitmap_zero(p_nodes, MAX_NUMNODES); /* - * If the Address Range Structure provides a local processor pxm, link + * If the Address Range Structure provides a local processor pxm, set * only that one. Otherwise, find the best performance attributes and - * register all initiators that match. + * collect all initiators that match. */ if (target->processor_pxm != PXM_INVAL) { cpu_nid = pxm_to_node(target->processor_pxm); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - access0done = true; - if (node_state(cpu_nid, N_CPU)) { - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + if (access == 0 || node_state(cpu_nid, N_CPU)) { + set_bit(target->processor_pxm, p_nodes); return; } } @@ -617,47 +614,10 @@ static void hmat_register_target_initiators(struct memory_target *target) * We'll also use the sorting to prime the candidate nodes with known * initiators. */ - bitmap_zero(p_nodes, MAX_NUMNODES); list_sort(NULL, &initiators, initiator_cmp); if (initiators_to_nodemask(p_nodes) < 0) return; - if (!access0done) { - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { - loc = localities_types[i]; - if (!loc) - continue; - - best = 0; - list_for_each_entry(initiator, &initiators, node) { - u32 value; - - if (!test_bit(initiator->processor_pxm, p_nodes)) - continue; - - value = hmat_initiator_perf(target, initiator, - loc->hmat_loc); - if (hmat_update_best(loc->hmat_loc->data_type, value, &best)) - bitmap_clear(p_nodes, 0, initiator->processor_pxm); - if (value != best) - clear_bit(initiator->processor_pxm, p_nodes); - } - if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, - best, 0); - } - - for_each_set_bit(i, p_nodes, MAX_NUMNODES) { - cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - } - } - - /* Access 1 ignores Generic Initiators */ - bitmap_zero(p_nodes, MAX_NUMNODES); - if (initiators_to_nodemask(p_nodes) < 0) - return; - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { loc = localities_types[i]; if (!loc) @@ -667,7 +627,7 @@ static void hmat_register_target_initiators(struct memory_target *target) list_for_each_entry(initiator, &initiators, node) { u32 value; - if (!initiator->has_cpu) { + if (access == 1 && !initiator->has_cpu) { clear_bit(initiator->processor_pxm, p_nodes); continue; } @@ -681,14 +641,33 @@ static void hmat_register_target_initiators(struct memory_target *target) clear_bit(initiator->processor_pxm, p_nodes); } if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, best, 1); + hmat_update_target_access(target, loc->hmat_loc->data_type, best, access); } +} + +static void __hmat_register_target_initiators(struct memory_target *target, + unsigned long *p_nodes, + int access) +{ + unsigned int mem_nid, cpu_nid; + int i; + + mem_nid = pxm_to_node(target->memory_pxm); + hmat_update_target_attrs(target, p_nodes, access); for_each_set_bit(i, p_nodes, MAX_NUMNODES) { cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + register_memory_node_under_compute_node(mem_nid, cpu_nid, access); } } +static void hmat_register_target_initiators(struct memory_target *target) +{ + static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); + + __hmat_register_target_initiators(target, p_nodes, 0); + __hmat_register_target_initiators(target, p_nodes, 1); +} + static void hmat_register_target_cache(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); From patchwork Tue Sep 12 08:21:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13381038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30EBFCA0ECE for ; Tue, 12 Sep 2023 08:21:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA536B00CA; Tue, 12 Sep 2023 04:21:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA99A6B00CB; Tue, 12 Sep 2023 04:21:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4A086B00CC; Tue, 12 Sep 2023 04:21:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 900C86B00CA for ; Tue, 12 Sep 2023 04:21:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4A873160D6C for ; Tue, 12 Sep 2023 08:21:46 +0000 (UTC) X-FDA: 81227251812.27.4A2FF15 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by imf06.hostedemail.com (Postfix) with ESMTP id 3792E180013 for ; Tue, 12 Sep 2023 08:21:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=J006qmvE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694506904; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5q/+10vC2vdDAokGP2vJe9GaWjpJPrct12ZNmI/Oc6Q=; b=4arZCzXt6GdkYzHBfKXg6C2EZnwYNX7s4bABJtZQqrpupN/SrAsgHFMwN3Ik1KFVJRxwlN TeQQYF3SMNDtoEStWKUIxVlhUCxPC4JPUtp6EqRbEvRYmc6yRTNeyK6rAFlIKXbSO6RqT8 1SMwUhAPmubmk0EKRkbUe2LQCriOteY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=J006qmvE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694506904; a=rsa-sha256; cv=none; b=TudGDeh9JLi9m97WJ0QylJ1u2BMUkW4/v9Mkhj4AIfOLB22euFwhHob7gP/+MlICSl0pmt Y/7IFWxPwknGuVxHVA3I95KHSOeyvNoat1WbgzxD47b83MRPA/eQhqdT/s11rjRIwynK7E RAS9qOFA7fvAd4YIjeKjSYlZWHGGqng= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694506904; x=1726042904; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ti7/r9NO/pFnQ+XqmL1xuZSvG1Zs3AoM9xj6/TDWKZ8=; b=J006qmvEKigY3L+yl+CksY78jljPOyr2VMmgxKH45aPJXi2RrrhS1V0M bgGSQ6CkNuXinvFcST+CY263hDlIwgZS6FSkmBw3EsUcAmJgPUXc77eGM UXClBo6fHbjAAfYspSsezSnmQeri11AL4ZFNHrvAWkWKgIK71SYvjTJju YiRQ+A5YNK4xZx8lGxhQTEJRt2qd4NbBFUXITf9xNWKRGaI0H5Vep6vrH F3N3NeeuQT7aLq6UGYUfr+v1z6xYrW6MDXDCZu0ufNpHZs4aN8Tcy5uVc FUOUFb64Qb49437NN2I/tXHXuUSvYmOZNcHhYtE7gwvXOAUF3D69bkyh/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="442323046" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="442323046" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="746787664" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="746787664" Received: from shicha9x-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.213]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:37 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Dave Jiang , Rafael J Wysocki Subject: [PATCH -V3 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Tue, 12 Sep 2023 16:21:00 +0800 Message-Id: <20230912082101.342002-4-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912082101.342002-1-ying.huang@intel.com> References: <20230912082101.342002-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: neqwzjyfknuisf668er6n41nqit4zmwz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3792E180013 X-HE-Tag: 1694506904-419624 X-HE-Meta: U2FsdGVkX19tZ4ZpfEN5fvXt3zarPK7OI3a5Boo0kcrrk2yQ+SPHPsIgGKtVUOrsNP4vZaC0eqag3Kb4LjOnaICfVMGHOKUqLisFrpOmUwdt6PybojFbxfknEBz8gBHxSbechoX5mYPFqusRSryGSkaknoWcSxyZ8+OgQeG+//pb82aoZd3CA/DUSJaxXcl0UyBO4QpiiQ8LGHKFvA+wJLfqIsoP/HAUcCC4C+bs9Tmsu6KpeN+ZJZxb1YTf+h0XZM1brq4bWpGv0Bv1qFhTYROOZAWMTh+71JnedLX5PBlo5aPvuxmaI1d0mTHWF0g5o8P48t/i6wh54FBZr5cXShANt4bqNNJxFaeusanmL2MdCcaPPZ07FiSybxRO7k3GhzRxDfIdH/bUKxpNDoJ6EwwU7QsHkG6ZLW1G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=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A memory tiering abstract distance calculation algorithm based on ACPI HMAT is implemented. The basic idea is as follows. The performance attributes of system default DRAM nodes are recorded as the base line. Whose abstract distance is MEMTIER_ADISTANCE_DRAM. Then, the ratio of the abstract distance of a memory node (target) to MEMTIER_ADISTANCE_DRAM is scaled based on the ratio of the performance attributes of the node to that of the default DRAM nodes. The functions to record the read/write latency/bandwidth of the default DRAM nodes and calculate abstract distance according to read/write latency/bandwidth ratio will be used by CXL CDAT (Coherent Device Attribute Table) and other memory device drivers. So, they are put in memory-tiers.c. Signed-off-by: "Huang, Ying" Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Dave Jiang Cc: Rafael J Wysocki Reviewed-by: Dave Jiang --- drivers/acpi/numa/hmat.c | 62 ++++++++++++++++++++- include/linux/memory-tiers.h | 18 ++++++ mm/memory-tiers.c | 103 ++++++++++++++++++++++++++++++++++- 3 files changed, 181 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 2dee0098f1a9..64c0810d324b 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -24,6 +24,7 @@ #include #include #include +#include static u8 hmat_revision; static int hmat_disable __initdata; @@ -759,6 +760,61 @@ static int hmat_callback(struct notifier_block *self, return NOTIFY_OK; } +static int hmat_set_default_dram_perf(void) +{ + int rc; + int nid, pxm; + struct memory_target *target; + struct node_hmem_attrs *attrs; + + if (!default_dram_type) + return -EIO; + + for_each_node_mask(nid, default_dram_type->nodes) { + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + continue; + attrs = &target->hmem_attrs[1]; + rc = mt_set_default_dram_perf(nid, attrs, "ACPI HMAT"); + if (rc) + return rc; + } + + return 0; +} + +static int hmat_calculate_adistance(struct notifier_block *self, + unsigned long nid, void *data) +{ + static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); + struct memory_target *target; + struct node_hmem_attrs *perf; + int *adist = data; + int pxm; + + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + return NOTIFY_OK; + + mutex_lock(&target_lock); + hmat_update_target_attrs(target, p_nodes, 1); + mutex_unlock(&target_lock); + + perf = &target->hmem_attrs[1]; + + if (mt_perf_to_adistance(perf, adist)) + return NOTIFY_OK; + + return NOTIFY_STOP; +} + +static struct notifier_block hmat_adist_nb __meminitdata = { + .notifier_call = hmat_calculate_adistance, + .priority = 100, +}; + static __init void hmat_free_structures(void) { struct memory_target *target, *tnext; @@ -801,6 +857,7 @@ static __init int hmat_init(void) struct acpi_table_header *tbl; enum acpi_hmat_type i; acpi_status status; + int usage; if (srat_disabled() || hmat_disable) return 0; @@ -841,7 +898,10 @@ static __init int hmat_init(void) hmat_register_targets(); /* Keep the table and structures if the notifier may use them */ - if (!hotplug_memory_notifier(hmat_callback, HMAT_CALLBACK_PRI)) + usage = !hotplug_memory_notifier(hmat_callback, HMAT_CALLBACK_PRI); + if (!hmat_set_default_dram_perf()) + usage += !register_mt_adistance_algorithm(&hmat_adist_nb); + if (usage) return 0; out_put: hmat_free_structures(); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index c8382220cced..9d27ca3b143e 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -31,8 +31,11 @@ struct memory_dev_type { struct kref kref; }; +struct node_hmem_attrs; + #ifdef CONFIG_NUMA extern bool numa_demotion_enabled; +extern struct memory_dev_type *default_dram_type; struct memory_dev_type *alloc_memory_type(int adistance); void put_memory_type(struct memory_dev_type *memtype); void init_node_memory_type(int node, struct memory_dev_type *default_type); @@ -40,6 +43,9 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype); int register_mt_adistance_algorithm(struct notifier_block *nb); int unregister_mt_adistance_algorithm(struct notifier_block *nb); int mt_calc_adistance(int node, int *adist); +int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, + const char *source); +int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -64,6 +70,7 @@ static inline bool node_is_toptier(int node) #else #define numa_demotion_enabled false +#define default_dram_type NULL /* * CONFIG_NUMA implementation returns non NULL error. */ @@ -116,5 +123,16 @@ static inline int mt_calc_adistance(int node, int *adist) { return NOTIFY_DONE; } + +static inline int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, + const char *source) +{ + return -EIO; +} + +static inline int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist) +{ + return -EIO; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 76c0ad47a5ad..fa1a8b418f9a 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -37,7 +37,7 @@ struct node_memory_type_map { static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); static struct node_memory_type_map node_memory_types[MAX_NUMNODES]; -static struct memory_dev_type *default_dram_type; +struct memory_dev_type *default_dram_type; static struct bus_type memory_tier_subsys = { .name = "memory_tiering", @@ -108,6 +108,11 @@ static struct demotion_nodes *node_demotion __read_mostly; static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms); +static bool default_dram_perf_error; +static struct node_hmem_attrs default_dram_perf; +static int default_dram_perf_ref_nid = NUMA_NO_NODE; +static const char *default_dram_perf_ref_source; + static inline struct memory_tier *to_memory_tier(struct device *device) { return container_of(device, struct memory_tier, dev); @@ -595,6 +600,102 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +static void dump_hmem_attrs(struct node_hmem_attrs *attrs, const char *prefix) +{ + pr_info( +"%sread_latency: %u, write_latency: %u, read_bandwidth: %u, write_bandwidth: %u\n", + prefix, attrs->read_latency, attrs->write_latency, + attrs->read_bandwidth, attrs->write_bandwidth); +} + +int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, + const char *source) +{ + int rc = 0; + + mutex_lock(&memory_tier_lock); + if (default_dram_perf_error) { + rc = -EIO; + goto out; + } + + if (perf->read_latency + perf->write_latency == 0 || + perf->read_bandwidth + perf->write_bandwidth == 0) { + rc = -EINVAL; + goto out; + } + + if (default_dram_perf_ref_nid == NUMA_NO_NODE) { + default_dram_perf = *perf; + default_dram_perf_ref_nid = nid; + default_dram_perf_ref_source = kstrdup(source, GFP_KERNEL); + goto out; + } + + /* + * The performance of all default DRAM nodes is expected to be + * same (that is, the variation is less than 10%). And it + * will be used as base to calculate the abstract distance of + * other memory nodes. + */ + if (abs(perf->read_latency - default_dram_perf.read_latency) * 10 > + default_dram_perf.read_latency || + abs(perf->write_latency - default_dram_perf.write_latency) * 10 > + default_dram_perf.write_latency || + abs(perf->read_bandwidth - default_dram_perf.read_bandwidth) * 10 > + default_dram_perf.read_bandwidth || + abs(perf->write_bandwidth - default_dram_perf.write_bandwidth) * 10 > + default_dram_perf.write_bandwidth) { + pr_info( +"memory-tiers: the performance of DRAM node %d mismatches that of the reference\n" +"DRAM node %d.\n", nid, default_dram_perf_ref_nid); + pr_info(" performance of reference DRAM node %d:\n", + default_dram_perf_ref_nid); + dump_hmem_attrs(&default_dram_perf, " "); + pr_info(" performance of DRAM node %d:\n", nid); + dump_hmem_attrs(perf, " "); + pr_info( +" disable default DRAM node performance based abstract distance algorithm.\n"); + default_dram_perf_error = true; + rc = -EINVAL; + } + +out: + mutex_unlock(&memory_tier_lock); + return rc; +} + +int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist) +{ + if (default_dram_perf_error) + return -EIO; + + if (default_dram_perf_ref_nid == NUMA_NO_NODE) + return -ENOENT; + + if (perf->read_latency + perf->write_latency == 0 || + perf->read_bandwidth + perf->write_bandwidth == 0) + return -EINVAL; + + mutex_lock(&memory_tier_lock); + /* + * The abstract distance of a memory node is in direct proportion to + * its memory latency (read + write) and inversely proportional to its + * memory bandwidth (read + write). The abstract distance, memory + * latency, and memory bandwidth of the default DRAM nodes are used as + * the base. + */ + *adist = MEMTIER_ADISTANCE_DRAM * + (perf->read_latency + perf->write_latency) / + (default_dram_perf.read_latency + default_dram_perf.write_latency) * + (default_dram_perf.read_bandwidth + default_dram_perf.write_bandwidth) / + (perf->read_bandwidth + perf->write_bandwidth); + mutex_unlock(&memory_tier_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(mt_perf_to_adistance); + /** * register_mt_adistance_algorithm() - Register memory tiering abstract distance algorithm * @nb: The notifier block which describe the algorithm From patchwork Tue Sep 12 08:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13381039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8693CA0ECA for ; Tue, 12 Sep 2023 08:21:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 766146B00CC; Tue, 12 Sep 2023 04:21:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 715BC6B00CD; Tue, 12 Sep 2023 04:21:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B9246B00CE; Tue, 12 Sep 2023 04:21:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 46FCF6B00CC for ; Tue, 12 Sep 2023 04:21:52 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2F955B3F6B for ; Tue, 12 Sep 2023 08:21:52 +0000 (UTC) X-FDA: 81227252064.17.CE0A853 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by imf06.hostedemail.com (Postfix) with ESMTP id 05228180005 for ; Tue, 12 Sep 2023 08:21:49 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nlKfgHNN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694506910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9UXPZ2hd8r/D2KCGsv3BU7JBNJRwGcw5KD/mPjMQNGY=; b=YIceLKffHZJyqe981EePAhZ7Il8wve2w5tnDiJhCxXHAajLh3yV7vPN4WyeaeFQYtEhafO imJxDujYSCjm7M1qXQvRxadhwpDR3Zv/KKKpymD5jSITMBPcTGmRqfjVfdFMNoOjcW78kE LwK0RxGrOroJNrAVqZXgAAeF6g64JSo= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nlKfgHNN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694506910; a=rsa-sha256; cv=none; b=uW2nM3mxfcNow8/UvZsmDaNKYk51L0m2R/169MbpJNf9plnNsG/MYGRgW1nYvSsLyauBev DtIqEOmz9DBc/oASPbKwQMjOzYfWGmT5llIs2NhLA1Rk5AZvWi0PSjIMfEgD9wSi/BRjti DFyJ/CpiLSVeEjuohAJzZi0/+Yfmfo4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694506910; x=1726042910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9suKmuHrRCqPZ954lWyRT88cx6w5DPJyIVkc7QOTcgM=; b=nlKfgHNN2yjYd+JSBfblqYI0tlgp4pYpGErSdSxN5hAeAXmwLxn88gHd ag+5/Twv8Dwkm+RSJDiOq5QgAcaUqj5GdtqkglJLgtBILKTS682BoEK+q AJjBfbvc8ATKGAUBDwG8dL+Oh6p/jFaf5E0EPxBdxQyn0qrg61Xhl6UiQ 24a70staTdUHL3UG27NBUJyy5BEKeS7Ji4YFXxc7PNWjFIeHOHt0g4Q0i Wirv7z7Z2jNd8SrPilF0h+F/ztHf0jjPbpD51hiV/3nR9lzrMrg+VUkuy SqjaUqU7sErYzKUirIVftIawOiVAF4ZbB9OmvDY3cAT4OAZf+yLIB0rAp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="442323077" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="442323077" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="746787712" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="746787712" Received: from shicha9x-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.213]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:43 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Dave Jiang , Rafael J Wysocki Subject: [PATCH -V3 4/4] dax, kmem: calculate abstract distance with general interface Date: Tue, 12 Sep 2023 16:21:01 +0800 Message-Id: <20230912082101.342002-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912082101.342002-1-ying.huang@intel.com> References: <20230912082101.342002-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: bzc6759i1mih664tp1ar9nyxa55wd71p X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 05228180005 X-HE-Tag: 1694506909-549709 X-HE-Meta: U2FsdGVkX1+vWsLM7b/CNNuGm489/lDuL2PBaNmu7Ia9m1MYyzqlLafF9Ehi2OgOwqf77ivkvLbS1hjle2az2LkkzPjUbfJQClqJs0GTJ2OB1HLXknfrkmh2pHo4xlWj+vneaVg0VotYj8OegFuG26W6o/bFfV5fEzsXWGeouXiyGbZaefrMqtr3fwLoQHJySV7Cfl8zsmopEnglDmOOJgUhLzndins730dVJliNsGK/DJx8O+bQFl89jHLKUcgsVKNCm8id9Qikyf19ojNWTk3ckT73+7YqY8u2oIK5pdOhEuR9b4iNuxNZC0E8AH/QG9grV75SlMpPlcprKlZN6KSX2bBefHS0eFxeKVlZzlsp+EMKwt0bh15GM/N96Uj9JDh7w+W6M9lpkctGdxUOoLRNx3MKUcwdYn6MUr9PX91AGLYKvCwjMN9fC3L8r3ry8qKx8dS09hrJZooUPYKAFYy5zlaczyx7Rk9zvcZV/l1vYfCagqJFiQjzVMdXUYzWxM8UbDAbDz+fME5ocoabzJE6o2gZoZorjkOOplCpyNaTZl+63t42drCRi/w6cTJzVytels0GYwDmPzPuvpM4YXsXxA2o0CurfMS5EWztmb3eYGp5DGzsBQPht3tXd4EhrEuLYm9SXXv9I2eStDf+5mhzsI0qFjR30mp0omXww7bMZPwfa2cx7je37c+DSMcwFLqhseUziqKsBrlN1kNGKkkkRQ5Mz95EXEKohHsd3A6Dn2mDmSOJD9ZhWGJfajm8+t4WXIqSzAOjZiQ1Pyd0s2bRmsIySmvKPSEGzjzf3vd5ZumHP9VqND+F5TDhzFvXWsXikwwRwerXD5Vg/N9JiLWYDhulZWu4pNRAZ2ZFsQOzNg4mwZgnrpZmNCOzIwu4o06bWRagcRTcxUaWSa/9wZ8qZvIuorMnkJwubuwtDUeRcMosOgFBnb9JTnGTX1ZHWxbDoXv9VUpgvhhHTwE /oEWuMat DWBQJPv0+f3ORS0L7My5m9tZVAk+xoEf8oOp7bVxeLlQdvHtmD2AuAy+TZGjQfpAbuOHyGPhOtcDkcndY/NBofRgoVaD43y+ZnHkvvEFXth3fWKj37u7qrvRTklAYqb04/NGP9A0+wOqwDUzTFZe7n9Zxdi9WSdjF7FppETHGGIc9Ydt9l7uVHDVHRb6tr3FQ1/NPiKHmjbMaUp/D4k+LemXZ/fNYxWwxRR9HFiBdsxKjMYVp9q0twQjtODHjBLtIU+BCxfj7PxsvDzufeTGMtEhRL2+ZgEFCWgOKdbPksxNBCnEP4cNtBP3oK0afz/R7FL4JlrAgfWOiUFAqi6dpukziai8H4uy3skktxy/1nzuUyGdOH76rJplBma0AR+clRtmmd1Kfs1yKqfdurH10kaVwBnq/ZMS7wMKDSZeZ1r+BZhsqVciO9Ur9V0BVr4qwdFEsebtW+LpUiqbOiyt/rX19HXjcuKGd2QJw X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Previously, a fixed abstract distance MEMTIER_DEFAULT_DAX_ADISTANCE is used for slow memory type in kmem driver. This limits the usage of kmem driver, for example, it cannot be used for HBM (high bandwidth memory). So, we use the general abstract distance calculation mechanism in kmem drivers to get more accurate abstract distance on systems with proper support. The original MEMTIER_DEFAULT_DAX_ADISTANCE is used as fallback only. Now, multiple memory types may be managed by kmem. These memory types are put into the "kmem_memory_types" list and protected by kmem_memory_type_lock. Signed-off-by: "Huang, Ying" Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Dave Jiang Cc: Rafael J Wysocki Reviewed-by: Dave Jiang --- drivers/dax/kmem.c | 62 ++++++++++++++++++++++++++++-------- include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 2 +- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index c57acb73e3db..369c698b7706 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -49,14 +49,52 @@ struct dax_kmem_data { struct resource *res[]; }; -static struct memory_dev_type *dax_slowmem_type; +static DEFINE_MUTEX(kmem_memory_type_lock); +static LIST_HEAD(kmem_memory_types); + +static struct memory_dev_type *kmem_find_alloc_memory_type(int adist) +{ + bool found = false; + struct memory_dev_type *mtype; + + mutex_lock(&kmem_memory_type_lock); + list_for_each_entry(mtype, &kmem_memory_types, list) { + if (mtype->adistance == adist) { + found = true; + break; + } + } + if (!found) { + mtype = alloc_memory_type(adist); + if (!IS_ERR(mtype)) + list_add(&mtype->list, &kmem_memory_types); + } + mutex_unlock(&kmem_memory_type_lock); + + return mtype; +} + +static void kmem_put_memory_types(void) +{ + struct memory_dev_type *mtype, *mtn; + + mutex_lock(&kmem_memory_type_lock); + list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) { + list_del(&mtype->list); + put_memory_type(mtype); + } + mutex_unlock(&kmem_memory_type_lock); +} + static int dev_dax_kmem_probe(struct dev_dax *dev_dax) { struct device *dev = &dev_dax->dev; unsigned long total_len = 0; struct dax_kmem_data *data; + struct memory_dev_type *mtype; int i, rc, mapped = 0; int numa_node; + int adist = MEMTIER_DEFAULT_DAX_ADISTANCE; /* * Ensure good NUMA information for the persistent memory. @@ -71,6 +109,11 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } + mt_calc_adistance(numa_node, &adist); + mtype = kmem_find_alloc_memory_type(adist); + if (IS_ERR(mtype)) + return PTR_ERR(mtype); + for (i = 0; i < dev_dax->nr_range; i++) { struct range range; @@ -88,7 +131,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } - init_node_memory_type(numa_node, dax_slowmem_type); + init_node_memory_type(numa_node, mtype); rc = -ENOMEM; data = kzalloc(struct_size(data, res, dev_dax->nr_range), GFP_KERNEL); @@ -167,7 +210,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) err_res_name: kfree(data); err_dax_kmem_data: - clear_node_memory_type(numa_node, dax_slowmem_type); + clear_node_memory_type(numa_node, mtype); return rc; } @@ -219,7 +262,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax) * for that. This implies this reference will be around * till next reboot. */ - clear_node_memory_type(node, dax_slowmem_type); + clear_node_memory_type(node, NULL); } } #else @@ -251,12 +294,6 @@ static int __init dax_kmem_init(void) if (!kmem_name) return -ENOMEM; - dax_slowmem_type = alloc_memory_type(MEMTIER_DEFAULT_DAX_ADISTANCE); - if (IS_ERR(dax_slowmem_type)) { - rc = PTR_ERR(dax_slowmem_type); - goto err_dax_slowmem_type; - } - rc = dax_driver_register(&device_dax_kmem_driver); if (rc) goto error_dax_driver; @@ -264,8 +301,7 @@ static int __init dax_kmem_init(void) return rc; error_dax_driver: - put_memory_type(dax_slowmem_type); -err_dax_slowmem_type: + kmem_put_memory_types(); kfree_const(kmem_name); return rc; } @@ -275,7 +311,7 @@ static void __exit dax_kmem_exit(void) dax_driver_unregister(&device_dax_kmem_driver); if (!any_hotremove_failed) kfree_const(kmem_name); - put_memory_type(dax_slowmem_type); + kmem_put_memory_types(); } MODULE_AUTHOR("Intel Corporation"); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 9d27ca3b143e..ab6651402d7e 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -24,6 +24,8 @@ struct memory_tier; struct memory_dev_type { /* list of memory types that are part of same tier as this type */ struct list_head tier_sibiling; + /* list of memory types that are managed by one driver */ + struct list_head list; /* abstract distance for this specific memory type */ int adistance; /* Nodes of same abstract distance */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index fa1a8b418f9a..ca68ef17554b 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -586,7 +586,7 @@ EXPORT_SYMBOL_GPL(init_node_memory_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype) { mutex_lock(&memory_tier_lock); - if (node_memory_types[node].memtype == memtype) + if (node_memory_types[node].memtype == memtype || !memtype) node_memory_types[node].map_count--; /* * If we umapped all the attached devices to this node,