From patchwork Tue Sep 26 06:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13398704 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 2FCF1E7D0C5 for ; Tue, 26 Sep 2023 06:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE48D8D0061; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B93B28D0005; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A353F8D0061; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8E27C8D0005 for ; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6DE651CAED8 for ; Tue, 26 Sep 2023 06:06:53 +0000 (UTC) X-FDA: 81277715106.27.173A532 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf12.hostedemail.com (Postfix) with ESMTP id 6A07140004 for ; Tue, 26 Sep 2023 06:06:50 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XS+1mUQ+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695708410; a=rsa-sha256; cv=none; b=3jon2EOma/7+le3uWLdKHknIUS62nphfxe1FSJodNBijWpRH55Ti3+MAl6vVYVqdnzuihN 0rKyjXjfZGQFKAiZ+S7yyyQN8zaP039ftPU1PK5HUdLCPqJ1FmMALSBQU6wQMhKA0FuofJ 1xogVSfdKlpFHJiQ8oInfNGBbCBpwlQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XS+1mUQ+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1695708410; 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=jpsRs6vQ0NjJ+/nsEn1pGv/AH/u/TSOL1LsQ+VgK/ac=; b=JTNg/FLMc/kxXsuZmpRVOthC/R/Uye+UxSbqcl+5pfC4FQR/c+I284nHqdvmKsjl2OnoS/ 3bgWvzq8fAyDxlzYNZ7wB+WYQgQEIisG26d9v7Gj7MMattDxOwt0Qy0fYvLKqtgCVIXHwJ tGEBCVK7fMU7gCU9PNlyvpHRTR5P+7I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695708410; x=1727244410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fpxsnW+xQLEWo8iAGh4opiRsZsy5mqUtfGIRqyXDBpc=; b=XS+1mUQ+Q17L8HHEQjpgV2O0xM9CPBZnBmWZShNPfodAJ+Bg0nNmccDd L78elWL6V0ht3H4MoNMpX7LnQ5wKtgMhF3Qvn4qLJZEcs6WxYL1B/F7FF boaAJ8iGqZKpz836DyNuSYNoi3TlRMn8EqyweB6gypZXLIpj0GEnsldLo nMWQC/MfZANBg3PspbKNHwiyUIhqaVSfr02jiSiJNnhA7uZ2rD7bA37Ef lSyr4DjMbN/vpLTyIGmwRMHC3tgaCTT792dImUpSaFlAxsQ44J2WP2LEQ LZ3cOmwusuYspi0Ge1rs2wva57Iq2log3HvzvQUYLPYirFFZ2YXSt3ymN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="447990812" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="447990812" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:06:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="892074770" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="892074770" Received: from aozhu-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.94]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:05:39 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , Alistair Popple , Dave Jiang , "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 -V4 1/4] memory tiering: add abstract distance calculation algorithms management Date: Tue, 26 Sep 2023 14:06:25 +0800 Message-Id: <20230926060628.265989-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926060628.265989-1-ying.huang@intel.com> References: <20230926060628.265989-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6A07140004 X-Stat-Signature: r8gd6senq5jhuu97ykmg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jn+VSx3mF3w1S2I37sRsLMuMf4X/656Jd55vJF2oRnQf6qULGxUDpKUMPkEGMKG224qeafUNnMuXqhTzJhyKkomitvWdQlatfXI/2jq2LIfScQaFrVTn2+dEa9WykBSuf0FHSh+3Jmhnupy53b3/r2gOZwEL8N4sRXlcU5r/uTTT4IdLyPP6JtcupgxyII+O7Z6B1YeNoKwo7gBx723+ON2VIN81/qJwcugga58PzDZo9Equ/2RsPP9rsh1VkLd/wqiqVlLs0vN/yH25K99TPOVkfgj8/v91xkMO2ICEwNksnA0pl+7oouLHRMetAkXE+KbkSg84jkplUye0PjVGIDOKY+alYJetq16/9UmXH78mV9re9WcAs9DHLPVfH/nL1ReN7WWWxzb0rfb0PcKF/dOzBrOZYdWaG8hKnjVQvbqYBR2GYjIf4 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 Reviewed-by: Alistair Popple Reviewed-by: Dave Jiang 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 --- 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 26 06:06:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13398705 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 F3051E8181D for ; Tue, 26 Sep 2023 06:06:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88A5E8D0062; Tue, 26 Sep 2023 02:06:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 838478D0005; Tue, 26 Sep 2023 02:06:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7008C8D0062; Tue, 26 Sep 2023 02:06:58 -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 612968D0005 for ; Tue, 26 Sep 2023 02:06:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2AB78140F77 for ; Tue, 26 Sep 2023 06:06:58 +0000 (UTC) X-FDA: 81277715316.25.DD77052 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf12.hostedemail.com (Postfix) with ESMTP id 09FC940018 for ; Tue, 26 Sep 2023 06:06:55 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=M1dhd9HK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695708416; a=rsa-sha256; cv=none; b=a1Bxp9pOm1X7R7CfQUQvVfH1jAhnw1IpZS7FUJ3xthQPdXb1kdwpR6DHXw1UU/CbQ6rKYZ 4H6Cdpp8M9Onbre0JP7yPvr5t/GVDDQu32VIDvyp2xnJ7KGuEjsnpgIOiUgJVW/naYkh0U 960hDPnkOICEQJc8l17x+IhZRT6ZpDM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=M1dhd9HK; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1695708416; 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=giW1qeem/Xl69zU+7YhiYYsig6IRmYadWtMvNKZSVwY=; b=6lWrHj2rcQ0Q4QS2OPVmYjvCA2QI88hy4iYYDz7Aawo9i3Z9Fls3216+a1uBgDhY3CgIYR bmcDvFZ3Sp4WGUEPGEosXPev92sgE/6Um6xUKNhOWv2g3GEGEFqdwQunva7NIIC3eZf/Tn Mvut3/OzBw5So3Zsfux2RK47Osg8Bw8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695708416; x=1727244416; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0F06IrWYpZawJ+w948h09vgHlfS9BulW8L+t529P3IM=; b=M1dhd9HKmIM2oTL5R5K3MEOjmYqDf4vIXma2e7vu9hw7dVDxsvogQEf/ /FyN1RrUVqFQfS/eFqgoCr6IEwCYBrKkmdhrgapT+alcwv5irBY9Z2+S2 odDB76PxIyJXUfnl2gYQlPZfXwbSLjo7h0NHSNIE31AnelNk6PGOyWRD+ f8XiRUcxxpiStiXgAcTr+yneENGXmEX2VhWp3H1sA0NrkiiGS/4iklcyS RMgIEPgZuEtxpkyaPKr78xuFZ5nEUejuYVrivtIB5cH7UyRK5K8yEviUg /NDHl+GJ91oZh9KxTMesGiQmlDi9sii3LwQB8/NaHsNOqgpx01tgH+IWX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="447990831" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="447990831" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:06:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="892074781" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="892074781" Received: from aozhu-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.94]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:05:45 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Alistair Popple , Bharata B Rao , Dave Jiang , "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 -V4 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Tue, 26 Sep 2023 14:06:26 +0800 Message-Id: <20230926060628.265989-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926060628.265989-1-ying.huang@intel.com> References: <20230926060628.265989-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 09FC940018 X-Stat-Signature: hzodzeysju1w8fob779fct74ntx9o6dm X-HE-Tag: 1695708415-640135 X-HE-Meta: U2FsdGVkX1/nCCsATYE4GG/k5Un+78ggkG+kmuCWL0PuIG1R2kSYphV1ePC5AmA/o3hd9r9DSyB2NwiJ9lUyRgvxkHf6vcXymt8Kz7eKKjPQgNKMRgE3hdvFeB7FtNyswE0AQ+DltQnoO523vBEYsznDBjPOk6j3GOUQbwGw7KDDhj/7or9eLpLhyryfzh+HZCo0HoYEv36m+YlG5aVJ5iDcph80h1ifXmRWFyBcWCQxd/h2aoClU+7Fz8r0qK4FL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YTYjOu4MKqE785iWpw0ZzJvKuw8+RLNNvn9TsQnP8/iVpKrpWm6+7tl1ApQuRf8uQ4cFISG9JOJMc1xOYx2xUGo9gV8OUZKdrrICsNT+ReynF+vjkc1yeAa1/NKbpyIWGnAI2zkKTl++LKOMk/Z13hZEwnewhqNL21r0M220dKnoR6povT//YgiCJvksJTgw== 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 Reviewed-by: Dave Jiang 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 Tue Sep 26 06:06:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13398706 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 5172DE8181D for ; Tue, 26 Sep 2023 06:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDF768D0063; Tue, 26 Sep 2023 02:07:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D900A8D0005; Tue, 26 Sep 2023 02:07:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C32038D0063; Tue, 26 Sep 2023 02:07:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B07A38D0005 for ; Tue, 26 Sep 2023 02:07:03 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6DA83160F71 for ; Tue, 26 Sep 2023 06:07:03 +0000 (UTC) X-FDA: 81277715526.25.6B88EE2 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf12.hostedemail.com (Postfix) with ESMTP id 3D5B840004 for ; Tue, 26 Sep 2023 06:07:01 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ULrJNi8L; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695708421; a=rsa-sha256; cv=none; b=i705l2JzCS7kgnYIhWKw+axp/j8/38t7JcHPW4DujVtmXtNeYcQzq/70sfT44Sad+sreUc WYkRKmfRtXXhXsEuh+X8Jl/s0E4nA9ruu1FwMfugwEWRGrmDeQm50IuGZH2D5ThpTShHff OgUNA+e8X2RQ3OxPL1Oz6lgEXVUJYo4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=ULrJNi8L; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1695708421; 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=vyzGIgRkUfdl/HJIhg/FbZXVnYegP2OF1LxjJ6MbP8E=; b=aXHwdj+j3+xRvZaHmLViUVNXs5h7oB0PP68vV7U4DFCkbJu6ZWUL3BcM+Q6/wEKEn2Ujkv 3GefHqzOHIEDEkcDCghxZQWtxL7Zfhm9pZWT7NZJYyIlZpUuyrYpgE7hf+NGIZGL9cRbNh RcoDdVuHAMkuqyf97HrMrpEgBk8h+z4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695708421; x=1727244421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J/tnrd8Wcw8r5aEvovh7DYTLJfhjcN/4NzFCxtBHH1c=; b=ULrJNi8LBh+KWJBIBe+f+C/Vu66ZY65rznsBTXA9X9a/kly6Gyx4wBjM 0pPuAnD66FIkZkyfMPsXD8/Z9OLky1DzOS//oYMjsAkkY/QLyrfCFTdAw SxOTn06kwGO5Xf6IH0EcIuo0pYR8Dxaogl6vXM2a+YXyfvjk2Ir1VT2bv cknJKRS84ZwpB1gcO1znhGM2Pzy+COn3ZlxVisIJMkl8KnOSmV6IFwaO6 Aw62+ExroxbNJMtkos52tKFWaC7TD05ueoQhxM8o/myHeBXm6wrcsUuA9 WuHPlwz3mknomf4Nz63hLAJVUufiHhhAl/2gzOeqX+nRKUD12rzVdfO/8 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="447990852" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="447990852" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:07:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="892074793" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="892074793" Received: from aozhu-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.94]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:05:50 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , Dave Jiang , "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 -V4 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Tue, 26 Sep 2023 14:06:27 +0800 Message-Id: <20230926060628.265989-4-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926060628.265989-1-ying.huang@intel.com> References: <20230926060628.265989-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3D5B840004 X-Stat-Signature: skzwcsgwc5dwa9t1t6twb6m5aeoznj5q X-HE-Tag: 1695708421-679845 X-HE-Meta: U2FsdGVkX1+mO6uqoHevow1ktYGWoj3d2Xev4fU9Lue4S6luA2cPu0+chkfnO2TIa8vWzWcQv/+uk+YoKNFEyLd0Ej6cqUMnfOUO1iLa259YnwufS70nVR92+Otwt7Y2DLLotY7UMhIQNW9bf/THsoFuBefW5qAk/C6HHDBjLWeiu1lHFZavSJDvcCP5ZNmhIhgmjmhRHKRBukL4DU9oyT0FO7TwSgqf6634YB22PdbSF/lvcJDrcthXKERiyaiCPlCgqCh0svYOijzoe87jSEv8n3rCWuHkW6M/u4Y5BNQPbY5jNwkCXYNIld7gkVqS+Mph3igQ+wH+l5uRjnrNdyMuVtX6nsV/0Pf4c4w+rLM5cQc8uOfFirnfvpu5gBH1Z2BIxSiPtnXsGIncFPkaeWnyVSqYbH9D4LGkTP87TX1rNpWE24aP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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. 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 Reviewed-by: Dave Jiang 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 Reviewed-by: Alistair Popple --- drivers/acpi/numa/hmat.c | 65 +++++++++++++++++++++- include/linux/memory-tiers.h | 18 ++++++ mm/memory-tiers.c | 103 ++++++++++++++++++++++++++++++++++- 3 files changed, 183 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 2dee0098f1a9..9ef5f1bdcfdb 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; @@ -841,8 +897,13 @@ 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)) - return 0; + if (hotplug_memory_notifier(hmat_callback, HMAT_CALLBACK_PRI)) + goto out_put; + + if (!hmat_set_default_dram_perf()) + register_mt_adistance_algorithm(&hmat_adist_nb); + + 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 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 26 06:06:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13398707 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 04994E7D0C5 for ; Tue, 26 Sep 2023 06:07:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 926908D0064; Tue, 26 Sep 2023 02:07:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D6578D0005; Tue, 26 Sep 2023 02:07:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74EC68D0064; Tue, 26 Sep 2023 02:07:08 -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 6017A8D0005 for ; Tue, 26 Sep 2023 02:07:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F6E440F9D for ; Tue, 26 Sep 2023 06:07:08 +0000 (UTC) X-FDA: 81277715736.13.CEC9401 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf12.hostedemail.com (Postfix) with ESMTP id 0500040004 for ; Tue, 26 Sep 2023 06:07:05 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VgdPw6QL; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695708426; a=rsa-sha256; cv=none; b=QlQza+cxp0ORyPWYPj6+9pHQEoPTqyem4wja/4S4MhHg6oVQTy6SGiI/yXVUANmou/Qt07 39PGsSOHy+4sY+5uL2GgdYWelA86uDnKqHcSPKDQNkxaZjt1t1wtIybF0Ve4ms4DGqHKFu yDNy9KRJSvMKA6W5Gl5kKhos17StJbU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=VgdPw6QL; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1695708426; 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=ejMWpaHQI23M8H2zPM9TNrUkh1HO1AccqncrT0WnHE8=; b=LsW6OmMxEzSCC8yF4HO/f8CXT1MJ4DjKpXUwB2kdL0G2lC7zS8eCY4DRIRNUJmEHLsv9tn KjTKu0uBwgX9qCL8QRVImFuyhodk4g55IdPJrjZTI6qVULvZea6W5zLezbrpBPTDDLENzc nnLYPj25zhR+6AlgeFYuPLx+rc/ZdNI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695708426; x=1727244426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kfBl53G6+3W4hrsT7f5lhn9OvXRFwRRxK2VozpSoI5M=; b=VgdPw6QLQMqXwGtPPcXgzveZaqJMSsZBpYMYFsrXunrJFyQvzpILWg3l J759AoQw+9Ro2Nxs0qWvI0maFrn+K4d5xXiUHpX7Mn9c+fy7PLhSWDMhQ n+yUfAkHJLPdL+ajDj07RC+haIqf084THkyAtghlb5C0sIV/F8i3bUTvB c083m/yE29/mBU64fdS6cOau4qD2TQUgSz9RjlzBqA3mT1zpuryGZDs4k vAvnOD1Zqm+U5HPxL6lHLKoAxYlPN+2sXRll3ZGAdBDbxwlA/JYJUviGH 8gJh8NCUaYBDnuaPexyT0Y26NhCecdRF1F42XuhErbn1t+OuKB9v1W+fG Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="447990870" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="447990870" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:07:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="892074807" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="892074807" Received: from aozhu-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.94]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:05:56 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , Dave Jiang , "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 -V4 4/4] dax, kmem: calculate abstract distance with general interface Date: Tue, 26 Sep 2023 14:06:28 +0800 Message-Id: <20230926060628.265989-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926060628.265989-1-ying.huang@intel.com> References: <20230926060628.265989-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0500040004 X-Stat-Signature: efccrm5psdtxjb57brcgsmizxcdcpyoo X-HE-Tag: 1695708425-107375 X-HE-Meta: U2FsdGVkX1/xg/hiwe8FNHrYZa/YsvXREh+IWsMf/9/jMH7TR6pTw4/xMwCkT8Xq8mpK5z6SUIzbS28GHiaQvtOQ+ezWVtmQEY0FSzQmBylqhdt8cGfgiO0Hr9lSKpfiADAAeGqaA+FoBQxe6jCY7lrMtPmp+y+dcLxD9rwJWLw85F9YTRJPRIcwJX280tHmM7gXIieTXGjlCLP5V/TxPj8wzT9n7PyxL5YiFmlPto4PZ8nSM4Hb9v6X2kksEDMvWOpuDg7ZdrSIfh5CRkkP2bTtdBIjNGLOElvyjeV9/AvUGmpkgnyzKCdsfL4efQIKbsg7pRQQkfUZttw9x11X/ZSXbyrcS6YqYH+SwJQrDITKW9NJPB/LLoyeSiMVjiuVSPhT0DPswTcdSIcC9Hcn5rBJpMEigezcWNydRzoHzcwGtzsH4BjrXuBrxlR3aGGzHJjRpv6GRrFFwoMatjezGx9eLGjru+MxfEqDOUf5CYgHYiR0D+gzal9BveRxdvlnZEEIdpNs92/hBbTgP2/aSu9Dp+oBneHv6rsxThVKec/KqXzMhEPIiZJ83AfL+2IN3hSLzPiRbcTOfV8Zc0HQ7EldgOpHzQ1+b3opDmTeJAjk2NV79OPytsEVfNTIz5xub4WNgcBuUqPkOdI0RyylJBjqTF/WpI1gOGoIKw1tEzUgrLTn87CLEjsL1XCfcDvQldZhpnJ+v28TK4P2oT85aGGdtRKnw75AH/Ib85DP5zXujvhHVrGehLdwWQDa0LrLjDJ1XqwZmGVXqEP71hyFLBk6VZGyeHno5c2CX/qX8DzUm6iCWNn6R4uRUnyfd/Roe9qpEVev8+i8SqKTlFtYHITc0WrN1aWe5PRQFt51mpr/a4jKgPZkYpTgGG9JRiZZf8jGkRVEhCE+8fIztp7kPPJ2BeoBD+HiVjkb+d1cKUZ99ht9dtpBmoMVdi6HxA2RVAAfly693YkGlkGUc6+ tnxv/9Lc d6Nj3dVKlT3abPMEcVImic39SLp9EJo42LyZDELrNUtOWYqDHNtje69JA8u+/u3lhWuJZgt0+4BsL9/fog/uqOPqMBMeQsJiDHWSk8oUA1ZQ02S6Q8WzCWuEM0ci/iX5YthLByc84HdCmCFcmb2qXqLXKSa9QNBt/JfTDQLwJMeSh84W3pDz1xYgDRll1NgP14RW2RAoGgP1vacG9LeuyIVJoBT2VZKo9bhrOG3QUPV3yFij4UNmTuBtZGNk31d8eZF0kHuZtsP7cvpSkvd4SZgKc1tnU5LpdZ64rkvef2dEga7wX9DV+AwyD6Fb9Ez6rG5/wGnRN4N0/KCR+7nZlbAu4jFH4ENYYauKCGp0hbpjavssF5uaA06eE1rOUcvqx9vTq/xR3ycXa3qthEkQhbBvZirsLP9tmRA0leGnFKEe3dNUC8ra1vfOdkmr5zFqbHQZki3lZRamBRBvWKKtGGTBZEL9m1WrsO1+q 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 Reviewed-by: Dave Jiang 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 Reviewed-by: Alistair Popple --- drivers/dax/kmem.c | 62 ++++++++++++++++++++++++++++-------- include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 3 +- 3 files changed, 53 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..a28606e65ef3 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -586,13 +586,14 @@ 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, * clear the node memory type. */ if (!node_memory_types[node].map_count) { + memtype = node_memory_types[node].memtype; node_memory_types[node].memtype = NULL; put_memory_type(memtype); }