Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5450532yba; Wed, 10 Apr 2019 20:58:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFZonDrNUjynORuCmRTYOA4kfgHTBh7+NMCe87TpXA7pS6C1EZGRbJF6u0lt7D8X6JlZIh X-Received: by 2002:a17:902:4381:: with SMTP id j1mr45844569pld.75.1554955098631; Wed, 10 Apr 2019 20:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554955098; cv=none; d=google.com; s=arc-20160816; b=Ye9Hn0g+SBt1HLHKvbJwnX3KLvnCJmuqgIswwT0DvgRmB3oJS3yxKKr3WEOFl5ro85 MeHFd7XlMfRlcND/Y6OBPw+VoboJWq9bL05Qz4dsDBGUq25WX/y0E6POSHKlx7AULD2w Hkp/nEcsahEpsJ+hP65LqzMD7f+8CHp1bF1UWGYbRH4GMdr93L2/RHYqyLG5R9muHJRl xxb9rNBIbzxb8GFUVCcM94TmbNAjbMsXEsdKZA7yJsfV/f8l1VnAs1itUf5uwFPSXHQx owsOlQNqRKioa4UV0qoIFV1t44mdtSvscn9u4xTXkJ/IuZmwy5E3fCe2Iy/mi65283u7 oo8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=zT5IRyMHrSI4fnrzELRIPvo8b6vbfkc3L02HfOTWYA0=; b=TcvHJS2TfTonG/CJuWQaLumZYyTMIHhYpHgvyhbmlikkqF+T45Kq+oiFyXg2vQrFyL KM9jc666QLXnbmEogA4gWntXxXoCoqdq8M+IVQdh8oo62GQjO1bTM2s8m8Ys+IqmLVRb QvkkCPZ2mWksDslKNwUjMdbzLQ4nVisedWe7sBtwNJWKNREMEEgfPCX+hQh9jIgvcknG irtwUg09DxXaAyfk95VKKMoX5ePxglpvCG0auv8A4hrgSX45RYp6vBXudr8XbLmdJiir Y0tbF1YF3XOA7+qcQPkMvhRbxVxGlnr2NVm1d0Bqn8UIkpY12pN7aNXo1vJJJGnMrSNt E6Pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s34si33894752pgl.97.2019.04.10.20.58.02; Wed, 10 Apr 2019 20:58:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726805AbfDKD5Z (ORCPT + 99 others); Wed, 10 Apr 2019 23:57:25 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:44216 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbfDKD5Z (ORCPT ); Wed, 10 Apr 2019 23:57:25 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R761e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0TP0I5rB_1554955031; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TP0I5rB_1554955031) by smtp.aliyun-inc.com(127.0.0.1); Thu, 11 Apr 2019 11:57:22 +0800 From: Yang Shi To: mhocko@suse.com, mgorman@techsingularity.net, riel@surriel.com, hannes@cmpxchg.org, akpm@linux-foundation.org, dave.hansen@intel.com, keith.busch@intel.com, dan.j.williams@intel.com, fengguang.wu@intel.com, fan.du@intel.com, ying.huang@intel.com, ziy@nvidia.com Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 1/9] mm: define N_CPU_MEM node states Date: Thu, 11 Apr 2019 11:56:51 +0800 Message-Id: <1554955019-29472-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1554955019-29472-1-git-send-email-yang.shi@linux.alibaba.com> References: <1554955019-29472-1-git-send-email-yang.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kernel has some pre-defined node masks called node states, i.e. N_MEMORY, N_CPU, etc. But, there might be cpuless nodes, i.e. PMEM nodes, and some architectures, i.e. Power, may have memoryless nodes. It is not very straight forward to get the nodes with both CPUs and memory. So, define N_CPU_MEMORY node states. The nodes with both CPUs and memory are called "primary" nodes. /sys/devices/system/node/primary would show the current online "primary" nodes. Signed-off-by: Yang Shi --- drivers/base/node.c | 2 ++ include/linux/nodemask.h | 3 ++- mm/memory_hotplug.c | 6 ++++++ mm/page_alloc.c | 1 + mm/vmstat.c | 11 +++++++++-- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 86d6cd9..1b963b2 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -634,6 +634,7 @@ static ssize_t show_node_state(struct device *dev, #endif [N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY), [N_CPU] = _NODE_ATTR(has_cpu, N_CPU), + [N_CPU_MEM] = _NODE_ATTR(primary, N_CPU_MEM), }; static struct attribute *node_state_attrs[] = { @@ -645,6 +646,7 @@ static ssize_t show_node_state(struct device *dev, #endif &node_state_attr[N_MEMORY].attr.attr, &node_state_attr[N_CPU].attr.attr, + &node_state_attr[N_CPU_MEM].attr.attr, NULL }; diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 27e7fa3..66a8964 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -398,7 +398,8 @@ enum node_states { N_HIGH_MEMORY = N_NORMAL_MEMORY, #endif N_MEMORY, /* The node has memory(regular, high, movable) */ - N_CPU, /* The node has one or more cpus */ + N_CPU, /* The node has one or more cpus */ + N_CPU_MEM, /* The node has both cpus and memory */ NR_NODE_STATES }; diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index f767582..1140f3b 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -729,6 +729,9 @@ static void node_states_set_node(int node, struct memory_notify *arg) if (arg->status_change_nid >= 0) node_set_state(node, N_MEMORY); + + if (node_state(node, N_CPU)) + node_set_state(node, N_CPU_MEM); } static void __meminit resize_zone_range(struct zone *zone, unsigned long start_pfn, @@ -1569,6 +1572,9 @@ static void node_states_clear_node(int node, struct memory_notify *arg) if (arg->status_change_nid >= 0) node_clear_state(node, N_MEMORY); + + if (node_state(node, N_CPU)) + node_clear_state(node, N_CPU_MEM); } static int __ref __offline_pages(unsigned long start_pfn, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 03fcf73..7cd88a4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -122,6 +122,7 @@ struct pcpu_drain { #endif [N_MEMORY] = { { [0] = 1UL } }, [N_CPU] = { { [0] = 1UL } }, + [N_CPU_MEM] = { { [0] = 1UL } }, #endif /* NUMA */ }; EXPORT_SYMBOL(node_states); diff --git a/mm/vmstat.c b/mm/vmstat.c index 36b56f8..1a431dc 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1910,15 +1910,22 @@ static void __init init_cpu_node_state(void) int node; for_each_online_node(node) { - if (cpumask_weight(cpumask_of_node(node)) > 0) + if (cpumask_weight(cpumask_of_node(node)) > 0) { node_set_state(node, N_CPU); + if (node_state(node, N_MEMORY)) + node_set_state(node, N_CPU_MEM); + } } } static int vmstat_cpu_online(unsigned int cpu) { + int node = cpu_to_node(cpu); + refresh_zone_stat_thresholds(); - node_set_state(cpu_to_node(cpu), N_CPU); + node_set_state(node, N_CPU); + if (node_state(node, N_MEMORY)) + node_set_state(node, N_CPU_MEM); return 0; } -- 1.8.3.1