From patchwork Wed Aug 16 08:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13354644 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 98BA2C001DF for ; Wed, 16 Aug 2023 08:00:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E76E28000F; Wed, 16 Aug 2023 04:00:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1978F8D0021; Wed, 16 Aug 2023 04:00:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0371228000F; Wed, 16 Aug 2023 04:00:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E4D728D0021 for ; Wed, 16 Aug 2023 04:00:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9DC5A1A0E58 for ; Wed, 16 Aug 2023 08:00:53 +0000 (UTC) X-FDA: 81129221586.11.69A2AD3 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf25.hostedemail.com (Postfix) with ESMTP id D8A79A0021 for ; Wed, 16 Aug 2023 08:00:49 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EC96gV75; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 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=1692172850; 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=bMi8kwv5PwRwtKD94IS03m8QJZf3Yln7zhQx3eNqK00=; b=pxyRYPPzIO1B/qlfn0iiSjqjWsKCL1NyAYPCUJg9MIcyxW+YfAZ+nSF1H5ljV3znM0ZSHf HER77Grp6MVWyoOPgYcm/PF0DwXQWb3dJwq08w4ankQvtaeIez7xNscEl80C/a8NsVpSUx NVN1VbYTnVGaFHsv5a6E6GOQ14wkHVA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EC96gV75; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692172850; a=rsa-sha256; cv=none; b=mH3Q99ziNrJkYXoQv6bHXEv9uDnvq1GcKrlDIbPm54vyx4UBnjCrbagUNk+gDZ7g9wUlSj HBRz1rT8KLeav5z1mI5qwCsmnHj9JZPLGu59zNNjnfPp5MM4PrYU/LgpqCrYOQfhtvxDuG 67T2YvY6PG107wcUadRQba731/3IGqE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692172849; x=1723708849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=981so79sA8EfMDrE64ZhtP9K9RrUiad1BJbeNjjyXCc=; b=EC96gV75kr38IixpOpyTzs3fcAR3lhlhqD+XY11Om1SQ8OLFR+1GuQ2i DyaBzxW10BZRBiisVoV+BQaw5W+MmnJTmKYs+A6OaX50iKxbIE0e9p9SG mzaW31WBSwpgZMWWFKfzFb9K2s7lNzQ2OF81nLBMsTAWmm/TCiv66tMa9 aVi0KcGj9jcs7b2vUwDr92DJ9Nd8UpuzZWF9vs0jon/Rpl7jiBx5LnSvu T1yj/UzGRpBanh4N7WT3+VEDd/3gS1GHKBqQbzlCjKjoPfbn6GAbTenbP BAojkf6oLjg1XOVLP4dnlfcj8Y8V7gW5OQQvgPmxru4PBJz8Y96iB7yyB w==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="352058159" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="352058159" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="804112793" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="804112793" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:42 -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 , Rafael J Wysocki Subject: [PATCH -V2 1/4] memory tiering: add abstract distance calculation algorithms management Date: Wed, 16 Aug 2023 16:00:21 +0800 Message-Id: <20230816080024.105554-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816080024.105554-1-ying.huang@intel.com> References: <20230816080024.105554-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D8A79A0021 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t4pdnkdcdas87zibra18xyc7tiuusfng X-HE-Tag: 1692172849-72452 X-HE-Meta: U2FsdGVkX18YwzltgrLpv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kfaKIdimgLsEPbpBrXea+/ywbqnXyVE1QuzR8gMDCat1ku5FhkIg/Q1tT9/N5pM8snAS0RyhonRvSJycv+iaNPPe3joryFggGWS0bSbrLENksQJ0zeLpRRYKUAMiiy8eynivGea9lSvWN/jzl1iMfQ9yOsvIqmUacIE3nui5B690aeXUGzyMS5P+2fUuQIfrNLRjC5g1gJ3lTAIMcrPig0BGZ/bp4iwGXBZwRT9vQ7f+/Nwf8mu7G9JZw9Wdef8NrbWKvd5CaYL65AAqCRX2LN/mTyBoGVPUf8yem4L5G7fdY4MnZmF9iPD+1pB2bbUrQQI5XQ+Rwqq6Y4rJb/8ivqmYIkLT2W5wAbKyga9ybgq5UO1 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: Rafael J Wysocki --- 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 fc9647b1b4f9..c6429e624244 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 destroy_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 a516e303e304..1e55fbe2ad51 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 Wed Aug 16 08:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13354645 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 15DC0C001B0 for ; Wed, 16 Aug 2023 08:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FCDC280010; Wed, 16 Aug 2023 04:00:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ACBC8D0021; Wed, 16 Aug 2023 04:00:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FF42280010; Wed, 16 Aug 2023 04:00:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6D31F8D0021 for ; Wed, 16 Aug 2023 04:00:56 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 333F680E54 for ; Wed, 16 Aug 2023 08:00:56 +0000 (UTC) X-FDA: 81129221712.29.E367E34 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf25.hostedemail.com (Postfix) with ESMTP id D642FA0024 for ; Wed, 16 Aug 2023 08:00:53 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QIRehXCx; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 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=1692172854; 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=ple2qLF/9v262kzXhtyYsZdZGNZwi86M+XBmt7iXJls=; b=jPqRE1rxd95pbj70yZfNGdg+i0PUrwxA2+pyqXVp/+6GnNKuAxqjKIWmRVNvyjC8CeSc9D HM1SyTuLvtD9mYwBZ7+2w4CbG8+k8IkyUpjeRQkjiGJ/waolJl3ekGuXR1gzqE92nkeaFe IhbnlVaCQsYhlZ/FGH1esifbi+rY6JY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QIRehXCx; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692172854; a=rsa-sha256; cv=none; b=C8WNC1thxjxHBE35hzdNfJ2XU63qAd8U6u86aPFfEobCjSf+eez0riWosNXcFE2ew7viNS bXaYrkRX6SZifGy/GQ+kjErsJvlzCmy6rnLAzNe3aTDkOypOtcDy8EQSEFKE4V/FjJNklE 0h24aXMRAvXTZ1vnki53mfngW5EdQuA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692172853; x=1723708853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+UQwwd17z7WFVjrXjNbRVmdJdagQCRgAkM7c4A6D7Rs=; b=QIRehXCx+/GfPIBqWW+LWSOerucPpmd4FDPuymQLnRb12zJz36Qhw69K yr5628K7aCpxV5MHmWtJWaps3D7EIyr/gWLJzOfSb2a+/Dx/S6heywow4 dtFA3sGnQ9dRwkFQYTBQTZRAHdcwDm7D2M7sNkxA/JVbfn+vSUmk+Sz79 thYeRMU/M8avqIvo/RUJ7iPPjnMi1PTPYLetZRLGthk7JfZjVjBhxt4Wk dynpu3sDL7AJIJsdfi1icpCBZJXd7wCvLzVFqcB4BPvOR53X1d2YAsNva CDhS2a3K5ypoBnfQU970ryPkCl0KURXIYHZtWAfwoCMeVyu03upzjlCze w==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="352058170" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="352058170" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="804112799" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="804112799" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:46 -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 , Rafael J Wysocki Subject: [PATCH -V2 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Wed, 16 Aug 2023 16:00:22 +0800 Message-Id: <20230816080024.105554-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816080024.105554-1-ying.huang@intel.com> References: <20230816080024.105554-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D642FA0024 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ey38hwqu5c53s31aki79xgsjuk65hadq X-HE-Tag: 1692172853-350022 X-HE-Meta: U2FsdGVkX1/4h3nQJIgJVgyLb+65OMRS6WFYnqBxNfCds3xGaHQdbVjJSFIwLuPlaSau/2Q75Hr9QfYQnI1GOpMLWXGF6gzYTmHFH46gSq2XP9ByCHSHtX0ZxdHexFjRdTbtSgQYTaTGz1M4FLqjqfaGffv4O2FtE1yq3LiRNuYSZiSruO2AhmkYX/XH4GiaTvF7meWESRgmWeLYDeS7q5o1I2JFmRspFtevG9f3gBaRMnx9ay9GxZb6+yeuuh3EBkXllc1XmZGIKsICJdBdaKAgN7+o0+prNf3uA7ugQl0pxY/J4TeF8FdhA1WDIVLqAXgRIOgsMd+Auh2zMtd/aWr1t+SekOps8UzKd9tUBHPdjgZtJMf56Y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F/lnHIGKGLuKcyCSNBWW0ZFQV7uMqM90+iW0wsHOs//t4fQ= 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: Rafael J Wysocki --- 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 Wed Aug 16 08:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13354646 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 2DCB7C001DF for ; Wed, 16 Aug 2023 08:00:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3645280011; Wed, 16 Aug 2023 04:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE5A08D0021; Wed, 16 Aug 2023 04:00:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 914F5280011; Wed, 16 Aug 2023 04:00:58 -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 7BBBD8D0021 for ; Wed, 16 Aug 2023 04:00:58 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 35C27140E50 for ; Wed, 16 Aug 2023 08:00:58 +0000 (UTC) X-FDA: 81129221796.21.21CA365 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf25.hostedemail.com (Postfix) with ESMTP id 1D320A0009 for ; Wed, 16 Aug 2023 08:00:55 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ye4HndDs; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 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=1692172856; 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=7TQYdF6jynsjCMEBUA9q8WwQNgD8G0shT5J2hqS62VA=; b=ZnC6h6zb26knrJrvzXweP2r1M1twgEBYNK7LUP59VtQFLfXd09UJAjtn0luyUj6p3GIjRh 4reZVJN1S5XpOL5GbceWgtCAeDA5RJHWqFXscN546vUj6x8OEyPwTbmc9GvYx0TwNk62qy irG7Fwr/MEpFPqu/b4QmX3iGgURWCFI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Ye4HndDs; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692172856; a=rsa-sha256; cv=none; b=SbXBS22ZM9AWafiqOXcUh6r1bQJNh2C7+vodInlipg/P05KW++a90xkGtm5bUsCaX0ChWv Qc635EOMELwC34HiFgwybT4wxD6pZcKBBZEai2vYovFKg+YZik8S2+Jh7spzVlPSPq9JuW vGSxs4HymjBRdAAmtigHNnO3472cYpI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692172856; x=1723708856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PAXiM4QxwflvtLeQyOXin3qRlOkgjmcYey5dyC3C20E=; b=Ye4HndDsC92TXF4bIu6CkxVw1j4fXyUWq1dsJRTzcZUHBra4fpN4HJAf 88eSM4F/l7WiKUQt3/3kUrZaL0lSNZRjMzMYhPgIv9/DFgxkqm06nuHYJ GbrIby9ktGkCijsJWIn3S/iLSq4zrooyv0H6BBMgKOag2O+OZAzamdpd3 TumR2aYEm6/UvGgaQxs5Guq61phJVxO19YPZFyzPmN5eoi/5xXyw0hE8f Qja4d7L7dmUReBEqXEZTBHkWMSPkA8YTk84BGPmL9F+j+K/ZRuEj5pQfC Yqj4qGQdtDLAOT60nJYs7qdZEjaxCAfgjljE7AUT4eqraXVTwKfrqv6U6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="352058196" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="352058196" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="804112805" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="804112805" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:49 -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 , Rafael J Wysocki Subject: [PATCH -V2 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Wed, 16 Aug 2023 16:00:23 +0800 Message-Id: <20230816080024.105554-4-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816080024.105554-1-ying.huang@intel.com> References: <20230816080024.105554-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1D320A0009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4fm3z8cso5kube7fsnrbhb86jzzdnhf6 X-HE-Tag: 1692172855-284902 X-HE-Meta: U2FsdGVkX19qBQZ8aX1tbRu+1s4H3ksi8L32MPE7pgnygIFRIWXrr4c2JDMI1WqpMjh+2zYYadxzJLhy1i3WfDMd0o/ntoQ1sNj78MXF9O+OLJ9pBDCoqqQvYWG8WfQM+i/zgOIZIe5JPQehINKoRDUqLIq62j2N5fRk2WhTcHiBwSwBCoqXeLA9X2EbDnz/4QPV7bskLetE/kPLmnxO9Vvd+deyCf5/9sAMeLJGoFAtPpRdIfHNMTc8o7y+wUiNuGuzHUSlaRZ7HkKrQt6BNGCl/azazXkz9OtGppVwctqeWhzHBLF/m71+le74aeQBNcnwvlImxyn1scML+YEanuOhL4dBtfJolGiWD0Ud01gpPBMyxjwtCirglb/9EZNm2+IOWrv46QTn2+wa8OQH6m7oYxpStcVU9MvPg8THXk1V03iT+FchV40yWYibWbyf74HrxLbqNF6cCVUGXAnpoZ6fooI5iLJ6FHjguZVoWX0e1StN8UgpVbLyY+6JrbU+JSupXq5om+0m6sY3X7rtNTN0PPZPBzGwsl65/4CqhWQGPQsi7WcqPINPZQGSBvp+0QPs4sdkp71qOeLj/Y1w8IL0bioAi/EKw+p98MWYHml78sd38wDiDEQtVWcAhZsaobDhUrmuV45hiTlpp2CntGU5LyNnVn2sQ/U6OGtsn52tCpDXn3AbJNRiUa/nEyXYN/c0LCgbBHCT0sw3z0g1BM6n6DeIdLe+Hlz7RF8ShkPbRPNlq1CegQLjbXZetluk/gTsMj2JlahiJrYtjiZ3Z4OJTJjPCnjOJkbskSTMvsa9ADR/hpjseELmnle7KRw4/vNAbNDvfGx5TAZP2D1/0sgn6jrL1TEciKPyrqf5LHQftb583WVPG3mSKPvuPqJwoxZpgcpgEBXQh+7HV3zxozLfL+MRRl9QEydKpKzvD6EjNMhWXUrZeickcouhbBNHW1dgroIbl+8IFZCuRRP Cjigtgw+ 9TqeM/sI05VNOH7u340G5XWIC5kyrm5uPqRnqKXK+1wLaGU+AajbksaoO/f0L3UMiN8R62+HtC4zkecds3PC9WbaYvnpzLdDjNSBKE3Iw+gOPBAZaFevaDVMni4FhhiYo3b/UicN+3vpO+skOagR6bwG6ihGVakejRhgTxtOxcbzn+cLCl9RPgDjpLRpdBNCWEevS/pqCYRrEsOAv28EfwkjBk/ZV6zdeDIaxNkTajvzPZohosER1S26YKSMBps8kgdGhwSzjfgvB1X39Bxf+xlRUt97er0kQunNE9FqZBA3JGYeV4PYdvS13+ii7Vu7YJ8Va8NrFIcAlMk6G5WeEi3l+uAuVT0E1vT9C3j7PmTB9aA8S0dJ7QhNY1eeotCl6tl1Mq2bU8qLtLb6VuQITXVdknXpYbpuZLuHVy3SvipO6OKhZ1AKdTIa1SRWLovekVepduMsUOOTCYnOmn/w1bEoUGGk3u4sjlxRD 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: 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. 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: Rafael J Wysocki --- drivers/acpi/numa/hmat.c | 137 ++++++++++++++++++++++++++++++++++- include/linux/memory-tiers.h | 2 + mm/memory-tiers.c | 2 +- 3 files changed, 139 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 2dee0098f1a9..02114b376618 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,136 @@ static int hmat_callback(struct notifier_block *self, return NOTIFY_OK; } +static int hmat_adistance_disabled; +static struct node_hmem_attrs default_dram_attrs; + +static void dump_hmem_attrs(struct node_hmem_attrs *attrs) +{ + pr_cont("read_latency: %u, write_latency: %u, read_bandwidth: %u, write_bandwidth: %u\n", + attrs->read_latency, attrs->write_latency, + attrs->read_bandwidth, attrs->write_bandwidth); +} + +static void disable_hmat_adistance_algorithm(void) +{ + hmat_adistance_disabled = true; +} + +static int hmat_init_default_dram_attrs(void) +{ + struct memory_target *target; + struct node_hmem_attrs *attrs; + int nid, pxm; + int nid_dram = NUMA_NO_NODE; + + if (default_dram_attrs.read_latency + + default_dram_attrs.write_latency != 0) + return 0; + + 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]; + if (nid_dram == NUMA_NO_NODE) { + if (attrs->read_latency + attrs->write_latency == 0 || + attrs->read_bandwidth + attrs->write_bandwidth == 0) { + pr_info("hmat: invalid hmem attrs for default DRAM node: %d,\n", + nid); + pr_info(" "); + dump_hmem_attrs(attrs); + pr_info(" disable hmat based abstract distance algorithm.\n"); + disable_hmat_adistance_algorithm(); + return -EIO; + } + nid_dram = nid; + default_dram_attrs = *attrs; + continue; + } + + /* + * 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(attrs->read_latency - default_dram_attrs.read_latency) * 10 > + default_dram_attrs.read_latency || + abs(attrs->write_latency - default_dram_attrs.write_latency) * 10 > + default_dram_attrs.write_latency || + abs(attrs->read_bandwidth - default_dram_attrs.read_bandwidth) * 10 > + default_dram_attrs.read_bandwidth) { + pr_info("hmat: hmem attrs for DRAM nodes mismatch.\n"); + pr_info(" node %d: ", nid_dram); + dump_hmem_attrs(&default_dram_attrs); + pr_info(" node %d: ", nid); + dump_hmem_attrs(attrs); + pr_info(" disable hmat based abstract distance algorithm.\n"); + disable_hmat_adistance_algorithm(); + return -EIO; + } + } + + 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 *attrs; + int *adist = data; + int pxm; + + if (hmat_adistance_disabled) + return NOTIFY_OK; + + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + return NOTIFY_OK; + + if (hmat_init_default_dram_attrs()) + return NOTIFY_OK; + + mutex_lock(&target_lock); + hmat_update_target_attrs(target, p_nodes, 1); + mutex_unlock(&target_lock); + + attrs = &target->hmem_attrs[1]; + + if (attrs->read_latency + attrs->write_latency == 0 || + attrs->read_bandwidth + attrs->write_bandwidth == 0) + return NOTIFY_OK; + + /* + * 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 * + (attrs->read_latency + attrs->write_latency) / + (default_dram_attrs.read_latency + + default_dram_attrs.write_latency) * + (default_dram_attrs.read_bandwidth + + default_dram_attrs.write_bandwidth) / + (attrs->read_bandwidth + attrs->write_bandwidth); + + 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 +932,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,8 +973,11 @@ 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); + usage += !register_mt_adistance_algorithm(&hmat_adist_nb); + if (usage) return 0; + out_put: hmat_free_structures(); acpi_put_table(tbl); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index c6429e624244..9377239c8d34 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -33,6 +33,7 @@ struct memory_dev_type { #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 destroy_memory_type(struct memory_dev_type *memtype); void init_node_memory_type(int node, struct memory_dev_type *default_type); @@ -64,6 +65,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. */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 1e55fbe2ad51..9a734ef2edfb 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", From patchwork Wed Aug 16 08:00:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13354647 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 4C41CC04A94 for ; Wed, 16 Aug 2023 08:01:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D84E7280012; Wed, 16 Aug 2023 04:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2EAA8D0021; Wed, 16 Aug 2023 04:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA932280012; Wed, 16 Aug 2023 04:01:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A674A8D0021 for ; Wed, 16 Aug 2023 04:01:00 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7ED181A0E63 for ; Wed, 16 Aug 2023 08:01:00 +0000 (UTC) X-FDA: 81129221880.15.216A35F Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf25.hostedemail.com (Postfix) with ESMTP id 59CCBA0009 for ; Wed, 16 Aug 2023 08:00:58 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NWuvSm3E; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 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=1692172858; 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=/J3xowAfE1zGd7AEaFhJaYn9P3duTkBb5prcu6rPmAk=; b=KN0Nryr5QrMbYnDY2BP7sqsmqg55u44TFM0nljBw1oBYZI52HfRWYR1B6SJNk3recNC2TK ARm4IHZJqohMODjKErvM3yx1B6tmfrIOKAjAoKwabM/IRqdBQV6Y/rUuuMwHit5we8ryFq v72A5MuMQOTmUo1gY8Ot9ab+ylxl69c= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NWuvSm3E; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692172858; a=rsa-sha256; cv=none; b=mYWWKSOZhXgTnBOKxdfQoCLwFoW9saNKvrcL6hD8DQON95QvfDfkLA9NU8NQZ+6KNsFz8C UG+q3zWUL4b/oQW7T1FGHbXn9B1MBIk70P8o2xja6qakM53rvRLMlX9xeXg7QvIEJJ3NKf H05KV0M8TgcUJc5zzF+Jg1T8UM0Woxs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692172858; x=1723708858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6ryYu1foaYe++UHjqS2s7U2JfNL/iOIOHf6dTzEUvXM=; b=NWuvSm3E1zXm1pdJGJQ/XHm1hmzBxrWN7Rp+uNjtgd93CgNMTASAy4sJ k3Hn50fUXqSPJOgOqZhplvZU9RhWG2laT6QBW4EQW0v7reTTnzzo5IVMk UtKUspGuWZhFv2LOMyAPIP4bgvJR3CiHFCue59WmBQX1dtPhOd16DZN59 Y3rnYgzuhdi9Cz01TOnrSYyI6j3itp8bDNeM6gqTayZTn6bBWj65b5YT0 GRA00cCe8OgHGxpjG7G1m4izoXjScYiIY7GSF+OXkipRGQV49H37/buP0 xrPVWTpMCdTr0Ck49EJUvhXS13l79rrpz21XkYOAdXA5dy0UyRTQlX8eD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="352058222" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="352058222" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="804112811" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="804112811" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:53 -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 , Rafael J Wysocki Subject: [PATCH -V2 4/4] dax, kmem: calculate abstract distance with general interface Date: Wed, 16 Aug 2023 16:00:24 +0800 Message-Id: <20230816080024.105554-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816080024.105554-1-ying.huang@intel.com> References: <20230816080024.105554-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 59CCBA0009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: txfzo35sydgam5hgaes81qjcmfainhef X-HE-Tag: 1692172858-149007 X-HE-Meta: U2FsdGVkX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3jEOEgxNggNMFawrAElldmqJyj8YdjFqlismUHlaWJfIrW8XegWhAPXqqH0MzBqyozVCcqrOaLXKfdPiti9UddJxx9gy7Dr4cBdB83eQGIUZXZucwJlW1z+Jk2954kp6OZAtGOnhQBe/Kk4wTa7zmgmNWGG1JpYPbwBEPnHcEha85cEYE4zGtFAZXa9XmJMhXY+UsvYFhxVtNLy6AI0CcAUUJ2nRD/5z3nbqsEVQrG2SLx7sy+VkDPYNsOSGQVzWspzo3XF3u3eW7RBKuqD1J2bSF/W829Tpb0t8Mv7mSVxc8fJ9Y+Q8tshLlsvFp73KjxkIsPjYwlsXPwhlBNykOHtLCdhyKTiRjyej2gJ5 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: Rafael J Wysocki --- drivers/dax/kmem.c | 54 +++++++++++++++++++++++++++--------- include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 2 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 898ca9505754..4961f30679fd 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -49,14 +49,40 @@ 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 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 +97,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 +119,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 +198,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 +250,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 +282,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,18 +289,21 @@ static int __init dax_kmem_init(void) return rc; error_dax_driver: - destroy_memory_type(dax_slowmem_type); -err_dax_slowmem_type: kfree_const(kmem_name); return rc; } static void __exit dax_kmem_exit(void) { + struct memory_dev_type *mtype, *mtn; + dax_driver_unregister(&device_dax_kmem_driver); if (!any_hotremove_failed) kfree_const(kmem_name); - destroy_memory_type(dax_slowmem_type); + list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) { + list_del(&mtype->list); + destroy_memory_type(mtype); + } } MODULE_AUTHOR("Intel Corporation"); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 9377239c8d34..aca22220cb5c 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 9a734ef2edfb..38005c60fa2d 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -581,7 +581,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,