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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8496C433F5 for ; Thu, 11 Nov 2021 08:20:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A8DB6109D for ; Thu, 11 Nov 2021 08:20:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4A8DB6109D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C13946B009D; Thu, 11 Nov 2021 03:20:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC2846B00A0; Thu, 11 Nov 2021 03:20:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8BCB6B00A1; Thu, 11 Nov 2021 03:20:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 9A4406B009D for ; Thu, 11 Nov 2021 03:20:29 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5BBEC82A1AD1 for ; Thu, 11 Nov 2021 08:20:29 +0000 (UTC) X-FDA: 78795952578.25.5D4007B Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf27.hostedemail.com (Postfix) with ESMTP id 4C55670000B3 for ; Thu, 11 Nov 2021 08:20:27 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10164"; a="256575896" X-IronPort-AV: E=Sophos;i="5.87,225,1631602800"; d="scan'208";a="256575896" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2021 00:20:25 -0800 X-IronPort-AV: E=Sophos;i="5.87,225,1631602800"; d="scan'208";a="602529955" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.239.159.101]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2021 00:20:22 -0800 From: "Huang, Ying" To: Baolin Wang Cc: , , , , , , , , Subject: Re: [PATCH v2 1/2] mm: migrate: Support multiple target nodes demotion References: Date: Thu, 11 Nov 2021 16:20:20 +0800 In-Reply-To: (Baolin Wang's message of "Thu, 11 Nov 2021 15:48:34 +0800") Message-ID: <87zgqbm7cr.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4C55670000B3 X-Stat-Signature: c7yy6rqf6fbx3yq4ak853e7r95i66iix Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf27.hostedemail.com: domain of ying.huang@intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=ying.huang@intel.com X-HE-Tag: 1636618827-537297 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: Baolin Wang writes: > We have some machines with multiple memory types like below, which > have one fast (DRAM) memory node and two slow (persistent memory) memory > nodes. According to current node demotion policy, if node 0 fills up, > its memory should be migrated to node 1, when node 1 fills up, its > memory will be migrated to node 2: node 0 -> node 1 -> node 2 ->stop. > > But this is not efficient and suitbale memory migration route > for our machine with multiple slow memory nodes. Since the distance > between node 0 to node 1 and node 0 to node 2 is equal, and memory > migration between slow memory nodes will increase persistent memory > bandwidth greatly, which will hurt the whole system's performance. > > Thus for this case, we can treat the slow memory node 1 and node 2 > as a whole slow memory region, and we should migrate memory from > node 0 to node 1 and node 2 if node 0 fills up. > > This patch changes the node_demotion data structure to support multiple > target nodes, and establishes the migration path to support multiple > target nodes with validating if the node distance is the best or not. > > available: 3 nodes (0-2) > node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 > node 0 size: 62153 MB > node 0 free: 55135 MB > node 1 cpus: > node 1 size: 127007 MB > node 1 free: 126930 MB > node 2 cpus: > node 2 size: 126968 MB > node 2 free: 126878 MB > node distances: > node 0 1 2 > 0: 10 20 20 > 1: 20 10 20 > 2: 20 20 10 > > Signed-off-by: Baolin Wang > --- > mm/migrate.c | 138 +++++++++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 102 insertions(+), 36 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index cf25b00..126e9e6 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -50,6 +50,7 @@ > #include > #include > #include > +#include > > #include > > @@ -1119,12 +1120,25 @@ static int __unmap_and_move(struct page *page, struct page *newpage, > * > * This is represented in the node_demotion[] like this: > * > - * { 1, // Node 0 migrates to 1 > - * 2, // Node 1 migrates to 2 > - * -1, // Node 2 does not migrate > - * 4, // Node 3 migrates to 4 > - * 5, // Node 4 migrates to 5 > - * -1} // Node 5 does not migrate > + * { nr=1, nodes[0]=1 }, // Node 0 migrates to 1 > + * { nr=1, nodes[0]=2 }, // Node 1 migrates to 2 > + * { nr=0, nodes[0]=-1 }, // Node 2 does not migrate > + * { nr=1, nodes[0]=4 }, // Node 3 migrates to 4 > + * { nr=1, nodes[0]=5 }, // Node 4 migrates to 5 > + * { nr=0, nodes[0]=-1 }, // Node 5 does not migrate > + * > + * Moreover some systems may have multiple slow memory nodes. > + * Suppose a system has one socket with 3 memory nodes, node 0 > + * is fast memory type, and node 1/2 both are slow memory > + * type, and the distance between fast memory node and slow > + * memory node is same. So the migration path should be: > + * > + * 0 -> 1/2 -> stop > + * > + * This is represented in the node_demotion[] like this: > + * { nr=2, {nodes[0]=1, nodes[1]=2} }, // Node 0 migrates to node 1 and node 2 > + * { nr=0, nodes[0]=-1, }, // Node 1 dose not migrate > + * { nr=0, nodes[0]=-1, }, // Node 2 does not migrate > */ > > /* > @@ -1135,8 +1149,13 @@ static int __unmap_and_move(struct page *page, struct page *newpage, > * must be held over all reads to ensure that no cycles are > * observed. > */ > -static int node_demotion[MAX_NUMNODES] __read_mostly = > - {[0 ... MAX_NUMNODES - 1] = NUMA_NO_NODE}; > +#define DEFAULT_DEMOTION_TARGET_NODES 15 > +struct demotion_nodes { > + unsigned short nr; > + short nodes[DEFAULT_DEMOTION_TARGET_NODES]; > +}; > + > +static struct demotion_nodes node_demotion[MAX_NUMNODES] __read_mostly; > > /** > * next_demotion_node() - Get the next node in the demotion path > @@ -1149,6 +1168,8 @@ static int __unmap_and_move(struct page *page, struct page *newpage, > */ > int next_demotion_node(int node) > { > + struct demotion_nodes *nd = &node_demotion[node]; > + unsigned short target_nr, index; > int target; > > /* > @@ -1161,9 +1182,25 @@ int next_demotion_node(int node) > * node_demotion[] reads need to be consistent. > */ > rcu_read_lock(); > - target = READ_ONCE(node_demotion[node]); > - rcu_read_unlock(); > + target_nr = READ_ONCE(nd->nr); > + > + if (target_nr == 0) { > + target = NUMA_NO_NODE; > + goto out; > + } else if (target_nr == 1) { > + index = 0; > + } else { > + /* > + * If there are multiple target nodes, just select one > + * target node randomly. > + */ > + index = get_random_int() % target_nr; > + } How about use "switch" here? Best Regards, Huang, Ying > + > + target = READ_ONCE(nd->nodes[index]); > > +out: > + rcu_read_unlock(); > return target; > } > [snip]