Skip to contentSkip to conversation

Offline memoryless cpuless node 0

PATCH Applied Srikar Dronamraju 2 participants 5 messages Aug 18, 2020 – Sep 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover Offline memoryless cpuless node 0

Changelog v5:->v6:
- Now the fix is Powerpc specific.
(David Hildenbrand, Michal Hocko, Christopher Lamater)
- rebased to v5.8
link v5: https://lore.kernel.org/linuxppc-dev/[email protected]/t/#u

Changelog v4:->v5:
- rebased to v5.8
link v4: http://lore.kernel.org/lkml/[email protected]/t/#u

Changelog v3:->v4:
- Resolved comments from Christopher.
Link v3: http://lore.kernel.org/lkml/[email protected]/t/#u

Changelog v2:->v3:
- Resolved comments from Gautham.
Link v2: https://lore.kernel.org/linuxppc-dev/[email protected]/t/#u

Changelog v1:->v2:
- Rebased to v5.7-rc3
- Updated the changelog.
Link v1: https://lore.kernel.org/linuxppc-dev/[email protected]/t/#u

Linux kernel configured with CONFIG_NUMA on a system with multiple possible nodes, marks node 0 as online at boot. However in practice, there are systems which have node 0 as memoryless and cpuless.

This can cause
1. numa_balancing to be enabled on systems with only one online node.
2. Existence of dummy (cpuless and memoryless) node which can confuse users/scripts looking at output of lscpu / numactl.

This patchset wants to correct this anomaly.

This should only affect systems that have CONFIG_MEMORYLESS_NODES. Currently there are only 2 architectures ia64 and powerpc that have this config.

Note: Patch 3 in this patch series depends on patches 1 and 2. Without patches 1 and 2, patch 3 might crash powerpc.

v5.8
available: 2 nodes (0,2)
node 0 cpus:
node 0 size: 0 MB
node 0 free: 0 MB
node 2 cpus: 0 1 2 3 4 5 6 7
node 2 size: 32625 MB
node 2 free: 31490 MB
node distances:
node 0 2

   0:  10  20
   2:  20  10

proc and sys files
------------------

 /sys/devices/system/node/online:            0,2
 /proc/sys/kernel/numa_balancing:            1
 /sys/devices/system/node/has_cpu:           2
 /sys/devices/system/node/has_memory:        2

/sys/devices/system/node/has_normal_memory: 2
/sys/devices/system/node/possible: 0-31

v5.8 + patches
------------------
available: 1 nodes (2)
node 2 cpus: 0 1 2 3 4 5 6 7
node 2 size: 32625 MB
node 2 free: 31487 MB
node distances:
node 2
2: 10

proc and sys files
------------------

/sys/devices/system/node/online:            2
/proc/sys/kernel/numa_balancing:            0
/sys/devices/system/node/has_cpu:           2
/sys/devices/system/node/has_memory:        2

/sys/devices/system/node/has_normal_memory: 2
/sys/devices/system/node/possible: 0-31

1. User space applications like Numactl, lscpu, that parse the sysfs tend to believe there is an extra online node. This tends to confuse users and applications. Other user space applications start believing that system was not able to use all the resources (i.e missing resources) or the system was not setup correctly.

2. Also existence of dummy node also leads to inconsistent information. The number of online nodes is inconsistent with the information in the device-tree and resource-dump

3. When the dummy node is present, single node non-Numa systems end up showing up as NUMA systems and numa_balancing gets enabled. This will mean we take the hit from the unnecessary numa hinting faults.

On a machine with just one node with node number not being 0, the current setup will end up showing 2 online nodes. And when there are more than one online nodes, numa_balancing gets enabled.

Without patch

$ grep numa /proc/vmstat
numa_hit 3864714
numa_miss 0
numa_foreign 0
numa_interleave 2872
numa_local 3864714
numa_other 0
numa_pte_updates 13739278           <----------
numa_huge_pte_updates 0               <----------
numa_hint_faults 13717222         <----------
numa_hint_faults_local 13717222         <----------
numa_pages_migrated 0

With patch

