From patchwork Tue Sep 12 08:20:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13381036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A976CA0EC3 for ; Tue, 12 Sep 2023 08:21:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 234A76B00C6; Tue, 12 Sep 2023 04:21:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BEA56B00C7; Tue, 12 Sep 2023 04:21:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05FA06B00C8; Tue, 12 Sep 2023 04:21:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E5CBD6B00C6 for ; Tue, 12 Sep 2023 04:21:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B5333B3F76 for ; Tue, 12 Sep 2023 08:21:32 +0000 (UTC) X-FDA: 81227251224.08.3F5D106 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by imf17.hostedemail.com (Postfix) with ESMTP id AB1634001E for ; Tue, 12 Sep 2023 08:21:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="HC/3EHTc"; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694506890; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ji7FdGjH6794Aq0s2VqnYa3aFeZerXInbOHUuNecxlM=; b=dfDGJjcGJmu5BXxiaVjW6IplPphbG9EDhEP1L+EF6ZiIJ5+LJzSreZiUNzrT1cxDKoaR16 hsL7S6deW/wGdYQ988Po7crG1xiw0lSo01zKi5UPJc1T7cw+a9KKPPDS1QGBd8BpIr8YdK s8lr7MHhmrjeeS1qMHzr+tgLZlYkP/o= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="HC/3EHTc"; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694506890; a=rsa-sha256; cv=none; b=6M3PwBn6eP9RhoNtiapKupnowrW3cdFE4kuWI7cn2C55LX8VrwOrOlozud6j3VZyxW+USA 0fDLq4AbhtZpMOHRvqUBNCfSwM8vSeF408U5xl6o0l+I1UdrSU321rEhTgn9LBwabvLHsO zO+842LmHhdAa7WnwFsdZhUUcAv6xIw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694506890; x=1726042890; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K9eyz/1vX8ET5OccsB4EUKb5BEUHSB2vczhawrkoKN4=; b=HC/3EHTcByPvk8QQgFIcboQNxBuEiKZQPbxB/OCNxRdMPho0SQ6njTMu 7IuZK18HW5meYy9wazXxZODfB9ZybiI1c/YWm8b+Lq/HyS0QS4XGc4ENx QHOPL++FyWqM8ied0izu+SAeKyyshitfe1V0PfkjheL/gAom/S+J+Si/k ylkEAIO6+HM3uKue4s56aB1BExas7FHTFvxbTzCnfAmYJkRZWO2105NkD nSIDKm18DWiaGcE/KhXHIvzvSOoc+B5+3MJwr/vKGUJ7PGmM+Ld+H3p8U ZYDy+AgKJVMUpo3ypER7B7A6y9yyhrM0Sc/FdyuETyxDJErVAsrQQlnid g==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="442323002" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="442323002" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="746787604" X-IronPort-AV: E=Sophos;i="6.02,245,1688454000"; d="scan'208";a="746787604" Received: from shicha9x-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.213]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 01:21:23 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Dave Jiang , Rafael J Wysocki Subject: [PATCH -V3 1/4] memory tiering: add abstract distance calculation algorithms management Date: Tue, 12 Sep 2023 16:20:58 +0800 Message-Id: <20230912082101.342002-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230912082101.342002-1-ying.huang@intel.com> References: <20230912082101.342002-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AB1634001E X-Rspam-User: X-Stat-Signature: f9hwozsgh18usoh1q88b5xemimkgba9n X-Rspamd-Server: rspam01 X-HE-Tag: 1694506890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5d/dlT74IFvGetfFASMmX0C6+iXGY+Bh2rhz3t8ZsKmVftUA1+9mQW4WpjNgvPLRVQG8Ard+L5bCr6GZNNoTjPbhus//G9PxMLN1C5UrtHjMAsI5NY4rm6ysbbFCNGz//OxByaLqsRaxFhPZLMb8VRkcXWjDAirX8hoXWd1iab7mtLiUy4fmCKcEbm2yGmcwWATfyvwckG9qBgO3SJh+Zz4Zhe4GN8IDkjh2legRb47yqkKNbuDbP3JbeYlAx02Vnf+Tt6dza/JCdWJSICfQ5FsubcvkHnFL4SP3NwA1SdzNLkKDAIU0rmpwJ6pt/arQnR8vA+uqeC3pQdZr5fS8Or96/V07jqfO0dOGIf/KvkWeTiM7A+FFtxNZAHhbapMFfOzjEQbU1wo0uvKSz7UiM40Hd19 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The abstract distance may be calculated by various drivers, such as ACPI HMAT, CXL CDAT, etc. While it may be used by various code which hot-add memory node, such as dax/kmem etc. To decouple the algorithm users and the providers, the abstract distance calculation algorithms management mechanism is implemented in this patch. It provides interface for the providers to register the implementation, and interface for the users. Multiple algorithm implementations can cooperate via calculating abstract distance for different memory nodes. The preference of algorithm implementations can be specified via priority (notifier_block.priority). Signed-off-by: "Huang, Ying" Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Dave Jiang Cc: Rafael J Wysocki Reviewed-by: Dave Jiang Reviewed-by: Alistair Popple --- include/linux/memory-tiers.h | 19 ++++++++++++ mm/memory-tiers.c | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 437441cdf78f..c8382220cced 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -6,6 +6,7 @@ #include #include #include +#include /* * Each tier cover a abstrace distance chunk size of 128 */ @@ -36,6 +37,9 @@ struct memory_dev_type *alloc_memory_type(int adistance); void put_memory_type(struct memory_dev_type *memtype); void init_node_memory_type(int node, struct memory_dev_type *default_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype); +int register_mt_adistance_algorithm(struct notifier_block *nb); +int unregister_mt_adistance_algorithm(struct notifier_block *nb); +int mt_calc_adistance(int node, int *adist); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -97,5 +101,20 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int mt_calc_adistance(int node, int *adist) +{ + return NOTIFY_DONE; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 37a4f59d9585..76c0ad47a5ad 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "internal.h" @@ -105,6 +106,8 @@ static int top_tier_adistance; static struct demotion_nodes *node_demotion __read_mostly; #endif /* CONFIG_MIGRATION */ +static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms); + static inline struct memory_tier *to_memory_tier(struct device *device) { return container_of(device, struct memory_tier, dev); @@ -592,6 +595,62 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +/** + * register_mt_adistance_algorithm() - Register memory tiering abstract distance algorithm + * @nb: The notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + * + * Every memory tiering abstract distance algorithm provider needs to + * register the algorithm with register_mt_adistance_algorithm(). To + * calculate the abstract distance for a specified memory node, the + * notifier function will be called unless some high priority + * algorithm has provided result. The prototype of the notifier + * function is as follows, + * + * int (*algorithm_notifier)(struct notifier_block *nb, + * unsigned long nid, void *data); + * + * Where "nid" specifies the memory node, "data" is the pointer to the + * returned abstract distance (that is, "int *adist"). If the + * algorithm provides the result, NOTIFY_STOP should be returned. + * Otherwise, return_value & %NOTIFY_STOP_MASK == 0 to allow the next + * algorithm in the chain to provide the result. + */ +int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(register_mt_adistance_algorithm); + +/** + * unregister_mt_adistance_algorithm() - Unregister memory tiering abstract distance algorithm + * @nb: the notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + */ +int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(unregister_mt_adistance_algorithm); + +/** + * mt_calc_adistance() - Calculate abstract distance with registered algorithms + * @node: the node to calculate abstract distance for + * @adist: the returned abstract distance + * + * Return: if return_value & %NOTIFY_STOP_MASK != 0, then some + * abstract distance algorithm provides the result, and return it via + * @adist. Otherwise, no algorithm can provide the result and @adist + * will be kept as it is. + */ +int mt_calc_adistance(int node, int *adist) +{ + return blocking_notifier_call_chain(&mt_adistance_algorithms, node, adist); +} +EXPORT_SYMBOL_GPL(mt_calc_adistance); + static int __meminit memtier_hotplug_callback(struct notifier_block *self, unsigned long action, void *_arg) {