From patchwork Fri Jun 16 07:05:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13282157 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 1F93DEB64D7 for ; Fri, 16 Jun 2023 07:06:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96FA58E0002; Fri, 16 Jun 2023 03:06:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F73E8E0003; Fri, 16 Jun 2023 03:06:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74A008E0002; Fri, 16 Jun 2023 03:06:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 607FE8E0001 for ; Fri, 16 Jun 2023 03:06:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 22DA380B38 for ; Fri, 16 Jun 2023 07:06:37 +0000 (UTC) X-FDA: 80907728034.07.6DB6A19 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf23.hostedemail.com (Postfix) with ESMTP id 1309214000A for ; Fri, 16 Jun 2023 07:06:34 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=KkCYPB0P; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 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=1686899195; 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=f9dHLj6EuEPxVfNQUBMaHH4/HauCewxglkMxL+7RNpI=; b=MVDHlbuCfGNBGTzWBRnuD4JmmVFBMEGp4ICXD4tY4d/po8fh1DzraxIKjtVHCm5Fc0mLfw F6m5/P8ScBUPCyAPw8+9toOTzG3K5CfBiPH4RaAuVUy+d+Iv9AU95Mvv/wnuV9yTgC6f8y 3/8i9zHw+WMEW6iUsyq+aI/UTvpy7f4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686899195; a=rsa-sha256; cv=none; b=E78KqYw57v+TFvz5NRrR84IF2jQehWY5mJOLD5CfAmRUGlOOgVIKwFvif6WDxFuzWyKYO5 HUtn168yubtYpY5CW5mQ1WAwYMq6sJfWOudsAakmed6zgR5Pl3Ia1kebFIpItS19WYU/YW 12/sHB9GzDd9TjZc4i9QQC5EGAn43gA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=KkCYPB0P; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 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=1686899195; x=1718435195; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BOTZijuFBGgF9HYlGd8ChHaPOkRYQrtLy4cnXooPCAY=; b=KkCYPB0P0yOHxLuDHl3qwi6AcRuhLrYsF+OS1Mw0FzT5UxpFPLTVO1H7 i8+jfvhWWw3MJIoxO7FLr0I7+o2QfWcHhszgXwWVqkiNd8PHLFcyVhtDM VfRHq0TCG4RVWphYCRqNthlJj7MiHasX0fG+Pbz9rjd5qck7sr1/jFrLl J0uTzZwR04+Y1dma0yBjYyqnM+uIE+EQAsSkpOFLAgXr8GAPQwMzbUubc K9SANo1QHvLWXaIqBdUNGzZGO1vi2hScvyNeXGhz5SJCnvZkRxytpx6ZO xpj7t8S3gCCUPUYxJA27tsCQK6DaWrDXboeIluXnaAjTc8Q772paaEnSx g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361668720" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="361668720" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 00:06:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782783610" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="782783610" Received: from cpeng15-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.216]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 00:06:08 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , 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: [RFC 1/4] memory tiering: add abstract distance calculation algorithms management Date: Fri, 16 Jun 2023 15:05:35 +0800 Message-Id: <20230616070538.190042-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230616070538.190042-1-ying.huang@intel.com> References: <20230616070538.190042-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1309214000A X-Rspam-User: X-Stat-Signature: inw8xn8at7hpb4j1ca781cotqbaui7ru X-Rspamd-Server: rspam03 X-HE-Tag: 1686899194-418927 X-HE-Me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EOfnDNuJ8754kCIHqIus1FNQ2R7C8ZDxaFihxB3jEXYNx1R2PXFrrlU1mRBAEOCkLU/aBetefbakvazOCoOo5rqVWSt1p7UKSirbkCKC/H74vUagYheUK67IMG1WmZdJRo0PSDwsx7IlpOczL5lAM9FvlP5tHhecmEcX5ht+rwi3PLuTZ8RLmE2PAGO8faunIYZgMuRG7bN9vyo5nZWWn7ThBSFfiNNYkQ8MDJGzaggq2SclKVkCNopmM9UPMoy1JcmrxHILaq6umoJJ/gLEippBdFtLCNZBw79hZIQ8XzxZXRVf6Jhxq8U5JGmqCUduDoO7cy5jnYixDyOCWymJnDaPfYk8WdGv3x0C+vUWVAinwKgvlZtN3+D0= 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 e593e56e530b..fb5398e710cc 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); @@ -593,6 +596,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) {