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) {