Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10302890rwp; Thu, 20 Jul 2023 18:52:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFhRAHCTZk6/NCKIsXYpaJQMO59u4nMCQwPu147UxUfmDEZ21esZ15Yit7d/y55nHiq13MB X-Received: by 2002:a05:6402:5154:b0:51d:d295:6741 with SMTP id n20-20020a056402515400b0051dd2956741mr357246edd.6.1689904368468; Thu, 20 Jul 2023 18:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689904368; cv=none; d=google.com; s=arc-20160816; b=sEo4ISmYQ+GytHUVDGyR6Q88FXk0BouQgjEGu5SCULuQJ73IqPcM/eNbn3wZtR7q4r Vs4Y6+5KK8TNmniVvgvinZmJhGh6BGMcR0+79I08VqEfv53w5CvsGv58gSCUUEHHoVm4 fXUhytW7LHyVbKQe3yZdzrG9h6pXhTtTWC9N9LzWENnsbc0yC2h7CoYqzPsORh2tnskm gOZ6cj3SazKMnkuhLo4ee4WV6CHtp+SzH8+dglBbKi5Ti/oupOwjX51L4cKZdwTIK0j5 6RZgkxhsETQKbeXpIn8Nsn8iP0pKYen94V+eZbTS/Idf0gJwfComGV8dCqpvcYB9hqMw D1PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mwlR3P3BI/k6pKiodh+YaDuSPT0DQXy8CnCLXSzimOg=; fh=lzKkhZyaUrhNkIakGPxlbJijiu34Upm1x29wDAUxkMQ=; b=m6rXmzgh60wwwgH6xs2fJAyivgjymmguVg3/+hDr3lx7gBXgto8ThmUL3ZBClSqk+T Mw1ATJjKR9iX6oFMMe1S5eoWazNJUIYtPkGI8VUfyIMH7Hyn1TQ6130LIiqWCodO83TR RmdU/B2FOxZ2RioI99qtZjjvWSgisxaoD/6HOEd7nKxUbDl8M3m7m/8enMOP/siQzEL6 mGZ5uBpIwO8kG2UtnRWqd+tQ9u0ZNvQrn0gUUPZ2uGNZEL3jm+N8VpDph7pox1miPMSH MHRcBFo2A4bvqhmRwP0shegUJqDy10d/NnvUz7p2evuwEdDVm1zoGu147Fd21uBel1Ja t2aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hYrzwCZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020aa7c3d2000000b0051dd1d7fbeasi1564421edr.683.2023.07.20.18.52.22; Thu, 20 Jul 2023 18:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hYrzwCZc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbjGUBpQ (ORCPT + 99 others); Thu, 20 Jul 2023 21:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjGUBpL (ORCPT ); Thu, 20 Jul 2023 21:45:11 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E632727; Thu, 20 Jul 2023 18:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689903909; x=1721439909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oyCI5HLzYg6B8dSBk9eHwDqLZtZfH++WogxlpW3EVlc=; b=hYrzwCZc++J66V74kF1EeCIuDYRMacBixXqxGr++AKCnk+uUxvuIKrw7 7Y1Vz+YpKO4fJM9lTMxdNgaPl1AM4+t4uM7/C/SGJn5IoU4NzWyYXPIGp OdFq1+bvE4EAzYMPk4QC3FfB+sfxsmtp9D2Y28Aj/jHnfhMAWl+IwbiMG 5q++hKwhMOjUqjitfRbeIfuk3Q7uhLzOvpbG0Illl706u8Op7cFSkcI6r pR1ZOJb4aMu6a1iOygZnsEIYS5ZPipZsOYsFZARU9hrjHaS7vBDipXFFG dWuxJ45Ck6pw0EtriOFJD8wgVtu3qLzvVgo5jOEUYp+JeG9MsAcp8JVhx Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="347214137" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="347214137" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="724670918" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="724670918" Received: from yanfeng1-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.29.24]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 18:45:04 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-acpi@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 RESEND 1/4] memory tiering: add abstract distance calculation algorithms management Date: Fri, 21 Jul 2023 09:29:29 +0800 Message-Id: <20230721012932.190742-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230721012932.190742-1-ying.huang@intel.com> References: <20230721012932.190742-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { -- 2.39.2