From patchwork Fri Jul 21 01:29:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13321214 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 F0E4EEB64DA for ; Fri, 21 Jul 2023 01:45:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DC77280177; Thu, 20 Jul 2023 21:45:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68C4528004C; Thu, 20 Jul 2023 21:45:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50675280177; Thu, 20 Jul 2023 21:45:13 -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 3F63928004C for ; Thu, 20 Jul 2023 21:45:13 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 13C1E4033B for ; Fri, 21 Jul 2023 01:45:13 +0000 (UTC) X-FDA: 81033926106.07.61F6E27 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf11.hostedemail.com (Postfix) with ESMTP id DD65C4000A for ; Fri, 21 Jul 2023 01:45:09 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AMPVGPRk; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 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=1689903910; 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=mwlR3P3BI/k6pKiodh+YaDuSPT0DQXy8CnCLXSzimOg=; b=4x9WBp4WyvZvuGM0/0SU03iUs91SPdbex2hHbhmdWGK43Y6AmFi6MKRhmp0d7gdSSn6TBp ARwM7OWJeOMxHm51/sR0jMLSrtJLA6QUbEnElY1yTLkEViM827Csb+9WxDdIi3OYYq/vJS 36EmulPTUOQZToJojV99PFiaEn6A/rs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=AMPVGPRk; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf11.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689903910; a=rsa-sha256; cv=none; b=4Uda81cHWqdNPrsG21Zkc5ifJb2Hu/vUEN0IxZOb5vVBUqkYrIOjUfckte3JJkAQP8cZtB J/K9P95OH0z+YOF5zHEbDReOA/YhoVkuaxugVC1cI0Owde1zW2x/dZN5DPkE1hR8IxFpmT bQsxL8tY5U2csW0xNY56di3WNVkWR4g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689903910; x=1721439910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oyCI5HLzYg6B8dSBk9eHwDqLZtZfH++WogxlpW3EVlc=; b=AMPVGPRkY4bgTMssx2UHbc4I7YL9/3Lx+155r436WnJA96zy3xOtV8dq e6mBEth+sYIYLodZTXjXR+7hhyNc/vqoi7lqU0YmkQ50eoZgOz2gFKq22 Ywb46Vmt1fA4mrC6qiIlTe4Xjkm0zultWOEHjFSqerip/XUPgsmFYF5ZP wr6xqxgsFIqjIxP83mIGb8Ts6XFH+R0uswW2gFQNFEvyxSM9PCBbStNdH khaIruZhhd4x8S4TpcD2lYDbZPsoKhJp9mHazrYvyVBLW0ldR+VUysHE8 fKHIjUnFVuM5r5rZ1SGw8p67u/9I8zEgqnHbcc4AmDUc438r4FQm9nHJX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="347214140" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="347214140" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724670918" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724670918" Received: from yanfeng1-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.29.24]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:04 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, Huang Ying , "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 RESEND 1/4] memory tiering: add abstract distance calculation algorithms management Date: Fri, 21 Jul 2023 09:29:29 +0800 Message-Id: <20230721012932.190742-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721012932.190742-1-ying.huang@intel.com> References: <20230721012932.190742-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: uqmmeounxmntmf3ciww9pxup6cosoaxk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DD65C4000A X-HE-Tag: 1689903909-483681 X-HE-Meta: U2FsdGVkX1+AbIFzJ3IaSoBdBv0zWEhN6fWlZKIsi7iKUra0/r/jACTK5BGq04bdZirH2fntQgwOke4MSE/suSpaXVsGdisyPOdHyrAuTIZlCnn4whzcErEUQoHI7e06xV012tBovYVbIa9KkRQQAj6UM0PcBrCs41Yw5tcfSZa4jY2DdAkjqjntzKLtDOqk+NpnFKqh0h7YgpB6tD6GPSyOs8gqG9JUrFFRsixOU7Af2rFENPH9Eja8dPW1gzpm4OeWALyw96udtb3gHP1JaOBa6q/KUCKijqRTxINpIVJdFdF5gYcIIAOID79E0UpQMBDAt4qXAM6Z8uO9roIVf3FKKvf/6byoBwNxuzkIv0OYbad/rVOrAY0F7DGIjV/voKT1pPG0gUSzqF7N3cTeDXXvDjraNh9h+onkvBEAAO7b+mH1VNzyqdHqcak9uIM6JecSPA2E6Pf7WxarnimIBVLP9WC3+NtWa3nghwB4POQvWL+a6LRYFuQQuyDjygiONiKx5oaVg+u1LKs1738jHvS5JMnyNfac3LKy2ygPk/75ZBinST3POiRXRQ0zZOeM+X2CsrrbL1vzanyYvOZD58jKiMjiDo72M3Y0NHx0m5Lm5gQVGSJkwFGrtnpcRlcdTIH+Nl8cf3UE923BKK8ydVEthstatGfde4TTm9n/i3mZ/G6+z/UQnQZEJl8xyQby3YtO2buBBu6oDBRGuyb61EbfXD4z9INT7OWRa0AEMrJoy6iLQLgvmjOd1hhVBcjhw8byw4+//VIhq7cQ3RQKPEIkMbTTFVlWuLYNp1BqQ5xDWCQomj3hrZq6A15h+hI374Uze4lE8XoHjDs4lc7Ro/fHSJOevebKou7YQQeLQx8RkGYv7AQdzJBBbUbXTTHnrCyGQdq9m2RGh8NUz1iO5CV2MqazqlHe8ANuM3u1BcmgXpM3eOLdMDewImv6fWKkk1WoIsJpYb/yfmAPV3t gX1WUcKj ceW+t6E6zQ6cQ6wBF7h1TRvoKMxxryAQX1R0wci8mThepjMm/TAK/NN7RCwBWJwJUgEiULNMBmkAyGcCvmWaAW1NPvdjDosYurF/YQwAUYrnH5UeM2NCycpXxrU6b/cDuJBPBuey98oXfoM+JGlhJhCgrtE2Pe8Mwm98K6QkMACzulrNrs3FijkIC8Jo6FbQoiwf5r33oxX2uvjU6xHPpeBs+9FCqBM+CF3wz9MDQo86fn9sHAqkxLeUm/W+kUnqxPxklwZ6ZLmAWK8MAac1S80ZyN3p1YjWSSJMv7VMUyg5pK7lEX68XOd24ZyJESGDQFYfLqDW1VwhVITHI6Xr3H2Qb7okgafDetSMvwV7GJm/d1wk19zLJKBSaO1pfNreEDlgQYwcH7HRTuiT46klFTbHo5RCBpnFAumRfOi7iN+yUTOlgU0XMiIcgH1jlQFIcxTFp1uYUoGsdVyE= 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" 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 Fri Jul 21 01:29:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13321215 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 0807FC001DF for ; Fri, 21 Jul 2023 01:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97416280178; Thu, 20 Jul 2023 21:45:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 924B528004C; Thu, 20 Jul 2023 21:45:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ECD2280178; Thu, 20 Jul 2023 21:45:17 -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 6EE1828004C for ; Thu, 20 Jul 2023 21:45:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3F2F28033B for ; Fri, 21 Jul 2023 01:45:17 +0000 (UTC) X-FDA: 81033926274.18.E2C1D68 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf04.hostedemail.com (Postfix) with ESMTP id 0F0A140003 for ; Fri, 21 Jul 2023 01:45:14 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Ac4YGZ/K"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689903915; a=rsa-sha256; cv=none; b=n06Z9HSWUCseaOiUkiteFa1bm7eIkfuKyVvRfwJhq/5bweYKRlbnA23OzO0CFXED5ZoxVH QJz3f1zIMvRE3MzwOqip0a2nEnj1xesqv1ekPYGDbiAZAHW3erW5h2z64Lj1st8pJgPz8e kOjOOtnaGaVbO/5uGUVym5O+8qARD7s= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Ac4YGZ/K"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 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=1689903915; 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=57j5bkDByog/ext/hXgYlpRrsqAj6GMku5TIZq1E3C8=; b=n/059tWDwb6h9OFYl+aaQLrJGxJ5mzyXZfhJtkSs3UjjjIe8meFimJ/5Bgd2LtWqvZhvsS bv2kyfnFWjUl9URGRNHFhYFQaao+r2XQLvrcu1LEmFERSyuIYDJc3COuvbn9TJdXorsBi7 8Y/6c4uUrvPai1gSSqHAaA0jvtL5vZY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689903915; x=1721439915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Hn5VMwJGt0IXFlVjJsaiQl5L2c0xHT5vclGupSQt0Q=; b=Ac4YGZ/Kq+NYgS5BjFmjKY0YuO/Yh2aK3dLPLO4lb4F4mDwYWg5PS1dr hyJFPXFPa++55P3cOfg47A/1BYni3LobNkyLhAXJV0JrcJpg9/vXRsa5j RGSM5VTNWs8M1yMgRc1fPWEOu5unokPUZQOXq1U9aPUel/og4cBaGpHRM RSx99wALsb7OcQaBYtUTkxIXXshO0qRB4201QrnOo81Ifzk+nGciJVzdk KiICKdJGBcLeB6KtK/G0yJoTBFXHwGsRyyeuSsPDPHwqDb9nj6irkH2k0 HNaCdiaTL9CW2soXKyaRaiKZ7FlK4djdX43lq/hVduQ4fkwxoWhy0FiTI w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="347214164" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="347214164" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724671020" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724671020" Received: from yanfeng1-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.29.24]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:09 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, Huang Ying , "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 RESEND 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Fri, 21 Jul 2023 09:29:30 +0800 Message-Id: <20230721012932.190742-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721012932.190742-1-ying.huang@intel.com> References: <20230721012932.190742-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0F0A140003 X-Stat-Signature: fc1g3zck1n787mnwzpbgi3dwsg1kzzoh X-HE-Tag: 1689903914-158934 X-HE-Meta: U2FsdGVkX18WEMdRFyAz3qK5bFRUyMY769zv3udG0O13UvUQRBWt5SpAFnccg+AYbwl4hzvsiVgTQ/KMOE6W0DQpSRjECKCZMJafUuipLqfcgy+A2qdDZ+XPzsx9i/CAy74EE7hww1SmIAQiCYB0SmIlu2SL2WX4vMTlWU2DixJ83blMH3cTt0jkBXMAL75rsdeMu+Tni3/UmaebGGqz1qYy39c5uoWKo/mLW3ik+IROK7akWyzENrC0Iqf/o0Ru6pIqPzMobsr7d6eJ7YRFvjdcGlhyNt92EeCRxhmatR7q34WWkllcC8qQ9EwC/Rz1Y2rvaJjRYYCRMkVK+fBYUzpqAA/2CE8VqXdDj2fVnMqO7EdBkqZv8bQhUnzKdOryNSIGKzFTI+DOfULX0MdPp+JD8Kx7yDzq6MicKx4YPkq6WfBpYxKEQ01KL/uNfNo8AsASX1YZ1wuYSpL8BtM2x92Q3HgHph9IyEgn3VeZ5dUT1WU40/NOnwe4XUbbvfRa+CRZvUgQBYLdKYDUumHOp2TWMR+4A5MCFuI5isnwd94+oD3bSS0HLoW3Z+Q7OuuQ7Xu8ER1FqGC77KXqaWJaYLRXgQuAGyLmBkC9nzhB/05lxqPBOVI6OIEtJmrgpxT7SYuG1hrc0ky2dOvrGuslmM8VgVVDit82EnqCcrJu84048kEqj05yf+gdUlXRlTjaXNeGbkmrfBlNH5RkpdW+yFO6BkJWvZGy38hwyHVfM2Kp7q4lmopNA+3EWwJygCpCNg8qDxePN0fEPgZBEJ3mEBDBGvSrvwFjjdRaBzohQ4wdT6koAK9/QsLd97UKBW7DH4JV+a+xhaK2X/P6VmKoQshvDMUS2JGsmZqohcVqPuApqC3xYZWLELNiit9AyZwJxAnXGVCOvx0uBig7wOXIq35FspPSQmQGnL1NX5w5AEZFptG2S/4FdrNv0IK1nTJCk5E6o50vDCR3Xdrt0wk eZD6eBxN G1lGsawhm4jHRW45Wb0Ve+DaN3cPFfZPAmhrqkjbcIws9afBfrmLPiRlGLB4iBAvFv+uzIrhEE/pIkB7LHrFuW99YthiSceishAo3olpCMy1dKrAWki89wmnCZSRz2RvLss0TuQWvMD5HQ/gWEBZK8SE5pa1KMi2XTFnCkkOBMMO7TQY1h+IvrGnzK7ZkCfW67bnZ4z7UNcC0rakm3zXgUnymuJXKC3UDwDdj1yxWVdZL0znS3luELCl/C7TNrW/jqMxMfdyAYbU9FFf6i3UFq2xBBEOA23oZzFbsxv6W9klY18U+mqD1MjfaD0cFVbmzGoD7jvE7d922ecPIlUL0W8PxnSs0xFmT6XKV8WfJKrQUzebYMba3nGciiQryqjBtZb3eZtbtViVEA35jISidNZKG2ZNlEe8iJ6qy5gmWdMN3TnzmNIdxun0S2+9zzFOb42sB7BRc8kFChOyRwoCFtE1o7V0jI6CsVgoNxT8eVBmaZxodBz/nYTdt6w== 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" 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 Tested-by: Alistair Popple --- 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 Fri Jul 21 01:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13321216 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 D0746C001DF for ; Fri, 21 Jul 2023 01:45:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6409D280179; Thu, 20 Jul 2023 21:45:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F03528004C; Thu, 20 Jul 2023 21:45:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44365280179; Thu, 20 Jul 2023 21:45:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3418B28004C for ; Thu, 20 Jul 2023 21:45:25 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 11E144033D for ; Fri, 21 Jul 2023 01:45:25 +0000 (UTC) X-FDA: 81033926610.11.F3BC9B2 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf07.hostedemail.com (Postfix) with ESMTP id 0A8D940006 for ; Fri, 21 Jul 2023 01:45:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=M3qKn1A5; spf=pass (imf07.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689903923; 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=zqz1imDRs/kcqAi0UmgBBxno2gXq6mp/yd4rb4WEUco=; b=iRmWAl4P476eDic0kP7gr1mOnS59i10p1ReK8LM3TbolrwiV1/5Voasicz/BKfdtxw/vZU 9BrH6KT1m9JUaXD82ZUqUbMT61qUtNIPgyR9At9R/WVBrEpKTMl1fFh6uB2rXwCqgYP7Gk RGiVqtx3U75tGpUCiOWJCr5/NGXXiyY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689903923; a=rsa-sha256; cv=none; b=6dtA6ALOeFVxUmopvczWr+3B34/Al98auWC36qSKX4SSWEDaQcF5RENDYwKCeii3jGSXn0 UEiOVmu/4GMhoP08VILvtV6l6bXSp20JHDctWCOl7ZR0Llpisa9dBOjnvD/zliE7waJu9F aUpcC+Xm7+W3dbhF3laMY2sh2X8OPQM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=M3qKn1A5; spf=pass (imf07.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689903923; x=1721439923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fvluWJnQxPJxRNFSQvnsXlILnnh9VajCo65nakKALGw=; b=M3qKn1A5hAE0TjPHWC0eHtnqkvGfSI4a8s0ZGoiwbLfIb/SsXEeQdCCd KBQMdSNzgakSCUpAW63Q/dgY1/e/AmXOPvcCztcSEVP7Hp5VSSn9cYan6 qOzSJUSNUDjzJP5PPqk/Ox+9wyo8J88xX9E9+RfEft5eK7eNXThd+vPu0 c6LEC0cbXzhcnKoMN62wG749nxvREjub6vfJeP/h/y6YidcQbNWpOJqyd kOf3qbw/qPFP8G5Ks7EjRvKaANzEio69ozKTSzLa5t+KdzC09oymuqEP+ WKoru36HKTtdrUivDY+YVOyaPCj3vvE9SaKQym06Zlq68BPnEQiPnUGK/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="347214184" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="347214184" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724671128" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724671128" Received: from yanfeng1-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.29.24]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:14 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, Huang Ying , "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 RESEND 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Fri, 21 Jul 2023 09:29:31 +0800 Message-Id: <20230721012932.190742-4-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721012932.190742-1-ying.huang@intel.com> References: <20230721012932.190742-1-ying.huang@intel.com> MIME-Version: 1.0 X-Stat-Signature: k5swdxiuiob888qfnk4q1m8hhzhj1zsi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0A8D940006 X-Rspam-User: X-HE-Tag: 1689903922-836952 X-HE-Meta: U2FsdGVkX19a8M2Aq18wzLB99GiM2nQC5QI92P5SMe0jSJDENq6yszvKu2+KM6AWxZJXaA3pyHKrfoHSSyT9CIhGSqccAufPMp7XPZYvmjCRBy0+2l0a2c2Dc8ruci+C8wdxnMbwDEf+KKzexNGOeAFh8fRrfhJTuQZyjfS+H9H4+KZKp0U6kS8KoMiw5qnfgVxMrhxGQOUtEbH/XXqhxLX26fcz79AYNBAP6om1suaOmiQ+HAd40SEKjDBVXZNZ+H2pv1aQr5rPJnyCWxiHVhq5ycwk3bmYNxq83l6Xvvci61/gX1XJa5ipGbI6QggbMfL/Amnla/oWF6i7HcdfP/JchsgqwL++ORB6NvDUXAh1EQqTOQmgz8Mtv6QvKtUB88U1XiZMPHWENFwF59wj6AEg1lVXM1h5OQAqIiTIyJcq2NUDWZGJwzyYIlKyPYmzLlvnfDh1mD+p0zmXVDRJ3Fxz3ZnhiY4TrnYPXgFN66bzpmBdxLEsRYTuy4B9ek0HOnZQ7EN9ptCPXgM53QP1JcHIL8InFrDAiZP3zVA5DEDWvXWAj8PSGLBMMQMKNjChSzDH5F7M5LcwN2dCSJGiAxBrKcQLDOgmFd/UJQfCBdN3EIXBUOGsPY3iBYhuUdI7RKfaY2aTM4+8nh/2/XVWH5kfqKOlC5UHyvIWAGDDDO1MJPhHlTuJs0RpV3eDNvhzcHdYVOLmGEkhYQUY0csHjtZkoRuVfjhGTJ9SpxNT5uf2BbEoj9fJWyi8wLUsN3hU2Ui5Wq0dlyBsMJm2NfuYolkxkMkNH0HuOPO7Hrqi7JcM4XYVU+1IGEEA2h1ZOLXiKt2Bjp8RmFc4Xix2+nfAfpI5mV+uUGsa5Czz3qwbUrniRn3PfYvub0ce9w8JaovuodnQf93ag70TdJiVo/fXrwc0zzLL7PvR8GJOO9TDtmsvzBloDpgcV9yEG5Dq4HojF8uESvzd1TSwEQOyllk jLYTlrE6 +Iqss0iq8ITfyz0pL3e6233SwOhiQkzIhrhQ+iQL8SIZg3jTQKJIq3ENUpvjJ+laDfZhIa3w9vwzrloqMmXbfyqQuh8T4y1Dfq8r2nwZTnYXuyd5vcpDTplymcUQRkCMaHTY8sGBUWCoSQzSUzomWnwU7DTIm1ldGPsjlkpveFAYMDlqTNJcwnZ3elztm6AX0GAa9M7uVQHF/FMrd7vQYZvyCFCqRp0/nndPyDdAM1nc5cfd1UPuTWqgqClubQlQq+b1cxyqXM4GDA1CVMbz/PH1GNjossYupA3MQq7QZEx1K4yN8qL+lpcjWyGLeOT5UPwhs5RhY1sBuR5nXDQcrb8wU8EUmGxId19RQnlntUAD9GAUyRflu4BvDnPeURZNl6Bs4NwJ/tDaQB6QRoZlpFXN1rM6LGf1OLdBpnovup0i345oo/MLKld1M6v6Fh9hUMuwxNnVWP3pyoZg= 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" 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 | 138 ++++++++++++++++++++++++++++++++++- include/linux/memory-tiers.h | 2 + mm/memory-tiers.c | 2 +- 3 files changed, 140 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 2dee0098f1a9..306a912090f0 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,137 @@ 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 __meminitdata struct notifier_block hmat_adist_nb = +{ + .notifier_call = hmat_calculate_adistance, + .priority = 100, +}; + static __init void hmat_free_structures(void) { struct memory_target *target, *tnext; @@ -801,6 +933,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 +974,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 Fri Jul 21 01:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13321217 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 F3609EB64DA for ; Fri, 21 Jul 2023 01:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D85428017A; Thu, 20 Jul 2023 21:45:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 888AA28004C; Thu, 20 Jul 2023 21:45:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7029428017A; Thu, 20 Jul 2023 21:45:28 -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 605D428004C for ; Thu, 20 Jul 2023 21:45:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 31D9B1A0309 for ; Fri, 21 Jul 2023 01:45:28 +0000 (UTC) X-FDA: 81033926736.30.6CCDCEF Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf07.hostedemail.com (Postfix) with ESMTP id 0208C40003 for ; Fri, 21 Jul 2023 01:45:25 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gPNblRs0; spf=pass (imf07.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689903926; 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=QV8Teo1j0CFA6btKhSsxBE6pLS/TyY9NOfA3+UQFqbU=; b=wf1CLLteClhEEQlgyJ4d0oRFauxJ3Rg2MrE3rV4qnGitW5i2EUEI3VqvJeEYEraQrxj6Ik u2DydnfP6YcI0KTHZWsB34AtjTm6tIIoDar41hG1jsNklhRpVPkEI00QFqfCMbZIBX3o3b rEYr4X0fDqUdhc65ljxjkgVTnHbXxOw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689903926; a=rsa-sha256; cv=none; b=T6o5HUmeOyFTtq12JnOZUyTwYIqCnm2aQYmZ5s20b1c1cXactEwGDHqaGvaTIYdnGdcbPC Gj3xuQhWYCIRD0lVmKd6VykhrvVpBLvNplbf3K6vndBDrXGnXEYY0r09Rpooe9WMkqGW1g JqklCUxaHSoo79jbSiLf5pe6vbiUqrs= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gPNblRs0; spf=pass (imf07.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689903926; x=1721439926; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WgH5xLOkBW2Y/oZqJhHhP4ppJv8kSHk1fii5X3wpokk=; b=gPNblRs0gkZzNozH1FkZucPlT9h30GVT6nIPe87tIc9bOoZX9DvZn1IG OfirMVLeuALaBY9fYDPbejT6txNLRd1hDwah0iNA7waa4R4e/wFMzC31d NdAuLbH6C+SJ0eD/+Tiv2OG7XRfXSyZe/t7En6LYsYgBwl0I8yZIUy8MK y2+5I/fdmFkVs8D/RijbUGiCyr46GvCvzJ3Y+3MbBI+So8sfEIVhkEB4p 1qfNa9NRgKeIXxA6mq8IPAsf9usMXoBYXYyBXass/QZRYCx4+fgZ2TFWv QGk64LSV2YFleovyAA5HF9N9txWxaunKzUvHAyK/P2m370LzsiPH12FQD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="347214206" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="347214206" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724671167" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724671167" Received: from yanfeng1-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.29.24]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:20 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org, Huang Ying , "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 RESEND 4/4] dax, kmem: calculate abstract distance with general interface Date: Fri, 21 Jul 2023 09:29:32 +0800 Message-Id: <20230721012932.190742-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721012932.190742-1-ying.huang@intel.com> References: <20230721012932.190742-1-ying.huang@intel.com> MIME-Version: 1.0 X-Stat-Signature: hmm5qmuubinnpb6qt949s7p7qq63prf3 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0208C40003 X-Rspam-User: X-HE-Tag: 1689903925-467676 X-HE-Meta: U2FsdGVkX1/+U2gEqP/xcrR7PcKzw5XaExYYwxJqhr82HNK/2/UZxFEWeR8Lmoxojxuke+goSorpDCvPNeJhAnh/FnXqqU3+qpFO1S78CDUIALMtqUE6k2O2FJEMwtlmG7tEBn3vs7sIuTBk+VLyfpzaGIxEHG+2fzAjxx6WaDKLo6YVrRHZQFHBfCuEG22JislOkenCDXTgdvfnZtlM7al2JKkurIJZEPIns/UdGKMdtt523MN7bJuDQLvumVfDtw9JZREbtbm/wNHSK3E3j8kzlqfDpaIRD24pV1JEtBEFwTOTQANRziOoPSXoUi9DI+reXbUtTHOC8iJGZbM/9qmxey/zJ2wyQLHMsWZeXpuX/eXdLNPlzDh9yiGnZAaKj2G4Z4PCcGgAM+Gla+72xIiUF8E0+QgfXZkRoOR/r9FZ5uTKb9dQwgnvHf4Xbhs6LV/hb11oXS7DJQpiRypTve01WXL8pZlWdzoF8IO2ALzxAkmkFstFk5bApTd43tbBXViojjzAkK5h3no7uQt6I6/0jzRE59vjZiB7XRFPI6HdHoNRcc0qwEPd+Pxd071q4p7hRpjp6+zYNbVQjixW0voJoPWa3dEqp5GL0inLZd1qMVoYkzrvuDQ6q/3lFM0TEpSgsoWFD4fl7aga/vnIBtFSURkvJLdbS9eAz2N+FxYQIZbA9RkSHa+RUnh+uehExL1uyhMDjNB5z5alIQbGlLmkfjf9Ktojsf7qbL/7qfgSr0VzS/HYZrYLFT6I2FoBD6G8Ust+3INLKgvPzls2K5sE5GmRcVitzp3/3AkAJl2OMxye89NR8YxxQhgp7QZ9Zf/tc4nRzlslyU3CPhBw10kXL+EYBg942RKzcOId2Qu3+rOkde4S9Ki6aWEUN7A6dfwtS+NTbzwWjd41EXsrR2NvL1Y6/zS4t3GOfWGDpfmRKw+jT1OStKfibkr0U93LfQRuw8K2M7UymJAPFRF Lhnveoc8 AxVXaC1SaMF4YefcOR3AN3aZE2Ae9sn0R5WWrO0A2CkTIRDtT9PvzlNVa7y9it7/1UULLZY+KrMYv9d0oER9IEeduV/FU1CUn9yXuFSYb6ejIb4cP5zFUnb0ylIR1bBjh9zg7BiPJmC0U/2RqzmKPBhFmw31OfFC3beq0HOibKllrSRtY1KG00K8I9zmrSKTL8cWq3/olkbdsZSZLXPSYXOqn07SqMEXRABksoJNdpEMK85psZmihzc6zvb2elABVn5BDUlpNy8Srv8vvk5Z7bKKuj6Jjz6u88VPPkPp+DMn/n2kUH+3Bw7iZNi6PYL6Q9nDR/mv76h9V+gYl7YHLeuuUkrrj7n4DMbrCICkDkBvlWuyaRDurvdzzH0yBe+5l3r0ddrEY6eotKZCgEnhGOZbcaTQFSgiJbo/vMa+qiVmvIKUWnufJSM79suvTo0xbGzn7Z9gNJ1W0MGc= 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" 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..837165037231 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_memorty_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_memorty_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,