$ grep numa /proc/vmstat
numa_hit 6633324
numa_miss 0
numa_foreign 0
numa_interleave 2864
numa_local 6633324
numa_other 0
numa_pte_updates 0                 <----------
numa_huge_pte_updates 0                 <----------
numa_hint_faults 0                 <----------
numa_hint_faults_local 0                 <----------
numa_pages_migrated 0

Here are 2 sample numa programs.

numa01.sh is a set of 2 process each running threads as many as number of cpus;
each thread doing 50 loops on 3GB process shared memory operations.

numa02.sh is a single process with threads as many as number of cpus; each thread doing 800 loops on 32MB thread local memory operations.

Without patch
-------------

Testcase         Time:  Min      Max      Avg      StdDev
./numa01.sh      Real:  164.67   164.89   164.76   0.07
./numa01.sh      Sys:   2.88     3.38     3.05     0.17
./numa01.sh      User:  1297.85  1301.82  1300.86  1.51
./numa02.sh      Real:  27.44    27.46    27.45    0.01
./numa02.sh      Sys:   0.15     0.25     0.21     0.03
./numa02.sh      User:  216.65   216.93   216.80   0.09

With patch
-----------

Testcase         Time:  Min      Max      Avg      StdDev  %Change
./numa01.sh      Real:  164.20   164.38   164.28   0.08    0.292184%
./numa01.sh      Sys:   0.72     0.90     0.82     0.06    271.951%
./numa01.sh      User:  1300.39  1301.97  1300.94  0.56    -0.0061494%
./numa02.sh      Real:  27.41    27.51    27.45    0.03    0%
./numa02.sh      Sys:   0.09     0.16     0.13     0.03    61.5385%
./numa02.sh      User:  216.38   216.91   216.64   0.21    0.0738552%

numa01.sh

param                   no_patch    with_patch  %Change
-----                   ----------  ----------  -------
numa_hint_faults        2946055     0           -100%
numa_hint_faults_local  2946055     0           -100%
numa_hit                700617      681234      -2.76656%
numa_local              700617      681234      -2.76656%
numa_pte_updates        2947175     0           -100%
pgfault                 4125926     1120053     -72.8533%
pgmajfault              269         181         -32.7138%

numa02.sh

param                   no_patch    with_patch  %Change
-----                   ----------  ----------  -------
numa_hint_faults        137623      0           -100%
numa_hint_faults_local  137623      0           -100%
numa_hit                51332       54645       6.45406%
numa_local              51332       54645       6.45406%
numa_pte_updates        138903      0           -100%
pgfault                 247058      116743      -52.7467%
pgmajfault              154         157         1.94805%

Observations:
The real time and user time actually doesn't change much. However the system time changes to some extent. The reason being the number of numa hinting faults. With the patch we are not seeing the numa hinting faults.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Gautham R Shenoy <[email protected]>
Cc Satheesh Rajendran <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Aneesh Kumar K V <[email protected]>

Srikar Dronamraju (3):
powerpc/numa: Set numa_node for all possible cpus powerpc/numa: Prefer node id queried from vphn powerpc/numa: Offline memoryless cpuless node 0

 arch/powerpc/mm/numa.c | 45 ++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)
Signature · 1 line
2.18.1
#1 lore raw

PATCH v6 1/3 powerpc/numa: Set numa_node for all possible cpus

A Powerpc system with multiple possible nodes and with CONFIG_NUMA enabled always used to have a node 0, even if node 0 does not any cpus or memory attached to it. As per PAPR, node affinity of a cpu is only available once its present / online. For all cpus that are possible but not present, cpu_to_node() would point to node 0.

To ensure a cpuless, memoryless dummy node is not online, powerpc need to make sure all possible but not present cpu_to_node are set to a proper node.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Gautham R Shenoy <[email protected]>
Cc Satheesh Rajendran <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Aneesh Kumar K V <[email protected]>

---
Changelog v3:->v4:
- Resolved comments from Christopher.
Link v3: http://lore.kernel.org/lkml/[email protected]/t/#u

 arch/powerpc/mm/numa.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
arch/powerpc/mm/numa.c +15 -1
index 1f61fa2148b5..72f6cca1332c 100644
@@ -507,6 +507,11 @@ static int numa_setup_cpu(unsigned long lcpu)
 	int fcpu = cpu_first_thread_sibling(lcpu);
 	int nid = NUMA_NO_NODE;
 
