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) { From patchwork Fri Jun 16 07:05:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13282159 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 DDA89EB64D8 for ; Fri, 16 Jun 2023 07:06:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48DEC8E0005; Fri, 16 Jun 2023 03:06:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EE838E0003; Fri, 16 Jun 2023 03:06:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2420C8E0005; Fri, 16 Jun 2023 03:06:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 07D318E0003 for ; Fri, 16 Jun 2023 03:06:42 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C2ACE1A0B71 for ; Fri, 16 Jun 2023 07:06:41 +0000 (UTC) X-FDA: 80907728202.25.1BBE380 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf28.hostedemail.com (Postfix) with ESMTP id 3C07FC0022 for ; Fri, 16 Jun 2023 07:06:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nZU8NSil; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 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=1686899199; 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=57j5bkDByog/ext/hXgYlpRrsqAj6GMku5TIZq1E3C8=; b=pgaxWf9ukEsI3Gl+i+dLDeS2CD2JHcdaWKpOtfgRxbribqY3dkbR23yzPyVCG2sXAvsnjp N8OFd90G4o4M24VH4Vv4IRuVXF+Av9rGMi/c6PMQhQsQaJ07hNDhcsxdBBLTGvqW8stKbE jRtcNxWUqc9dpX2oKxzz0rjWA3BR8z4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=nZU8NSil; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686899199; a=rsa-sha256; cv=none; b=dsd7GlPmiIaxzGijR1PxqOJHH2JCd5J9L0duIvcfbjBEULE3IiVq48W1QWob6tUb5N0+tA 1yllzoazoLGj+KmCSXOPnppWZCivGxc456bafu14bDxcJove/XphVf4L8N/grPNucDhNRz dKURT7AwtoFrfAmoHDJYGtcWkq0FI9A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686899199; x=1718435199; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Hn5VMwJGt0IXFlVjJsaiQl5L2c0xHT5vclGupSQt0Q=; b=nZU8NSil0LyMc82otetNNk4qQzQkCy/Wkeu5f2peScEpvTi6m1wgfVuI 0w22zW1cJ0tsbBUT4rG+xKFfSd9FeNN7cQCEfEzB7NOZxN4U8Wm3J62W5 C8I9vgg1X2mNWHKqGHD5zpsx2HgqA8ItJTSNngn0FfwcAIOGMElVBBDqx KPPH08FvnR/8AuYkFHI+Wf9zS4x7hzb2H4Ghui/gWnT+ve8uh8KEJYoEG 7ULaet9wq4yYUUsKgTw+QN+Z4P6his5LaZkfbaiQR6EmbYUebaXcPYMt3 QFDDV4uK/ORMZLWQ6Qv7j2y5ZB+1Og/ccyhgzyeUov9JOFqiEUoPYxgi2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361668835" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="361668835" 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:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782783888" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="782783888" 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:12 -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 2/4] acpi, hmat: refactor hmat_register_target_initiators() Date: Fri, 16 Jun 2023 15:05:36 +0800 Message-Id: <20230616070538.190042-3-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: 3C07FC0022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uf9e57y7n7aeszarfsd4jdkfpcc7xp64 X-HE-Tag: 1686899198-949175 X-HE-Meta: U2FsdGVkX1+Dmqujj+XtV/8LicrO8RUGdFAMgiP5wi3jnCMJqnlXOMVP5bKfiKnIz/NZvVDqX+GMhJSzmc3VsYWZZ7V7sR0lys2gSm7g7vt3RoWkjSFF3YY3LbOX0Lh485te0VVDndKFGnhd3w+varBN3Tftuu0ae6L06L4nYD8+sLpzeDLXzhVqFzCysJo32O0BcS0W3I0XWZrAlIjQefsJDbSvSGgVuv3QlohxTgkzJtHwSMymhIZldeg/WZn6lLfoIic8p+K3fNzgG+rd922bNbuMuw667OLVuZMOSQO/uJucKV+FcNcYcNwGbwc7mm8XDxhTx+AiwcPoHmyapq1kDT+cOXSNxiciK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CtmTTtloflhaNx53QjqBVCfdCznwb/dv/tzphbcJi+88G6cCKPCvwKA== 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: Previously, in hmat_register_target_initiators(), the performance attributes are calculated and the corresponding sysfs links and files are created too. Which is called during memory onlining. But now, to calculate the abstract distance of a memory target before memory onlining, we need to calculate the performance attributes for a memory target without creating sysfs links and files. To do that, hmat_register_target_initiators() is refactored to make it possible to calculate performance attributes separately. 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 --- drivers/acpi/numa/hmat.c | 81 +++++++++++++++------------------------- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index bba268ecd802..2dee0098f1a9 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -582,28 +582,25 @@ static int initiators_to_nodemask(unsigned long *p_nodes) return 0; } -static void hmat_register_target_initiators(struct memory_target *target) +static void hmat_update_target_attrs(struct memory_target *target, + unsigned long *p_nodes, int access) { - static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); struct memory_initiator *initiator; - unsigned int mem_nid, cpu_nid; + unsigned int cpu_nid; struct memory_locality *loc = NULL; u32 best = 0; - bool access0done = false; int i; - mem_nid = pxm_to_node(target->memory_pxm); + bitmap_zero(p_nodes, MAX_NUMNODES); /* - * If the Address Range Structure provides a local processor pxm, link + * If the Address Range Structure provides a local processor pxm, set * only that one. Otherwise, find the best performance attributes and - * register all initiators that match. + * collect all initiators that match. */ if (target->processor_pxm != PXM_INVAL) { cpu_nid = pxm_to_node(target->processor_pxm); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - access0done = true; - if (node_state(cpu_nid, N_CPU)) { - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + if (access == 0 || node_state(cpu_nid, N_CPU)) { + set_bit(target->processor_pxm, p_nodes); return; } } @@ -617,47 +614,10 @@ static void hmat_register_target_initiators(struct memory_target *target) * We'll also use the sorting to prime the candidate nodes with known * initiators. */ - bitmap_zero(p_nodes, MAX_NUMNODES); list_sort(NULL, &initiators, initiator_cmp); if (initiators_to_nodemask(p_nodes) < 0) return; - if (!access0done) { - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { - loc = localities_types[i]; - if (!loc) - continue; - - best = 0; - list_for_each_entry(initiator, &initiators, node) { - u32 value; - - if (!test_bit(initiator->processor_pxm, p_nodes)) - continue; - - value = hmat_initiator_perf(target, initiator, - loc->hmat_loc); - if (hmat_update_best(loc->hmat_loc->data_type, value, &best)) - bitmap_clear(p_nodes, 0, initiator->processor_pxm); - if (value != best) - clear_bit(initiator->processor_pxm, p_nodes); - } - if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, - best, 0); - } - - for_each_set_bit(i, p_nodes, MAX_NUMNODES) { - cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 0); - } - } - - /* Access 1 ignores Generic Initiators */ - bitmap_zero(p_nodes, MAX_NUMNODES); - if (initiators_to_nodemask(p_nodes) < 0) - return; - for (i = WRITE_LATENCY; i <= READ_BANDWIDTH; i++) { loc = localities_types[i]; if (!loc) @@ -667,7 +627,7 @@ static void hmat_register_target_initiators(struct memory_target *target) list_for_each_entry(initiator, &initiators, node) { u32 value; - if (!initiator->has_cpu) { + if (access == 1 && !initiator->has_cpu) { clear_bit(initiator->processor_pxm, p_nodes); continue; } @@ -681,14 +641,33 @@ static void hmat_register_target_initiators(struct memory_target *target) clear_bit(initiator->processor_pxm, p_nodes); } if (best) - hmat_update_target_access(target, loc->hmat_loc->data_type, best, 1); + hmat_update_target_access(target, loc->hmat_loc->data_type, best, access); } +} + +static void __hmat_register_target_initiators(struct memory_target *target, + unsigned long *p_nodes, + int access) +{ + unsigned int mem_nid, cpu_nid; + int i; + + mem_nid = pxm_to_node(target->memory_pxm); + hmat_update_target_attrs(target, p_nodes, access); for_each_set_bit(i, p_nodes, MAX_NUMNODES) { cpu_nid = pxm_to_node(i); - register_memory_node_under_compute_node(mem_nid, cpu_nid, 1); + register_memory_node_under_compute_node(mem_nid, cpu_nid, access); } } +static void hmat_register_target_initiators(struct memory_target *target) +{ + static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); + + __hmat_register_target_initiators(target, p_nodes, 0); + __hmat_register_target_initiators(target, p_nodes, 1); +} + static void hmat_register_target_cache(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); From patchwork Fri Jun 16 07:05:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13282160 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 F318AEB64DA for ; Fri, 16 Jun 2023 07:06:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E8FE8E0006; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 771388E0003; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EB858E0006; Fri, 16 Jun 2023 03:06:44 -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 446BF8E0003 for ; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 112E2B032D for ; Fri, 16 Jun 2023 07:06:44 +0000 (UTC) X-FDA: 80907728328.02.AE1ECA7 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf09.hostedemail.com (Postfix) with ESMTP id 97FDD140003 for ; Fri, 16 Jun 2023 07:06:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TBhxk11G; spf=pass (imf09.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=1686899202; 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=N1ImL0LiDS3Sw8ZhB1FTXkgf1C45E0bfpeHiPJsXpmk=; b=IrCzVLRopJZbhxnEj1sF2+TtMW/WwRh2V940A7QAK9ljwfwIluOhWuUilygK2j/2oQjqtf ysERUX44VyF4SU0BK1mIdmis6uLAnYCDICinM87LAqb7nmkBx/9qZqA+LedV7VfCgGTQvq L0rbmAa1gVqK9yphf4Xlc+c3v64Q2tM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686899202; a=rsa-sha256; cv=none; b=nPP1McMRO2G6+bOHGyzhDbwFi88PUmm+326lXFo09ENyXruGh76T9MfF53gk1nHM8SFPpB THfq4aBKeP7pOofcHWHCv2KvYxG6yrODgH5SqV0WIczYjQY6njBDddTHxhlKK2NEnssunI BdPRY5Z+fI/cV5sqbA6tT8IhP3downk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TBhxk11G; spf=pass (imf09.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=1686899202; x=1718435202; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aOdlEaVHTONo9Kej4YBWg+d/l94TirHxQkRvgXaE8BA=; b=TBhxk11GfJTlchFWMJiCsS5f/78y9BDOF7f4Plb0ppAsm/Z6tLivF0w9 H2NHVoGCoQCakK5E4Ge4kgA4lYTmNBN2cqN/XaP5kBEJfHYWbWuzAq+AU 2kwBMJkq4cpGqtFWv2WEv7Zai17xISjdXXOmx639gDTpBkXotgKlHFZ9w R8wYSaOt+jhPCz5RC/40PPX2WvXBeWPBCkp7HZaXpDdyc5U72afA0ZFDx XNiRfXHjdk5E3gt1UaFk1gOVcDzJ6Y6iNy2mq0kD/QE1CDan8OF4+GUhp qkDhdVuOqvTh6niOhNrA7QE4McqZgHuDTH+5SANUOF+l42bgoo5OI7rOk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361668862" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="361668862" 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:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782783995" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="782783995" 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:16 -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 3/4] acpi, hmat: calculate abstract distance with HMAT Date: Fri, 16 Jun 2023 15:05:37 +0800 Message-Id: <20230616070538.190042-4-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: 97FDD140003 X-Rspam-User: X-Stat-Signature: z54zbenzz9b7qsboqfhwdptzqmt74jzr X-Rspamd-Server: rspam03 X-HE-Tag: 1686899201-220674 X-HE-Meta: U2FsdGVkX18GieYabOqPKZbf8gO+NwuDNYlcGsLZ7sZayyUvrAdy8n+nvX32lDN+OLQVtbF4sn8Y6wZXw4otuTr8YYLuewHrurMKjpFfI6TF+mXGHF1LyhQ/LZT+GASPgfn1+iGBz25PfQ7HrhB/D5X1OLkv7QNnCR4Gryrhq7j4TSMqN0FZnHWYLYLES/MHM1a34ZZ3N0uaeehiW9IPNV0xsbLeHwx1hCETsqoxirX4v1MNoWI4V3nRfvTOAPWmuxlACuAIGxAGZMzwpme6MRZNpuE4kcgBhJGsRaDVoOX2mLsEVRt9l/Y9WZ/dgRkL5VaHYnNXQHMVoZehG+qIGEUUEIQ38E6nNeyGPh5wpkqRKgseMgDdtnH/iqdsbzZrf1yNVB3nMT3Uc8r51TV9UzVH7NraBaWggNkBA0eAuiCTT+a2Ng+kXF6Ib/mbrnnteVVc+EuNsQIYMoaxeWI/cjRqFGTCoXMB3EcKWdxP97njmzLby8c8Z8Jzrrli5pUyEBf8wKhRxNrrNrLoCPQ22ElEYMz/qSQPoRe0OTILYP176kzCjqSdALIAOkUcfxkKVZUr11KoXh5dD3751yKAtsqbtCamwYz+DD1Lzx5cTOBP2pssLf2mRBNzRam+pj2S0drv5hDpxqBBqqtfMMZduHX32slEfxKHpkDr0We7ub1GZQv2TlK5QbApzaU1WyLfGStn51EaFqwtUnl4CRgxbHY1sVS6RfEgNUqdyxiu8ofKyKEcP+/v3iyWasV7ZT7ioGXbRmUsCDaxQz1e4hIx46CVVEdBi4QnUounqR0JpumH23GN8vsATaRBuByZm9ZLrBvw6N6WXJWTJ+6135u5pvFUxmk8OK45Z13wPAwyQm0Y3WEUx+mov1obGFnwHClTUlGTM9DeQqyoaQ6yedZXe59MYX3Ski6XpE34lHmFHyvsGcZRnARXZHtDPXWlxjSi1L5Imj6plMpH9xMeQXP Ngs2csqM FX/6KXc7NhvSRH4Vvr7voxMaLkkSnewgRw8kQNuhTnElM2rGVerjyLMmXS9IM2i0w+tEYlwyOiTUq7IhzOooprhxinf1WSYk3IuQxcWHmsNIl0xv6cyHvjHie5BCo+AEpOCvBbxiphhA8whO4UngErPPMXMq6cxQjK21ux9pLcOkWneI0myL1WoHL3IahEnrRP8Q/MAHZcVLj5PZ7q2NrTbv31gs2k90jIN4gkFkxWmRz3tgfcMsDJU2TqnbWTgNFwfkhW8HHZKGRv05Ezo1Ak5AG3ZL3//BA1IMvy3aziLr6DEHva6BCv3yrRu+KnTTd3uO0ykL66WpSGwBHIn42oqW17HJ8jC5TIGXOMaGp4/nULyqfl1NFMXutQ1gkIkaec7UQjOY/SHoHH/0MD5Fg5xgLDP7yXHiAM8DlRDUzzsklFycVSBRBbn+zkSokwbgwxNPVHP1x2pFz81o= 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: A memory tiering abstract distance calculation algorithm based on ACPI HMAT is implemented. The basic idea is as follows. The performance attributes of system default DRAM nodes are recorded as the base line. Whose abstract distance is MEMTIER_ADISTANCE_DRAM. Then, the ratio of the abstract distance of a memory node (target) to MEMTIER_ADISTANCE_DRAM is scaled based on the ratio of the performance attributes of the node to that of the default DRAM nodes. 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 --- drivers/acpi/numa/hmat.c | 124 ++++++++++++++++++++++++++++++++++- include/linux/memory-tiers.h | 2 + mm/memory-tiers.c | 2 +- 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 2dee0098f1a9..21e4deb581ad 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -24,6 +24,7 @@ #include #include #include +#include static u8 hmat_revision; static int hmat_disable __initdata; @@ -759,6 +760,123 @@ static int hmat_callback(struct notifier_block *self, return NOTIFY_OK; } +static int hmat_adistance_disabled; +static struct node_hmem_attrs default_dram_attrs; + +static void dump_hmem_attrs(struct node_hmem_attrs *attrs) +{ + pr_cont("read_latency: %u, write_latency: %u, read_bandwidth: %u, write_bandwidth: %u\n", + attrs->read_latency, attrs->write_latency, + attrs->read_bandwidth, attrs->write_bandwidth); +} + +static void disable_hmat_adistance_algorithm(void) +{ + hmat_adistance_disabled = true; +} + +static int hmat_init_default_dram_attrs(void) +{ + struct memory_target *target; + struct node_hmem_attrs *attrs; + int nid, pxm; + int nid_dram = NUMA_NO_NODE; + + if (default_dram_attrs.read_latency + + default_dram_attrs.write_latency != 0) + return 0; + + if (!default_dram_type) + return -EIO; + + for_each_node_mask(nid, default_dram_type->nodes) { + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + continue; + attrs = &target->hmem_attrs[1]; + if (nid_dram == NUMA_NO_NODE) { + if (attrs->read_latency + attrs->write_latency == 0 || + attrs->read_bandwidth + attrs->write_bandwidth == 0) { + pr_info("hmat: invalid hmem attrs for default DRAM node: %d,\n", + nid); + pr_info(" "); + dump_hmem_attrs(attrs); + pr_info(" disable hmat based abstract distance algorithm.\n"); + disable_hmat_adistance_algorithm(); + return -EIO; + } + nid_dram = nid; + default_dram_attrs = *attrs; + continue; + } + if (abs(attrs->read_latency - default_dram_attrs.read_latency) * 10 > + default_dram_attrs.read_latency || + abs(attrs->write_latency - default_dram_attrs.write_latency) * 10 > + default_dram_attrs.write_latency || + abs(attrs->read_bandwidth - default_dram_attrs.read_bandwidth) * 10 > + default_dram_attrs.read_bandwidth) { + pr_info("hmat: hmem attrs for DRAM nodes mismatch.\n"); + pr_info(" node %d:", nid_dram); + dump_hmem_attrs(&default_dram_attrs); + pr_info(" node %d:", nid); + dump_hmem_attrs(attrs); + pr_info(" disable hmat based abstract distance algorithm.\n"); + disable_hmat_adistance_algorithm(); + return -EIO; + } + } + + return 0; +} + +static int hmat_calculate_adistance(struct notifier_block *self, + unsigned long nid, void *data) +{ + static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); + struct memory_target *target; + struct node_hmem_attrs *attrs; + int *adist = data; + int pxm; + + if (hmat_adistance_disabled) + return NOTIFY_OK; + + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + return NOTIFY_OK; + + if (hmat_init_default_dram_attrs()) + return NOTIFY_OK; + + mutex_lock(&target_lock); + hmat_update_target_attrs(target, p_nodes, 1); + mutex_unlock(&target_lock); + + attrs = &target->hmem_attrs[1]; + + if (attrs->read_latency + attrs->write_latency == 0 || + attrs->read_bandwidth + attrs->write_bandwidth == 0) + return NOTIFY_OK; + + *adist = MEMTIER_ADISTANCE_DRAM * + (attrs->read_latency + attrs->write_latency) / + (default_dram_attrs.read_latency + + default_dram_attrs.write_latency) * + (default_dram_attrs.read_bandwidth + + default_dram_attrs.write_bandwidth) / + (attrs->read_bandwidth + attrs->write_bandwidth); + + return NOTIFY_STOP; +} + +static __meminitdata struct notifier_block hmat_adist_nb = +{ + .notifier_call = hmat_calculate_adistance, + .priority = 100, +}; + static __init void hmat_free_structures(void) { struct memory_target *target, *tnext; @@ -801,6 +919,7 @@ static __init int hmat_init(void) struct acpi_table_header *tbl; enum acpi_hmat_type i; acpi_status status; + int usage; if (srat_disabled() || hmat_disable) return 0; @@ -841,8 +960,11 @@ static __init int hmat_init(void) hmat_register_targets(); /* Keep the table and structures if the notifier may use them */ - if (!hotplug_memory_notifier(hmat_callback, HMAT_CALLBACK_PRI)) + usage = !hotplug_memory_notifier(hmat_callback, HMAT_CALLBACK_PRI); + usage += !register_mt_adistance_algorithm(&hmat_adist_nb); + if (usage) return 0; + out_put: hmat_free_structures(); acpi_put_table(tbl); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index c6429e624244..9377239c8d34 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -33,6 +33,7 @@ struct memory_dev_type { #ifdef CONFIG_NUMA extern bool numa_demotion_enabled; +extern struct memory_dev_type *default_dram_type; 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); @@ -64,6 +65,7 @@ static inline bool node_is_toptier(int node) #else #define numa_demotion_enabled false +#define default_dram_type NULL /* * CONFIG_NUMA implementation returns non NULL error. */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index fb5398e710cc..3aabc7240402 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -37,7 +37,7 @@ struct node_memory_type_map { static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); static struct node_memory_type_map node_memory_types[MAX_NUMNODES]; -static struct memory_dev_type *default_dram_type; +struct memory_dev_type *default_dram_type; static struct bus_type memory_tier_subsys = { .name = "memory_tiering", From patchwork Fri Jun 16 07:05:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13282161 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 788A0EB64D8 for ; Fri, 16 Jun 2023 07:06:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F16838E0007; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9DE38E0003; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF11C8E0007; Fri, 16 Jun 2023 03:06:44 -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 B53BD8E0003 for ; Fri, 16 Jun 2023 03:06:44 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 792E740B09 for ; Fri, 16 Jun 2023 07:06:44 +0000 (UTC) X-FDA: 80907728328.27.E003372 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf28.hostedemail.com (Postfix) with ESMTP id 52BE9C0016 for ; Fri, 16 Jun 2023 07:06:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RcD6kQ8+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 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=1686899202; 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=5gIuz0aTjS9U0fh0qkl+B3NT7lwCN2asmsH/d+KsHDc=; b=xQrFSQM3Jth9tvRDRwf/kM2oz9BBg/uPN2fdsqF8us8xexQtDUpdNznbTRwphBQKFgwOwx qHQaCpML1vy4b+OeWVMIglZptYINHd/KEn+064h/o25pR993kmDGc5iIyLBFyKHPI65QOv FzpkMMkN9KQo6Jl+5ZoBDBy9FIuEvto= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RcD6kQ8+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686899202; a=rsa-sha256; cv=none; b=AB35rL2AWD017FYR1QmbiGK5V9DHEwqaF8U3yhGUfvSHcvbES8HdyxAqxnNZqWLVhpXQDH qmmhfDG7pMjuxpTTx4tv1cTSj0EmPVtToDA62423pvQTPPwOHvAZkuDux9Sj7eIlpQbyM2 pneXxfjj4MOoI1FUDc2FwQ/8o6ztO64= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686899202; x=1718435202; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RTaDfZ9VPFX57fvR1Dzfk2rQNkh7YYvcsGhFjCOwvYY=; b=RcD6kQ8+GPc0EllpS5Ixy8Gga80IhaLvpLS8N1YD3rb07bqM/88Kiwud xKWPe0mnGmTjneo3CSdlEhQ7Zvns7fnk5NVZc2e9O0nTHJYxhnPpjji4L cO29QiVVwTSiaJ960T0ZhJ2Cu+lTsiwsh5odFuj9LILprY+aFqKsV9I++ 9I0WJRDiIn1U8f+oqaGNC2EpQ9XAd9dEStztZu082jH28ftKvdLi26RQR gwgq+R95toPejViBx1ASWZYsm0dk8drskzTEtTxZle6+QFoUJTU/Kde7u WpHIfkQ4e0bqXDaNQ0u37FKDZ26b2pdJoNdKMHfMAv8dHBWJAnKA5faFd A==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361668886" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="361668886" 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:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782784018" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="782784018" 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:19 -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 4/4] dax, kmem: calculate abstract distance with general interface Date: Fri, 16 Jun 2023 15:05:38 +0800 Message-Id: <20230616070538.190042-5-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: 52BE9C0016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eeqc9mscoz9rhebx91frk1x91dnk1dpy X-HE-Tag: 1686899202-416481 X-HE-Meta: U2FsdGVkX19TFjUO3vqgLtQMzXx20tpmQcrpcuhmQEtc57anaaeLR66R76zTpcxQrf8tlBSMp4ERxtQRCkjbkJ1+efu6SNudUphnZ9EjbApsjy9KthQotOD6SgnqHweDkdcpGJiqYm/JuRH5r/TkthNfuKe7BRRMHp0OgJ+gX8AHbeZm9x09bO872BD8PGNx9ie9WM50VNi0uWdB46xuN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TgCuYeS3rYP/L5/d/srl2+PZQHZL0e4z3hWbdVOe1PnJsCZ2uiWG0SGRkgaCAOvv+EstCgpLRdKeJzswmFSGaKlBVAuxVFRgZg1C1rGhfLqbml8ujZ3j+oSC+tyNIWC9hGzUBTWVeBMy0Zb1HApQDwgyoEUwW53BwW6WjuM75TtRK5S6s= 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: Previously, a fixed abstract distance MEMTIER_DEFAULT_DAX_ADISTANCE is used for slow memory type in kmem driver. This limits the usage of kmem driver, for example, it cannot be used for HBM (high bandwidth memory). So, we use the general abstract distance calculation mechanism in kmem drivers to get more accurate abstract distance on systems with proper support. The original MEMTIER_DEFAULT_DAX_ADISTANCE is used as fallback only. Now, multiple memory types may be managed by kmem. These memory types are put into the "kmem_memory_types" list and protected by kmem_memory_type_lock. 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 --- drivers/dax/kmem.c | 54 +++++++++++++++++++++++++++--------- include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 2 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 7b36db6f1cbd..079f53315562 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -49,14 +49,40 @@ struct dax_kmem_data { struct resource *res[]; }; -static struct memory_dev_type *dax_slowmem_type; +static DEFINE_MUTEX(kmem_memory_type_lock); +static LIST_HEAD(kmem_memory_types); + +static struct memory_dev_type *kmem_find_alloc_memorty_type(int adist) +{ + bool found = false; + struct memory_dev_type *mtype; + + mutex_lock(&kmem_memory_type_lock); + list_for_each_entry(mtype, &kmem_memory_types, list) { + if (mtype->adistance == adist) { + found = true; + break; + } + } + if (!found) { + mtype = alloc_memory_type(adist); + if (!IS_ERR(mtype)) + list_add(&mtype->list, &kmem_memory_types); + } + mutex_unlock(&kmem_memory_type_lock); + + return mtype; +} + static int dev_dax_kmem_probe(struct dev_dax *dev_dax) { struct device *dev = &dev_dax->dev; unsigned long total_len = 0; struct dax_kmem_data *data; + struct memory_dev_type *mtype; int i, rc, mapped = 0; int numa_node; + int adist = MEMTIER_DEFAULT_DAX_ADISTANCE; /* * Ensure good NUMA information for the persistent memory. @@ -71,6 +97,11 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } + mt_calc_adistance(numa_node, &adist); + mtype = kmem_find_alloc_memorty_type(adist); + if (IS_ERR(mtype)) + return PTR_ERR(mtype); + for (i = 0; i < dev_dax->nr_range; i++) { struct range range; @@ -88,7 +119,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } - init_node_memory_type(numa_node, dax_slowmem_type); + init_node_memory_type(numa_node, mtype); rc = -ENOMEM; data = kzalloc(struct_size(data, res, dev_dax->nr_range), GFP_KERNEL); @@ -167,7 +198,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) err_res_name: kfree(data); err_dax_kmem_data: - clear_node_memory_type(numa_node, dax_slowmem_type); + clear_node_memory_type(numa_node, mtype); return rc; } @@ -219,7 +250,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax) * for that. This implies this reference will be around * till next reboot. */ - clear_node_memory_type(node, dax_slowmem_type); + clear_node_memory_type(node, NULL); } } #else @@ -251,12 +282,6 @@ static int __init dax_kmem_init(void) if (!kmem_name) return -ENOMEM; - dax_slowmem_type = alloc_memory_type(MEMTIER_DEFAULT_DAX_ADISTANCE); - if (IS_ERR(dax_slowmem_type)) { - rc = PTR_ERR(dax_slowmem_type); - goto err_dax_slowmem_type; - } - rc = dax_driver_register(&device_dax_kmem_driver); if (rc) goto error_dax_driver; @@ -264,18 +289,21 @@ static int __init dax_kmem_init(void) return rc; error_dax_driver: - destroy_memory_type(dax_slowmem_type); -err_dax_slowmem_type: kfree_const(kmem_name); return rc; } static void __exit dax_kmem_exit(void) { + struct memory_dev_type *mtype, *mtn; + dax_driver_unregister(&device_dax_kmem_driver); if (!any_hotremove_failed) kfree_const(kmem_name); - destroy_memory_type(dax_slowmem_type); + list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) { + list_del(&mtype->list); + destroy_memory_type(mtype); + } } MODULE_AUTHOR("Intel Corporation"); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 9377239c8d34..aca22220cb5c 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -24,6 +24,8 @@ struct memory_tier; struct memory_dev_type { /* list of memory types that are part of same tier as this type */ struct list_head tier_sibiling; + /* list of memory types that are managed by one driver */ + struct list_head list; /* abstract distance for this specific memory type */ int adistance; /* Nodes of same abstract distance */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 3aabc7240402..8a763a765238 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -582,7 +582,7 @@ EXPORT_SYMBOL_GPL(init_node_memory_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype) { mutex_lock(&memory_tier_lock); - if (node_memory_types[node].memtype == memtype) + if (node_memory_types[node].memtype == memtype || !memtype) node_memory_types[node].map_count--; /* * If we umapped all the attached devices to this node,