From patchwork Wed Jul 12 07:48:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13309691 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 9E010EB64D9 for ; Wed, 12 Jul 2023 07:49:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 355636B0075; Wed, 12 Jul 2023 03:49:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 304A66B0078; Wed, 12 Jul 2023 03:49:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CCC16B007B; Wed, 12 Jul 2023 03:49:23 -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 107BE6B0075 for ; Wed, 12 Jul 2023 03:49:23 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CC59680146 for ; Wed, 12 Jul 2023 07:49:22 +0000 (UTC) X-FDA: 81002184564.04.A2B1D2B Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf26.hostedemail.com (Postfix) with ESMTP id AEED3140005 for ; Wed, 12 Jul 2023 07:49:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CCpea1Y8; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 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=1689148161; 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=fB4XWEG+M5RZuLpFmnNEQRMD3RhZogTLIBzc5Bki6k8AmAipv5i+ff487SAHvS4FLwZhoF 6bBwbVdgizArz+I7Yn4uK8KQUuSrgiY5ampO0wmOxIw20ycLt6TIjU5EAz4SUFT2yCAp3P 79nooawiDiT3TltH03xjHnKt2qyK7Qs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=CCpea1Y8; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689148161; a=rsa-sha256; cv=none; b=dq7h9pPFgwKXgV5ylzgkrjlFEXuyd7hsX0fYnx7ByoFSXqpimV1bCJVjmEUbk5UONJfruJ P0fWsiRRwQ4Cmko36jt1l5Y2dA2TbEReZU08ivGLOdFgeztcvhQgW+wa1UO0lBNZqHH31h uGve+p/iuBlWKXek0pOKJ9Z6ibQGOxw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689148160; x=1720684160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oyCI5HLzYg6B8dSBk9eHwDqLZtZfH++WogxlpW3EVlc=; b=CCpea1Y8JfChiLzEwYeKGOmHDwb7XucutXG4QLfEsEaf1m1rNVgnxtKv I3uXTkOvgp+lO31+P6Ajph3aVW+78UCIkCX04A/b1J/S3ThvwNvKYImNA QA/HhLDSFyWKRV/ATkeEmjKa2d48tnHgFPZpBZZoYoXaHxmRnm201dNAS J7uucV7RTixgu3uAYudGzP29djiS6hvzC9cbc+R4u5uypOlp5vxCLLbBC JXnggtsScB541RZqAZ1TLVGVN2HfrXDyw40kPOq2v1RT3TAuxxmf9fDiP 01NFSiI1c0N6/l7pLpAESyPGtDxTnZVA1KJilbhdhEIRbNeUb4840EVue w==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354734519" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="354734519" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="698744859" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="698744859" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:16 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@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 1/4] memory tiering: add abstract distance calculation algorithms management Date: Wed, 12 Jul 2023 15:48:57 +0800 Message-Id: <20230712074900.404064-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712074900.404064-1-ying.huang@intel.com> References: <20230712074900.404064-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: AEED3140005 X-Stat-Signature: 593nim9xhk7qz4t4xitzcf8zddg7i5ei X-HE-Tag: 1689148160-873944 X-HE-Meta: U2FsdGVkX1+l0Wb+n6ycYG55IPOlI2d5dwudgQo5tv1P2aA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xHB5YJExEP867A+m1R8zXrdwXX6rLZyGsW2WJrNaXvQcRTc84bLCYSyebgGY80o49QP0b8q/AsuNcj/H8OvlSyPpHGxU62zI1T4iDWUu3YPb+yno3v3Xlan1FBXaaWmqgZsmZBLZvyTDd/YzIk1sLiedsmfcOkdDJRnSMZZgX7oFQTEFdrlU86hOVJlAMJvKpu/v33EVnwBJx9UETnaDSVxfu1aQHFnyI9jEG/0CKkyf4EJob6KYjfLymmAql4z00XhLzN7nqgJHYwSPxUZcosDiccsDluJEqu/9gWd/HdUhILCsbT8hK/G/Pc+GTU= 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 Wed Jul 12 07:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13309692 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 0E1DFEB64D9 for ; Wed, 12 Jul 2023 07:49:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E3D96B0078; Wed, 12 Jul 2023 03:49:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 993ED8D0001; Wed, 12 Jul 2023 03:49:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85C566B007D; Wed, 12 Jul 2023 03:49:27 -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 787AF6B0078 for ; Wed, 12 Jul 2023 03:49:27 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 56F7DA01A8 for ; Wed, 12 Jul 2023 07:49:27 +0000 (UTC) X-FDA: 81002184774.03.9DA527F Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf22.hostedemail.com (Postfix) with ESMTP id 259ADC0019 for ; Wed, 12 Jul 2023 07:49:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iZDGd3wN; spf=pass (imf22.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 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=1689148165; 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=yD+oBUmD36ErKbQf6FKkSOw0Z+sVIuji3cuOQxcMre/xIpM1F55iNSoP8OSn5nQ/lkMxk2 Oig+92zoYJ5sS2uyjzroCPswFE6UKnt61+zi7b9NiDqqJfe0upT7Kg/C8NUL5TqiYjsxh7 bhXS3JdOdNNRJZ2vWvt0QJrT2kOJQsA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689148165; a=rsa-sha256; cv=none; b=ws6EJeaJfat1DnbCEzxpgXoYf5qnKLbwgTRqbJvsctg5oUv2/AWAiWgVtzmuLzukzF0tED MEafy1fkb5r94aGm3ZEs8OoaiOXF5fTJH4F55/RdBdxpMJWpMlfhF5bmMfMu/AsUGB5zAL bYClaJ9AFIv22e17bfhCuTrhCsUgVdU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iZDGd3wN; spf=pass (imf22.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 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=1689148165; x=1720684165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Hn5VMwJGt0IXFlVjJsaiQl5L2c0xHT5vclGupSQt0Q=; b=iZDGd3wNTqK+XRLuqdhq+Y7bRe0FxpYlKs8uFcNStDcf+7xdS3DZbVyc PUEARMMYjQgQBUq3uikpO5Xk83y0xZOceT5GkXk1vS037WrnqyyrH7dMW 514cLMqzP+ZPvbzVPRh1RDuB6eRpfqSfRSwncKGgs7flTE91d+G+sG0dC dRMlaXovVz61VJjhjIlCXZN1z2ssGT3E0LfVUFIUwY1VJ8gUlvrU9BbPl unB4nD5h6JixxOSwCkPb+1jjACyu3sOYQkfOv/RPwk3CnQCgHLbsjOWMh xDnBCgUEmKXXMg6i8utUg0aY0n4tZlxC1fLiRn2AuZ3SfGpM1zNQcqD5L A==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354734552" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="354734552" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="698744883" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="698744883" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:20 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@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 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Wed, 12 Jul 2023 15:48:58 +0800 Message-Id: <20230712074900.404064-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712074900.404064-1-ying.huang@intel.com> References: <20230712074900.404064-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 259ADC0019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pc6o1fy81w6i8yq95afmbcpf7fneqagh X-HE-Tag: 1689148164-117260 X-HE-Meta: U2FsdGVkX18voyu0QFeyp+0ARdE2ZYCpXbhSkCs7FwxWiX+gXNqcHOA8Xs2sruZ3PyNk+O5NkMYrqU+xz6quSWNP0JQDDNOYEPUOh/RfOGkFu21PfobnwDrmLc14NsW8xS8nyU3RX66VIMgrZZ6MkyjlkNdvWX3XWzDOw0W2uq3sZfImI4k7shQuRJqGtOAxr0SOdWxLqs0NUwXnUWnyli4N/5xl9zUNfkzvcD/8O1FmuobPkQTOt/q8U5OYYhz0acm5mD0pLIzxiO6grINvknZBw09tse3Jjfcyafbteih0z+AUJDQXSuIVzbzQqVtC/FWVzBYpbHTkioB0hBDdyNL62rmKMdIH7K4AJv8lblY3iqMTKYo26J73s5rK0ELW0KfY/pkJBM9EheRiWrWygZOXzz0hvXM4JznRcBRGE9dzrwuRaKOY4KAeEsau1i/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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 --- drivers/acpi/numa/hmat.c | 81 +++++++++++++++------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index bba268ecd802..2dee0098f1a9 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -582,28 +582,25 @@ static int initiators_to_nodemask(unsigned long *p_nodes) return 0; } -static void hmat_register_target_initiators(struct memory_target *target) +static void hmat_update_target_attrs(struct memory_target *target, + unsigned long *p_nodes, int access) { - static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); struct memory_initiator *initiator; - unsigned int mem_nid, cpu_nid; + unsigned int cpu_nid; struct memory_locality *loc = NULL; u32 best = 0; - bool access0done = false; int i; - mem_nid = pxm_to_node(target->memory_pxm); + bitmap_zero(p_nodes, MAX_NUMNODES); /* - * If the Address Range Structure provides a local processor pxm, link + * If the Address Range Structure provides a local processor pxm, set * only that one. Otherwise, find the best performance attributes and - * register all initiators that match. + * collect all initiators that match. */ if (target->processor_pxm != PXM_INVAL) { cpu_nid = pxm_to_node(target->processor_pxm); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - access0done = true; - if (node_state(cpu_nid, N_CPU)) { - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + if (access == 0 || node_state(cpu_nid, N_CPU)) { + set_bit(target->processor_pxm, p_nodes); return; } } @@ -617,47 +614,10 @@ static void hmat_register_target_initiators(struct memory_target *target) * We'll also use the sorting to prime the candidate nodes with known * initiators. */ - bitmap_zero(p_nodes, MAX_NUMNODES); list_sort(NULL, &initiators, initiator_cmp); if (initiators_to_nodemask(p_nodes) < 0) return; - if (!access0done) { - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { - loc = localities_types[i]; - if (!loc) - continue; - - best = 0; - list_for_each_entry(initiator, &initiators, node) { - u32 value; - - if (!test_bit(initiator->processor_pxm, p_nodes)) - continue; - - value = hmat_initiator_perf(target, initiator, - loc->hmat_loc); - if (hmat_update_best(loc->hmat_loc->data_type, value, &best)) - bitmap_clear(p_nodes, 0, initiator->processor_pxm); - if (value != best) - clear_bit(initiator->processor_pxm, p_nodes); - } - if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, - best, 0); - } - - for_each_set_bit(i, p_nodes, MAX_NUMNODES) { - cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - } - } - - /* Access 1 ignores Generic Initiators */ - bitmap_zero(p_nodes, MAX_NUMNODES); - if (initiators_to_nodemask(p_nodes) < 0) - return; - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { loc = localities_types[i]; if (!loc) @@ -667,7 +627,7 @@ static void hmat_register_target_initiators(struct memory_target *target) list_for_each_entry(initiator, &initiators, node) { u32 value; - if (!initiator->has_cpu) { + if (access == 1 && !initiator->has_cpu) { clear_bit(initiator->processor_pxm, p_nodes); continue; } @@ -681,14 +641,33 @@ static void hmat_register_target_initiators(struct memory_target *target) clear_bit(initiator->processor_pxm, p_nodes); } if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, best, 1); + hmat_update_target_access(target, loc->hmat_loc->data_type, best, access); } +} + +static void __hmat_register_target_initiators(struct memory_target *target, + unsigned long *p_nodes, + int access) +{ + unsigned int mem_nid, cpu_nid; + int i; + + mem_nid = pxm_to_node(target->memory_pxm); + hmat_update_target_attrs(target, p_nodes, access); for_each_set_bit(i, p_nodes, MAX_NUMNODES) { cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + register_memory_node_under_compute_node(mem_nid, cpu_nid, access); } } +static void hmat_register_target_initiators(struct memory_target *target) +{ + static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); + + __hmat_register_target_initiators(target, p_nodes, 0); + __hmat_register_target_initiators(target, p_nodes, 1); +} + static void hmat_register_target_cache(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); From patchwork Wed Jul 12 07:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13309693 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 1D266EB64DA for ; Wed, 12 Jul 2023 07:49:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63CB38D0001; Wed, 12 Jul 2023 03:49:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ECC96B007D; Wed, 12 Jul 2023 03:49:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2D48D0001; Wed, 12 Jul 2023 03:49:32 -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 3D8976B007B for ; Wed, 12 Jul 2023 03:49:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0DF7D1401A0 for ; Wed, 12 Jul 2023 07:49:32 +0000 (UTC) X-FDA: 81002184984.18.5905EF0 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf24.hostedemail.com (Postfix) with ESMTP id E3CCF180005 for ; Wed, 12 Jul 2023 07:49:29 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hQaYVZ2v; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 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=1689148170; 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=yRfSm6XjCKAjw16oFAA1V/D/4VXrMUelbT9g4oPS8EwcMvA3M4AypzVmvvf1zqD61ek6zh CkjWf2pHPhaD30LhmkYBxWyWGhTmwO5Un8BPOqOHD8YpX4Ik2XHpl6W2h3P+wvsNSFYAXy Nw64xZ2VPIgsQDu77+GCmUyPHVrlSa8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hQaYVZ2v; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689148170; a=rsa-sha256; cv=none; b=e+RiXeq4/OCWytwvicmTUPPEul3auxmnPWbOwDLJNhAB4wDNpKkUFURFLZbM7wBA2krE1e u7GgFBh15W9YjfXdWu552mLPXNEkp3ZkGJCaAxs6VjDCAEcXicuTSPQZ/QjVMhfiNecJlN h70MnCUHdEssk3qa870CB5dUhUNQyLQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689148170; x=1720684170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fvluWJnQxPJxRNFSQvnsXlILnnh9VajCo65nakKALGw=; b=hQaYVZ2vhxXWLq6EssSWQ1hxoTiJ9R8nvrWJZS+nCCf1SZKrzEqhLUxy cazCXec0p0z9bsm0/l7rondVqQ6nf+qqtP0prtwcmHe9SUSwt7jYzu5an WO09VHIVk38TTSwhzvwZCoOmsJx8weLR9Wz3wRmOeO6sopc1NcPfW9hnw yIuTW5ZLcZfj6EaHa1JU2IrxGZOCLPRe5zgNPo1AnF9P+9qNsVI9igSPn Jx/UBgM6O7bca6b/nZVW5dEXGPfaJ1hQnYq8A5TAr6A0CG7R8V9HTGhCL 9coJ5OS0PRiCKwhlS43pOy067x7JWM0BhzoD46rWHu4HXr9e7PDK7oL11 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354734583" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="354734583" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="698744921" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="698744921" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:24 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@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 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Wed, 12 Jul 2023 15:48:59 +0800 Message-Id: <20230712074900.404064-4-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712074900.404064-1-ying.huang@intel.com> References: <20230712074900.404064-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E3CCF180005 X-Stat-Signature: xmniiaq4bwh9umu45o83wnc61kk14nw3 X-Rspam-User: X-HE-Tag: 1689148169-934005 X-HE-Meta: U2FsdGVkX18LtJi5lAwl/TphCWgtI73GuDFbl+nBYUH4Ov5LVQ/FmUCx6TbwoG3EX1PQGy49g4Fp3jX1LzVy2/aYqQPoYv/Wr8HvJlMdcGfKVtMxFoGXbGlLcni2ZEFVqPoyqs5+iCCsxLHAIioGEJJbTN4ZXGLW1L+wZm94ANpEK1SQoekxCwqVRzEdphDZu4qJ09xEjhs7QrJllA/gihoCHQRRbAPzwPDtKWTiBJxy8oWYgSK5gxQq0nv3AB1MN80oiKn0Kks4VoXrCATnDEH1KRClVxY/azsQFnM4JILdajdh+5VTSUrO68+jih1QqwzJqOrNKEF+ez41kLR7ZVHapXInkxfvQQ6z4RnQGk3UjX9AASgdSlsBJEd/VDnWDEE954CuZ2IohJVxiu1vBFt1uw14ACSvnsk1gdSf1fD3uuzWt64z6NoCd4xCLWxbYMFFZcnfvb/YJhAL0rgm42jozxODnsWzwMJRzU0BYdStuVtAcjMfvkKvBdYMw67X4qzx6DM+QpC1dsG3BnnDJrHoodrjDe6CobrmC/LSBdf9rMYqob2vXlBjrRTmNUsb8OTUMYKvEYD+DTLiraO6d5+e7+SJDgvBqBt/gavrtzb41+xF86mj/KBUACGWoOZXGFp0qW83/NOfGQJA3FhtChuAI3XHVfFg/2pMznTLX90sxKcki4uScDD9B9okPcXJzY4RhbBtnHMJ2yAQRrw+Yi3w7o/Wsz0LX6DSp2ywANXTLS93JdddYSvA25Jn94FBreI+ezLljEk7+3aduSZfEY/5TJlrzd5XuEM54fLg20hrnIQSbnSKVOkWXDonXfAHYwLjk3pDP5M8y+QmsCcY6Do5ISoJ+pZnGU3k5Bpwar7w3Af636NmC6ih2kjav9mShFFA2D+/Qi2LGnjWyidb4wShZzqIoSKl904wbpvGYFBwFIoMmNVQjXnfgEbeMl3V5uRUF0fVOicSwBXU/R2 bl1aPUxC ZV8TmdUjvbxxvOE4PcRoVnJTIEWT0vUWbycwXcX0iI1ECFMIQCUPGQpR6P9dVNUC19RDWhbzZdLw66d7weniCYGPRP/fYhzmHZFZwCnAEi08xvbyjqADXTu95vhSS84Fl1nt13Nz6gtToHKU8JXm4BmtCg8AbXQHnBLmlCwSik0zomiaa2Nckpz+ETzLDXy27drjNTtiJ5M7XCTAI9yp8XFSlXDjnxQ+gWXCCIRq853XEJ9ugZoz92xfIRbOeNVKA7CltTXxQgLmU+sHlAzVujIEQsZUaao3tWVu2eIfK69MIPtK6yyoNgCv+FvqUzOFJmIDCoc6GXKSQ8E5BGQMeNzYTc8Ts1mfbBBRmgVCJMajEShJBJDlC4C7yqjq4IwIxf2SPXNfENZUIDMFx/cY5s8LcBtXBWlLFhmk5S9O+8sTOdnDPRgNMtQP6ZGNNnm6eHzc0YW04NoaRvkQ= 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 Wed Jul 12 07:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13309694 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 4D296EB64D9 for ; Wed, 12 Jul 2023 07:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB4506B0071; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D653A6B007B; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C36E16B007E; Wed, 12 Jul 2023 03:49:36 -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 B57ED6B007B for ; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 831A71C7C07 for ; Wed, 12 Jul 2023 07:49:36 +0000 (UTC) X-FDA: 81002185152.15.90186CF Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf23.hostedemail.com (Postfix) with ESMTP id 6DFA3140010 for ; Wed, 12 Jul 2023 07:49:34 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j2Vu5ABt; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 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=1689148174; 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=m6WYoGYnZKphtDJSSX37BQFQWnrgRH1/kdmrPNzcUsocga1YRqIW2yaqby4GEZBh5Z8CPp dvPY7dKRfjXGUbIsHWXFZyPfnWZ3XA93/UjRJ5mIkOVNZyjCMy34VTwnXAQbIA5RU3Jepf MJ4+9KUjbubyfPsXHAIstwepvr/PcXU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j2Vu5ABt; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689148174; a=rsa-sha256; cv=none; b=73G8PnTuxZnVxWntOfDrc1VF8/MBFtdwbs0P4IuwG2hFz1qJxbc6sjvCA74C0TZBa69MNX gSx/lUwVuFoS64tMHV46Ktia+Vza5v4Vz5HSqR9+DwG3sH+6BUm9mqtQvnIRqqaDxhXlye dJtYSaU7TtbdPSDo25A5GtVVZec5DPo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689148174; x=1720684174; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WgH5xLOkBW2Y/oZqJhHhP4ppJv8kSHk1fii5X3wpokk=; b=j2Vu5ABtCQknjfJ9Ox4IzukC7ujq5jzaWSPUPu+/yWVsinkzQR20z5Sl 2pZrkAnBiald3r4/OweZwstyz2uy9OKfzyU0ww3rbqpHS4jiZG6Jx+Bo/ sv8MRLnW+9it49Ga2k2M6hHs68UljTWcBHMlFHwnbMc5j/H1LgSHopoc1 xdhDNRb5MygdgUE4ctzTYf0OAKGFDWyfvLLD3jYkc1rkpSZfnzP5/OGjK bNJ7uA+krCTJhQ3mr1UXR4oUm/3TJYWdt691bmP1MmRr06Z18Kh9B18zz UITR42DC1m/0tw4U43jX4je0FAiCdDlGToR7z9Z6wNiAi+7zbhxn0h3rw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354734625" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="354734625" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="698744941" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="698744941" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:28 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@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 4/4] dax, kmem: calculate abstract distance with general interface Date: Wed, 12 Jul 2023 15:49:00 +0800 Message-Id: <20230712074900.404064-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712074900.404064-1-ying.huang@intel.com> References: <20230712074900.404064-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: zsx8absknqpqgjbo7ed1cqmm55hhfp1s X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6DFA3140010 X-HE-Tag: 1689148174-558165 X-HE-Meta: U2FsdGVkX19wX/G9b6ZXQKyxCEms4EMXkjkai1NNhCR2QKQcCxXiCHikzNWo7mwCSJlbQ756Y0tUpY+BGUDzfWJG12wLY2N41dcFYzMbpDTFNb7HPU9fHL5LimgQbjGruUBYbzgu/ZkDg+i/4sX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dBV8+brxC2nrQ7jXX0X5YKMDbVJw1g0P4BJCeZLY1+PZWDsdNLf9FpRRMSPlTc+XAUKz5+pnXgGTkHn4d8TMFPQTG76wmmBhhcyMLI+/yTrnEdtFj30BwGvqj2jhLDbiDVxKHV+VCaR1kPul9YEWYUtkqVQpVrMmBiEepX976ZHO3OeQGT+VoaIKHdmSIuaq7NGwiClRIK1gZMrfqcccCwWXt0lOup0rFEO/zHA= 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,