+	if (!cpu_present(lcpu)) {
+		set_cpu_numa_node(lcpu, first_online_node);
+		return first_online_node;
+	}
+
 	/*
 	 * If a valid cpu-to-node mapping is already available, use it
 	 * directly instead of querying the firmware, since it represents
@@ -935,8 +940,17 @@ void __init mem_topology_setup(void)
 
 	reset_numa_cpu_lookup_table();
 
-	for_each_present_cpu(cpu)
+	for_each_possible_cpu(cpu) {
+		/*
+		 * Powerpc with CONFIG_NUMA always used to have a node 0,
+		 * even if it was memoryless or cpuless. For all cpus that
+		 * are possible but not present, cpu_to_node() would point
+		 * to node 0. To remove a cpuless, memoryless dummy node,
+		 * powerpc need to make sure all possible but not present
+		 * cpu_to_node are set to a proper node.
+		 */
 		numa_setup_cpu(cpu);
+	}
 }
 
 void __init initmem_init(void)
Signature · 1 line
2.18.1
#2 lore raw

PATCH v6 2/3 powerpc/numa: Prefer node id queried from vphn

In reply to Srikar Dronamraju

Node id queried from the static device tree may not
be correct. For example: it may always show 0 on a shared processor. Hence prefer the node id queried from vphn and fallback on the device tree based node id if vphn query fails.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Gautham R Shenoy <[email protected]>
Cc Satheesh Rajendran <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Aneesh Kumar KV <[email protected]>

---
Changelog v2:->v3:
- Resolved comments from Gautham.
Link v2: https://lore.kernel.org/linuxppc-dev/[email protected]/t/#u

Changelog v1:->v2:
- Rebased to v5.7-rc3

 arch/powerpc/mm/numa.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
arch/powerpc/mm/numa.c +10 -9
index 72f6cca1332c..10c5064eeb88 100644
@@ -728,21 +728,22 @@ static int __init parse_numa_properties(void)
 	 */
 	for_each_present_cpu(i) {
 		struct device_node *cpu;
-		int nid;
-
-		cpu = of_get_cpu_node(i, NULL);
-		BUG_ON(!cpu);
-		nid = of_node_to_nid_single(cpu);
-		of_node_put(cpu);
+		int nid = vphn_get_nid(i);
 
 		/*
 		 * Don't fall back to default_nid yet -- we will plug
 		 * cpus into nodes once the memory scan has discovered
 		 * the topology.
 		 */
-		if (nid < 0)
-			continue;
-		node_set_online(nid);
+		if (nid == NUMA_NO_NODE) {
+			cpu = of_get_cpu_node(i, NULL);
+			BUG_ON(!cpu);
+			nid = of_node_to_nid_single(cpu);
+			of_node_put(cpu);
+		}
+
+		if (likely(nid > 0))
+			node_set_online(nid);
 	}
 
 	get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells);
Signature · 1 line
2.18.1
#3 lore raw

PATCH v6 3/3 powerpc/numa: Offline memoryless cpuless node 0

In reply to Srikar Dronamraju

Currently Linux kernel with CONFIG_NUMA on a system with multiple possible nodes, marks node 0 as online at boot. However in practice, there are systems which have node 0 as memoryless and cpuless.

This can cause numa_balancing to be enabled on systems with only one node with memory and CPUs. The existence of this dummy node which is cpuless and memoryless node can confuse users/scripts looking at output of lscpu / numactl.

By marking, node 0 as offline, lets stop assuming that node 0 is always online. If node 0 has CPU or memory that are online, node 0 will again be set as online.

v5.8
available: 2 nodes (0,2)
node 0 cpus:
node 0 size: 0 MB
node 0 free: 0 MB
node 2 cpus: 0 1 2 3 4 5 6 7
node 2 size: 32625 MB
node 2 free: 31490 MB
node distances:
node 0 2

   0:  10  20
   2:  20  10

proc and sys files
------------------

 /sys/devices/system/node/online:            0,2
 /proc/sys/kernel/numa_balancing:            1
 /sys/devices/system/node/has_cpu:           2
 /sys/devices/system/node/has_memory:        2

