From patchwork Tue Sep 26 06:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13398704 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 2FCF1E7D0C5 for ; Tue, 26 Sep 2023 06:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE48D8D0061; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B93B28D0005; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A353F8D0061; Tue, 26 Sep 2023 02:06:53 -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 8E27C8D0005 for ; Tue, 26 Sep 2023 02:06:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6DE651CAED8 for ; Tue, 26 Sep 2023 06:06:53 +0000 (UTC) X-FDA: 81277715106.27.173A532 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf12.hostedemail.com (Postfix) with ESMTP id 6A07140004 for ; Tue, 26 Sep 2023 06:06:50 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XS+1mUQ+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695708410; a=rsa-sha256; cv=none; b=3jon2EOma/7+le3uWLdKHknIUS62nphfxe1FSJodNBijWpRH55Ti3+MAl6vVYVqdnzuihN 0rKyjXjfZGQFKAiZ+S7yyyQN8zaP039ftPU1PK5HUdLCPqJ1FmMALSBQU6wQMhKA0FuofJ 1xogVSfdKlpFHJiQ8oInfNGBbCBpwlQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=XS+1mUQ+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1695708410; 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=jpsRs6vQ0NjJ+/nsEn1pGv/AH/u/TSOL1LsQ+VgK/ac=; b=JTNg/FLMc/kxXsuZmpRVOthC/R/Uye+UxSbqcl+5pfC4FQR/c+I284nHqdvmKsjl2OnoS/ 3bgWvzq8fAyDxlzYNZ7wB+WYQgQEIisG26d9v7Gj7MMattDxOwt0Qy0fYvLKqtgCVIXHwJ tGEBCVK7fMU7gCU9PNlyvpHRTR5P+7I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695708410; x=1727244410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fpxsnW+xQLEWo8iAGh4opiRsZsy5mqUtfGIRqyXDBpc=; b=XS+1mUQ+Q17L8HHEQjpgV2O0xM9CPBZnBmWZShNPfodAJ+Bg0nNmccDd L78elWL6V0ht3H4MoNMpX7LnQ5wKtgMhF3Qvn4qLJZEcs6WxYL1B/F7FF boaAJ8iGqZKpz836DyNuSYNoi3TlRMn8EqyweB6gypZXLIpj0GEnsldLo nMWQC/MfZANBg3PspbKNHwiyUIhqaVSfr02jiSiJNnhA7uZ2rD7bA37Ef lSyr4DjMbN/vpLTyIGmwRMHC3tgaCTT792dImUpSaFlAxsQ44J2WP2LEQ LZ3cOmwusuYspi0Ge1rs2wva57Iq2log3HvzvQUYLPYirFFZ2YXSt3ymN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="447990812" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="447990812" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:06:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="892074770" X-IronPort-AV: E=Sophos;i="6.03,177,1694761200"; d="scan'208";a="892074770" Received: from aozhu-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.94]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2023 23:05:39 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Bharata B Rao , Alistair Popple , Dave Jiang , "Aneesh Kumar K . V" , Wei Xu , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Rafael J Wysocki Subject: [PATCH -V4 1/4] memory tiering: add abstract distance calculation algorithms management Date: Tue, 26 Sep 2023 14:06:25 +0800 Message-Id: <20230926060628.265989-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230926060628.265989-1-ying.huang@intel.com> References: <20230926060628.265989-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6A07140004 X-Stat-Signature: r8gd6senq5jhuu97ykmg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jn+VSx3mF3w1S2I37sRsLMuMf4X/656Jd55vJF2oRnQf6qULGxUDpKUMPkEGMKG224qeafUNnMuXqhTzJhyKkomitvWdQlatfXI/2jq2LIfScQaFrVTn2+dEa9WykBSuf0FHSh+3Jmhnupy53b3/r2gOZwEL8N4sRXlcU5r/uTTT4IdLyPP6JtcupgxyII+O7Z6B1YeNoKwo7gBx723+ON2VIN81/qJwcugga58PzDZo9Equ/2RsPP9rsh1VkLd/wqiqVlLs0vN/yH25K99TPOVkfgj8/v91xkMO2ICEwNksnA0pl+7oouLHRMetAkXE+KbkSg84jkplUye0PjVGIDOKY+alYJetq16/9UmXH78mV9re9WcAs9DHLPVfH/nL1ReN7WWWxzb0rfb0PcKF/dOzBrOZYdWaG8hKnjVQvbqYBR2GYjIf4 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 Reviewed-by: Alistair Popple Reviewed-by: Dave Jiang Cc: Aneesh Kumar K.V Cc: Wei Xu 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 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) {