From patchwork Wed Aug 16 08:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13354644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98BA2C001DF for ; Wed, 16 Aug 2023 08:00:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E76E28000F; Wed, 16 Aug 2023 04:00:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1978F8D0021; Wed, 16 Aug 2023 04:00:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0371228000F; Wed, 16 Aug 2023 04:00:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E4D728D0021 for ; Wed, 16 Aug 2023 04:00:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9DC5A1A0E58 for ; Wed, 16 Aug 2023 08:00:53 +0000 (UTC) X-FDA: 81129221586.11.69A2AD3 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf25.hostedemail.com (Postfix) with ESMTP id D8A79A0021 for ; Wed, 16 Aug 2023 08:00:49 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EC96gV75; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692172850; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bMi8kwv5PwRwtKD94IS03m8QJZf3Yln7zhQx3eNqK00=; b=pxyRYPPzIO1B/qlfn0iiSjqjWsKCL1NyAYPCUJg9MIcyxW+YfAZ+nSF1H5ljV3znM0ZSHf HER77Grp6MVWyoOPgYcm/PF0DwXQWb3dJwq08w4ankQvtaeIez7xNscEl80C/a8NsVpSUx NVN1VbYTnVGaFHsv5a6E6GOQ14wkHVA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EC96gV75; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692172850; a=rsa-sha256; cv=none; b=mH3Q99ziNrJkYXoQv6bHXEv9uDnvq1GcKrlDIbPm54vyx4UBnjCrbagUNk+gDZ7g9wUlSj HBRz1rT8KLeav5z1mI5qwCsmnHj9JZPLGu59zNNjnfPp5MM4PrYU/LgpqCrYOQfhtvxDuG 67T2YvY6PG107wcUadRQba731/3IGqE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692172849; x=1723708849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=981so79sA8EfMDrE64ZhtP9K9RrUiad1BJbeNjjyXCc=; b=EC96gV75kr38IixpOpyTzs3fcAR3lhlhqD+XY11Om1SQ8OLFR+1GuQ2i DyaBzxW10BZRBiisVoV+BQaw5W+MmnJTmKYs+A6OaX50iKxbIE0e9p9SG mzaW31WBSwpgZMWWFKfzFb9K2s7lNzQ2OF81nLBMsTAWmm/TCiv66tMa9 aVi0KcGj9jcs7b2vUwDr92DJ9Nd8UpuzZWF9vs0jon/Rpl7jiBx5LnSvu T1yj/UzGRpBanh4N7WT3+VEDd/3gS1GHKBqQbzlCjKjoPfbn6GAbTenbP BAojkf6oLjg1XOVLP4dnlfcj8Y8V7gW5OQQvgPmxru4PBJz8Y96iB7yyB w==; X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="352058159" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="352058159" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="804112793" X-IronPort-AV: E=Sophos;i="6.01,176,1684825200"; d="scan'208";a="804112793" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 01:00:42 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Rafael J Wysocki Subject: [PATCH -V2 1/4] memory tiering: add abstract distance calculation algorithms management Date: Wed, 16 Aug 2023 16:00:21 +0800 Message-Id: <20230816080024.105554-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230816080024.105554-1-ying.huang@intel.com> References: <20230816080024.105554-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D8A79A0021 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t4pdnkdcdas87zibra18xyc7tiuusfng X-HE-Tag: 1692172849-72452 X-HE-Meta: U2FsdGVkX18YwzltgrLpv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kfaKIdimgLsEPbpBrXea+/ywbqnXyVE1QuzR8gMDCat1ku5FhkIg/Q1tT9/N5pM8snAS0RyhonRvSJycv+iaNPPe3joryFggGWS0bSbrLENksQJ0zeLpRRYKUAMiiy8eynivGea9lSvWN/jzl1iMfQ9yOsvIqmUacIE3nui5B690aeXUGzyMS5P+2fUuQIfrNLRjC5g1gJ3lTAIMcrPig0BGZ/bp4iwGXBZwRT9vQ7f+/Nwf8mu7G9JZw9Wdef8NrbWKvd5CaYL65AAqCRX2LN/mTyBoGVPUf8yem4L5G7fdY4MnZmF9iPD+1pB2bbUrQQI5XQ+Rwqq6Y4rJb/8ivqmYIkLT2W5wAbKyga9ybgq5UO1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The abstract distance may be calculated by various drivers, such as ACPI HMAT, CXL CDAT, etc. While it may be used by various code which hot-add memory node, such as dax/kmem etc. To decouple the algorithm users and the providers, the abstract distance calculation algorithms management mechanism is implemented in this patch. It provides interface for the providers to register the implementation, and interface for the users. Multiple algorithm implementations can cooperate via calculating abstract distance for different memory nodes. The preference of algorithm implementations can be specified via priority (notifier_block.priority). Signed-off-by: "Huang, Ying" Tested-by: Bharata B Rao Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Rafael J Wysocki --- include/linux/memory-tiers.h | 19 ++++++++++++ mm/memory-tiers.c | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index fc9647b1b4f9..c6429e624244 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -6,6 +6,7 @@ #include #include #include +#include /* * Each tier cover a abstrace distance chunk size of 128 */ @@ -36,6 +37,9 @@ struct memory_dev_type *alloc_memory_type(int adistance); void destroy_memory_type(struct memory_dev_type *memtype); void init_node_memory_type(int node, struct memory_dev_type *default_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype); +int register_mt_adistance_algorithm(struct notifier_block *nb); +int unregister_mt_adistance_algorithm(struct notifier_block *nb); +int mt_calc_adistance(int node, int *adist); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -97,5 +101,20 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return 0; +} + +static inline int mt_calc_adistance(int node, int *adist) +{ + return NOTIFY_DONE; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index a516e303e304..1e55fbe2ad51 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "internal.h" @@ -105,6 +106,8 @@ static int top_tier_adistance; static struct demotion_nodes *node_demotion __read_mostly; #endif /* CONFIG_MIGRATION */ +static BLOCKING_NOTIFIER_HEAD(mt_adistance_algorithms); + static inline struct memory_tier *to_memory_tier(struct device *device) { return container_of(device, struct memory_tier, dev); @@ -592,6 +595,62 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +/** + * register_mt_adistance_algorithm() - Register memory tiering abstract distance algorithm + * @nb: The notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + * + * Every memory tiering abstract distance algorithm provider needs to + * register the algorithm with register_mt_adistance_algorithm(). To + * calculate the abstract distance for a specified memory node, the + * notifier function will be called unless some high priority + * algorithm has provided result. The prototype of the notifier + * function is as follows, + * + * int (*algorithm_notifier)(struct notifier_block *nb, + * unsigned long nid, void *data); + * + * Where "nid" specifies the memory node, "data" is the pointer to the + * returned abstract distance (that is, "int *adist"). If the + * algorithm provides the result, NOTIFY_STOP should be returned. + * Otherwise, return_value & %NOTIFY_STOP_MASK == 0 to allow the next + * algorithm in the chain to provide the result. + */ +int register_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(register_mt_adistance_algorithm); + +/** + * unregister_mt_adistance_algorithm() - Unregister memory tiering abstract distance algorithm + * @nb: the notifier block which describe the algorithm + * + * Return: 0 on success, errno on error. + */ +int unregister_mt_adistance_algorithm(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&mt_adistance_algorithms, nb); +} +EXPORT_SYMBOL_GPL(unregister_mt_adistance_algorithm); + +/** + * mt_calc_adistance() - Calculate abstract distance with registered algorithms + * @node: the node to calculate abstract distance for + * @adist: the returned abstract distance + * + * Return: if return_value & %NOTIFY_STOP_MASK != 0, then some + * abstract distance algorithm provides the result, and return it via + * @adist. Otherwise, no algorithm can provide the result and @adist + * will be kept as it is. + */ +int mt_calc_adistance(int node, int *adist) +{ + return blocking_notifier_call_chain(&mt_adistance_algorithms, node, adist); +} +EXPORT_SYMBOL_GPL(mt_calc_adistance); + static int __meminit memtier_hotplug_callback(struct notifier_block *self, unsigned long action, void *_arg) {