/sys/devices/system/node/has_normal_memory: 2
/sys/devices/system/node/possible: 0-31

v5.8 + patch
------------------
available: 1 nodes (2)
node 2 cpus: 0 1 2 3 4 5 6 7
node 2 size: 32625 MB
node 2 free: 31487 MB
node distances:
node 2
2: 10

proc and sys files
------------------

/sys/devices/system/node/online:            2
/proc/sys/kernel/numa_balancing:            0
/sys/devices/system/node/has_cpu:           2
/sys/devices/system/node/has_memory:        2

/sys/devices/system/node/has_normal_memory: 2
/sys/devices/system/node/possible: 0-31

Example of a node with online CPUs/memory on node 0.
(Same o/p with and without patch)
numactl -H
available: 4 nodes (0-3)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
node 0 size: 32482 MB
node 0 free: 22994 MB
node 1 cpus: 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
node 1 size: 0 MB
node 1 free: 0 MB
node 2 cpus: 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 node 2 size: 0 MB
node 2 free: 0 MB
node 3 cpus: 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 node 3 size: 0 MB node 3 free: 0 MB
node distances:
node 0 1 2 3

  0:  10  20  40  40
  1:  20  10  40  40
  2:  40  40  10  20
  3:  40  40  20  10

Note: On Powerpc, cpu_to_node of possible but not present cpus would previously return 0. Hence this commit depends on commit ("powerpc/numa: Set numa_node for all possible cpus") and commit ("powerpc/numa: Prefer node id queried from vphn"). Without the 2 commits, Powerpc system might crash.

1. User space applications like Numactl, lscpu, that parse the sysfs tend to believe there is an extra online node. This tends to confuse users and applications. Other user space applications start believing that system was not able to use all the resources (i.e missing resources) or the system was not setup correctly.

2. Also existence of dummy node also leads to inconsistent information. The number of online nodes is inconsistent with the information in the device-tree and resource-dump

3. When the dummy node is present, single node non-Numa systems end up showing up as NUMA systems and numa_balancing gets enabled. This will mean we take the hit from the unnecessary numa hinting faults.

Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Gautham R Shenoy <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Aneesh Kumar K V <[email protected]>

---
Changelog:
v5->v6:
Moved fix from arch independent code to powerpc specific
(Michal Hocko, Christopher Lamater)

 arch/powerpc/mm/numa.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/mm/numa.c +10 -0
index 10c5064eeb88..0d72a7d4360e 100644
@@ -924,6 +924,16 @@ void __init mem_topology_setup(void)
 {
 	int cpu;
 
+	/*
+	 * Linux/mm assumes node 0 to be online at boot. However this is not
+	 * true on PowerPC, where node 0 is similar to any other node, it
+	 * could be cpuless, memoryless node. So force node 0 to be offline
+	 * for now. This will prevent cpuless, memoryless node 0 showing up
+	 * unnecessarily as online. If a node has cpus or memory that need
+	 * to be online, then node will anyway be marked online.
+	 */
+	node_set_offline(0);
+
 	if (parse_numa_properties())
 		setup_nonnuma();
 
Signature · 1 line
2.18.1
#4 lore raw
In reply to Srikar Dronamraju
Quoted 11 lines · Srikar Dronamraju

Changelog v5:->v6:
- Now the fix is Powerpc specific.
(David Hildenbrand, Michal Hocko, Christopher Lamater)
- rebased to v5.8
link v5: https://lore.kernel.org/linuxppc-dev/[email protected]/t/#u

Changelog v4:->v5:
- rebased to v5.8
link v4: http://lore.kernel.org/lkml/[email protected]/t/#u

[...]

Applied to powerpc/next.

[1/3] powerpc/numa: Set numa_node for all possible cpus

      https://git.kernel.org/powerpc/c/a874f1005ef5dfe53dfd8cda59a6600e89986ecd
[2/3] powerpc/numa: Prefer node id queried from vphn
      https://git.kernel.org/powerpc/c/6398eaa268168b528dd1d3d0e70e61e9c13bea23
[3/3] powerpc/numa: Offline memoryless cpuless node 0
      https://git.kernel.org/powerpc/c/e75130f20b1f48e04ccc806aea01f0a361f9cb6b

cheers