From mboxrd@z Thu Jan 1 00:00:00 1970 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 7D6E8EB64D8 for ; Tue, 20 Jun 2023 05:03:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0CC18D0003; Tue, 20 Jun 2023 01:03:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBC278D0001; Tue, 20 Jun 2023 01:03:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83D68D0003; Tue, 20 Jun 2023 01:03:24 -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 AA0A68D0001 for ; Tue, 20 Jun 2023 01:03:24 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6CA98C0530 for ; Tue, 20 Jun 2023 05:03:24 +0000 (UTC) X-FDA: 80921932728.21.34130A4 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf07.hostedemail.com (Postfix) with ESMTP id A841540009 for ; Tue, 20 Jun 2023 05:03:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cMBohvtb; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf07.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=1687237402; a=rsa-sha256; cv=none; b=YBLhB5qFD1GknPJF2R7+fTTx0gTFbL22YHgBZGqXAGZh7zoRztRKPRniHVu5YRvBZXKQaB a9iXibE0GAMglyBb2Ef5JWK0cML9qlzRlhR10hElvhmzxiCv4Y3d0Y4PQhKeNpNIOcAwS/ owIhPIUyiNYKCvYU0bFrdeRkpphIjlo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cMBohvtb; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf07.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=1687237402; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LjOakcmz/Gl2KfxKQ6F5s+JPJiPX+tbqwj2zmGwZkGI=; b=ALwkSOj4nrnj5/prnEootnazspHPUX5yy2jyVBeULjh5/BHxdp/w0f5yEOvPiWGZwmOTSi KJlrKk5dn6+xxMduRz+0v3Y28+7LUkn0ehvB/0m7HW6kXjnjq2c5a/nednoIXrnnN4dbyL aDZ+v/wha0L4cRVDvN+J3sXRNHKsIMA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687237401; x=1718773401; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=cnS/cu2Wflxtyu8R7xE428+IO3kIRTADI/+XFzqP+Yw=; b=cMBohvtbFeG+lZnMrfRhh0psZsb+elHjy0KLTlP0fNtw+W2YseAJo1Rb 4mWMgXGo3coMe/AJZxlua+M2saLWzkMrDSm2dHSSWgAx6vxzYHg0Gl+EH JPpoY07InB46A36MLQkjL1cHgK3TE2QgPkb6dodxTFtdhOGXWCdrJlciw JI6ZzNSXoMKUfddC/wdzs6Z2Uq1HQY9XXSyC20G9SDZ8fnuTLc1+tDdWr Tw4F6s2gxPEchSO7Z8/2mOO8Sd/1jXQ4FJLx7dCL7fPWrq9f6l0/wct9/ Nl1K4JsuvJC6jURqnGfCCo+4l29rcoogc0bK47ZD1AcQEw6NMQ+vSJuIo A==; X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="349494974" X-IronPort-AV: E=Sophos;i="6.00,256,1681196400"; d="scan'208";a="349494974" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2023 22:03:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="664152869" X-IronPort-AV: E=Sophos;i="6.00,256,1681196400"; d="scan'208";a="664152869" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2023 22:03:16 -0700 From: "Huang, Ying" To: "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Rafael J Wysocki Subject: Re: [RFC 3/4] acpi, hmat: calculate abstract distance with HMAT References: <20230616070538.190042-1-ying.huang@intel.com> <20230616070538.190042-4-ying.huang@intel.com> <87352nifox.fsf@linux.ibm.com> Date: Tue, 20 Jun 2023 13:01:41 +0800 In-Reply-To: <87352nifox.fsf@linux.ibm.com> (Aneesh Kumar K. V.'s message of "Mon, 19 Jun 2023 21:53:42 +0530") Message-ID: <87352m916y.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A841540009 X-Stat-Signature: cuwy5hu4wy1c7kbsx9iubrptb81yaf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dIi2LitlJ6lQjuVX9Xy72n7zGNhKiy/vxVF61zE6yWNQM7EALsrGdC/0jN+h0zeJhLVsShtHgzL91rHhxLbYvKyd3AZl62uVWQZNEFSpgPJKdaFw7iWH2KkQ90DfKz0O3LvvZnHESmeEAhHw5PXTz93xdnoqhamrtb5A1UvkTvVpFF/pMyun6YCKS7im7i54ATYxdWPoIHXf8bnG1k67oqv3crLFwxeEHbom1hpRfPtpSVcn6UEt1YnEpA0QhzBmcv768cnmlIa2OWVqGw2gcroG6CiOGNqcp/mrI9SFLZLTfXORG34h/R562usaWRLlz7/XTSF4GDjwzDHXmA24GwTMgai7NgYWA6DKzeP4uSItXXvt7yQYp8RnmA/kC2nXLP9sb+CkcvHVp3bhjSJKBrey+s7Tbq91z2J17XXoclmeJwd710QnmF/BI5cackJHytMA= 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: Hi, Aneesh, Thanks for your comments. "Aneesh Kumar K.V" writes: > Huang Ying writes: > >> 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; >> + } > > What is this check about? what is the significance of 10? Can you add > the details as a code comment ? We want to check the validity of HMAT here. We expect the performance of all default DRAM nodes are almost same, that is, the variation is less than 10%. And that will be used as base to calculate the abstract distance of other memory devices. If there is large variation among the performance of default DRAM nodes, it's hard to set a reasonable base for abstract distance calculation. I will add some comments for this in the next version. > >> + } >> + >> + 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); > > > Can you write a comment describing how we use all these attributes in > deriving the abstract distance value? Sure. How about the following text? The abstract distance of a memory node is in direct proportion to its memory latency (read + write) and inversely proportional to its memory bandwidth (read + write). The abstract distance, memory latency, and memory bandwidth of default DRAM nodes are used as base. Best Regards, Huang, Ying > >> + >> + 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", >> -- >> 2.39.2