diff options
author | Tim Chen <tim.c.chen@linux.intel.com> | 2016-10-07 20:00:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-07 21:46:28 -0400 |
commit | 03e86dba5b628a13a58adae62e5b918b969ae93e (patch) | |
tree | a35beb97eff3c45cb1bb83eeb9570d9bf58b30e4 | |
parent | dbe6ec815641aa22b50775aaeb47fa3a8d04ccf1 (diff) |
cpu: fix node state for whether it contains CPU
In current kernel code, we only call node_set_state(cpu_to_node(cpu),
N_CPU) when a cpu is hot plugged. But we do not set the node state for
N_CPU when the cpus are brought online during boot.
So this could lead to failure when we check to see if a node contains
cpu with node_state(node_id, N_CPU).
One use case is in the node_reclaime function:
/*
* Only run node reclaim on the local node or on nodes that do
* not
* have associated processors. This will favor the local
* processor
* over remote processors and spread off node memory allocations
* as wide as possible.
*/
if (node_state(pgdat->node_id, N_CPU) && pgdat->node_id !=
numa_node_id())
return NODE_RECLAIM_NOSCAN;
I instrumented the kernel to call this function after boot and it always
returns 0 on a x86 desktop machine until I apply the attached patch.
int num_cpu_node(void)
{
int i, nr_cpu_nodes = 0;
for_each_node(i) {
if (node_state(i, N_CPU))
++ nr_cpu_nodes;
}
return nr_cpu_nodes;
}
Fix this by checking each node for online CPU when we initialize
vmstat that's responsible for maintaining node state.
Link: http://lkml.kernel.org/r/20160829175922.GA21775@linux.intel.com
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
Acked-by: David Rientjes <rientjes@google.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: <Huang@linux.intel.com>
Cc: Ying <ying.huang@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | mm/vmstat.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/mm/vmstat.c b/mm/vmstat.c index dc04e76c7950..73aab319969d 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c | |||
@@ -1715,6 +1715,16 @@ static void __init start_shepherd_timer(void) | |||
1715 | round_jiffies_relative(sysctl_stat_interval)); | 1715 | round_jiffies_relative(sysctl_stat_interval)); |
1716 | } | 1716 | } |
1717 | 1717 | ||
1718 | static void __init init_cpu_node_state(void) | ||
1719 | { | ||
1720 | int cpu; | ||
1721 | |||
1722 | get_online_cpus(); | ||
1723 | for_each_online_cpu(cpu) | ||
1724 | node_set_state(cpu_to_node(cpu), N_CPU); | ||
1725 | put_online_cpus(); | ||
1726 | } | ||
1727 | |||
1718 | static void vmstat_cpu_dead(int node) | 1728 | static void vmstat_cpu_dead(int node) |
1719 | { | 1729 | { |
1720 | int cpu; | 1730 | int cpu; |
@@ -1772,6 +1782,7 @@ static int __init setup_vmstat(void) | |||
1772 | #ifdef CONFIG_SMP | 1782 | #ifdef CONFIG_SMP |
1773 | cpu_notifier_register_begin(); | 1783 | cpu_notifier_register_begin(); |
1774 | __register_cpu_notifier(&vmstat_notifier); | 1784 | __register_cpu_notifier(&vmstat_notifier); |
1785 | init_cpu_node_state(); | ||
1775 | 1786 | ||
1776 | start_shepherd_timer(); | 1787 | start_shepherd_timer(); |
1777 | cpu_notifier_register_done(); | 1788 | cpu_notifier_register_done(); |