Skip to contentSkip to conversation

powerpc/numa: reset node_possible_map to only node_online_map

RFC PATCH Superseded Nishanth Aravamudan 5 participants 18 messages Mar 5, 2015 – Mar 10, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 powerpc/numa: reset node_possible_map to only node_online_map

Raghu noticed an issue with excessive memory allocation on power with a simple cgroup test, specifically, in mem_cgroup_css_alloc -> for_each_node -> alloc_mem_cgroup_per_zone_info(), which ends up blowing up the kmalloc-2048 slab (to the order of 200MB for 400 cgroup directories).

The underlying issue is that NODES_SHIFT on power is 8 (256 NUMA nodes possible), which defines node_possible_map, which in turn defines the iteration of for_each_node.

In practice, we never see a system with 256 NUMA nodes, and in fact, we do not support node hotplug on power in the first place, so the nodes that are online when we come up are the nodes that will be present for the lifetime of this kernel. So let's, at least, drop the NUMA possible map down to the online map at runtime. This is similar to what x86 does in its initialization routines.

One could alternatively nodemask_and(node_possible_map, node_online_map), but I think the cost of anding the two will always be higher than zero and set a few bits in practice.

---
While looking at this, I noticed that nr_node_ids is actually a misnomer, it seems. It's not the number, but the maximum_node_id, as with sparse NUMA nodes, you might only have two NUMA nodes possible, but to make certain loops work, nr_node_ids will be, e.g., 17. Should it be changed?

arch/powerpc/mm/numa.c +8 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);
#1 lore raw
Quoted 12 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +4 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 10 lines
arch/powerpc/mm/numa.c +4 -0
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

#2 lore raw
Quoted 20 lines · David Rientjes
Quoted 18 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
Quoted 8 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 4 lines
arch/powerpc/mm/numa.c +1 -0
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

Yeah. Though at this point in boot I don't think it matters that the two maps are out-of-sync temporarily.

But it would simpler to just set the possible map to be the online map. That would also maintain the invariant that the possible map is always a superset of the online map.

Or did I miss a detail there (sleep deprived parent mode).

cheers

#3 lore raw
Quoted 27 lines · Michael Ellerman
Quoted 18 lines
Quoted 18 lines
arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
Quoted 8 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 4 lines
arch/powerpc/mm/numa.c +1 -0
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

Quoted 9 lines

Yeah. Though at this point in boot I don't think it matters that the two maps are out-of-sync temporarily.

But it would simpler to just set the possible map to be the online map. That would also maintain the invariant that the possible map is always a superset of the online map.

Or did I miss a detail there (sleep deprived parent mode).

I think reset_numa_cpu_lookup_table() which iterates over the possible map, and thus only a subset of nodes now, may be concerning.

I'm not sure why this is being proposed as a powerpc patch and now a patch for mem_cgroup_css_alloc(). In other words, why do we have to allocate for all possible nodes? We should only be allocating for online nodes in N_MEMORY with mem hotplug disabled initially and then have a mem hotplug callback implemented to alloc_mem_cgroup_per_zone_info() for nodes that transition from memoryless -> memory. The extra bonus is that alloc_mem_cgroup_per_zone_info() need never allocate remote memory and the TODO in that function can be removed.

#4 lore raw

Hello,

Quoted 8 lines · David Rientjes

I'm not sure why this is being proposed as a powerpc patch and now a patch for mem_cgroup_css_alloc(). In other words, why do we have to allocate for all possible nodes? We should only be allocating for online nodes in N_MEMORY with mem hotplug disabled initially and then have a mem hotplug callback implemented to alloc_mem_cgroup_per_zone_info() for nodes that transition from memoryless -> memory. The extra bonus is that alloc_mem_cgroup_per_zone_info() need never allocate remote memory and the TODO in that function can be removed.

For cpus, the general direction is allocating for all possible cpus. For iterations, we alternate between using all possibles and onlines depending on the use case; however, the general idea is that the possibles and onlines aren't gonna be very different. NR_CPUS and MAX_NUMNODES gotta accomodate the worst possible case the kernel may run on but the possible masks should be set to the actually possible subset during boot so that the kernel don't end up allocating for and iterating over things which can't ever exist.

It can be argued that we should always stick to the online masks for allocation and iteration; however, that usually requires more complexity and the only cases where this mattered have been when the boot code got it wrong and failed to set the possible masks correctly, which also seems to be the case here. I don't see any reason to deviate here.

Thanks.

Signature · 1 line
tejun
#5 lore raw
Quoted 6 lines · Tejun Heo

It can be argued that we should always stick to the online masks for allocation and iteration; however, that usually requires more complexity and the only cases where this mattered have been when the boot code got it wrong and failed to set the possible masks correctly, which also seems to be the case here. I don't see any reason to deviate here.

Hmm... but yeah, as you wrote, keeping the allocation local could be a reason but let's please not do this just to reduce memory consumption. If memory locality of the field affects performance noticeably, sure.

Thanks.

Signature · 1 line
tejun
#6 lore raw
In reply to Tejun Heo
Quoted 12 lines · Tejun Heo

Hello,

Quoted 8 lines · David Rientjes

I'm not sure why this is being proposed as a powerpc patch and now a patch for mem_cgroup_css_alloc(). In other words, why do we have to allocate for all possible nodes? We should only be allocating for online nodes in N_MEMORY with mem hotplug disabled initially and then have a mem hotplug callback implemented to alloc_mem_cgroup_per_zone_info() for nodes that transition from memoryless -> memory. The extra bonus is that alloc_mem_cgroup_per_zone_info() need never allocate remote memory and the TODO in that function can be removed.

Quoted 8 lines

For cpus, the general direction is allocating for all possible cpus. For iterations, we alternate between using all possibles and onlines depending on the use case; however, the general idea is that the possibles and onlines aren't gonna be very different. NR_CPUS and MAX_NUMNODES gotta accomodate the worst possible case the kernel may run on but the possible masks should be set to the actually possible subset during boot so that the kernel don't end up allocating for and iterating over things which can't ever exist.

Makes sense to me.

Quoted 6 lines

It can be argued that we should always stick to the online masks for allocation and iteration; however, that usually requires more complexity and the only cases where this mattered have been when the boot code got it wrong and failed to set the possible masks correctly, which also seems to be the case here. I don't see any reason to deviate here.

So, do you agree with the general direction of my change? :)

Thanks,
Nish

#7 lore raw
Quoted 1 line · Nishanth Aravamudan

So, do you agree with the general direction of my change? :)

Yeah, I mean it's an obvious bug fix. I don't know when or how it should be set on powerpc but if the machine can't do NUMA node hotplug, its node online and possible masks must be equal.

Thanks.

Signature · 1 line
tejun
#8 lore raw
In reply to David Rientjes
Quoted 36 lines · David Rientjes
Quoted 34 lines · Michael Ellerman
Quoted 18 lines
Quoted 18 lines
arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
Quoted 8 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 4 lines
arch/powerpc/mm/numa.c +1 -0
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

Yeah. Though at this point in boot I don't think it matters that the two maps are out-of-sync temporarily.

But it would simpler to just set the possible map to be the online map. That would also maintain the invariant that the possible map is always a superset of the online map.

Quoted 5 lines
Quoted 2 lines

Or did I miss a detail there (sleep deprived parent mode).

I think reset_numa_cpu_lookup_table() which iterates over the possible map, and thus only a subset of nodes now, may be concerning.

I think you are confusing the CPU online map and the NUMA node online map. reset_numa_cpu_lookup_table is a cpu->node mapping, only called at boot-time, and iterates over the CPU online map, which is unaltered by my patch.

Quoted 2 lines

I'm not sure why this is being proposed as a powerpc patch and now a patch for mem_cgroup_css_alloc().

I think mem_cgroup_css_alloc() is just an example of a larger issue. I should have made that clearer in my changelog. Even if we change mem_cgroup_css_alloc(), I think we want to fix the node_possible_map on powerpc to be accurate at run-time, just like x86 does.

Quoted 7 lines

In other words, why do we have to allocate for all possible nodes? We should only be allocating for online nodes in N_MEMORY with mem hotplug disabled initially and then have a mem hotplug callback implemented to alloc_mem_cgroup_per_zone_info() for nodes that transition from memoryless -> memory. The extra bonus is that alloc_mem_cgroup_per_zone_info() need never allocate remote memory and the TODO in that function can be removed.

This is a good idea, and seems like it can be a follow-on parallel patch to the one I provided (which does need an updated changelog now).

Thanks,
Nish

#9 lore raw
In reply to Michael Ellerman
Quoted 30 lines · Michael Ellerman
Quoted 20 lines · David Rientjes
Quoted 18 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
Quoted 8 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 4 lines
arch/powerpc/mm/numa.c +1 -0
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

Quoted 6 lines

Yeah. Though at this point in boot I don't think it matters that the two maps are out-of-sync temporarily.

But it would simpler to just set the possible map to be the online map. That would also maintain the invariant that the possible map is always a superset of the online map.

Yes, we could do that (see my reply to David just now). I didn't consider just setting the map directly, that would be clearer. I didn't want to post my nodes_and() version, because the cost of nodes_and seemed higher than nodes_clear & node_set appropriately.

-Nish

#10 lore raw
In reply to David Rientjes

Hi David,

Quoted 20 lines · David Rientjes
Quoted 18 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..24de29b3651b 100644
@@ -958,9 +958,17 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * zero out the possible nodes after we parse the device-tree,
+	 * so that we lower the maximum NUMA node ID to what is actually
+	 * present.
+	 */
+	nodes_clear(node_possible_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
Quoted 8 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 974

Quoted 4 lines
arch/powerpc/mm/numa.c +1 -0
+		node_set(nid, node_possible_map);
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		setup_node_data(nid, start_pfn, end_pfn);
 		sparse_memory_present_with_active_regions(nid);

This seems a bit strange, node_possible_map is supposed to be a superset of node_online_map and this loop is iterating over node_online_map to set nodes in node_possible_map.

So if we compare to x86:

arch/x86/mm/numa.c::numa_init():

        nodes_clear(numa_nodes_parsed);
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
	...
	numa_register_memblks(...);

arch/x86/mm/numa.c::numa_register_memblks():

	node_possible_map = numa_nodes_parsed;

Basically, it looks like x86 NUMA init clears out possible map and online map, probably for a similar reason to what I gave in the changelog that by default, the possible map seems to be based off MAX_NUMNODES, rather than nr_node_ids or anything dynamic.

My patch was an attempt to emulate the same thing on powerpc. You are right that there is a window in which the node_possible_map and node_online_map are out of sync with my patch. It seems like it shouldn't matter given how early in boot we are, but perhaps the following would have been clearer:

arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..1a118b08fad2 100644
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
        memblock_dump_all();
 
+       /*
+        * Reduce the possible NUMA nodes to the online NUMA nodes,
+        * since we do not support node hotplug. This ensures that  we
+        * lower the maximum NUMA node ID to what is actually present.
+        */
+       nodes_and(node_possible_map, node_possible_map, node_online_map);
+
        for_each_online_node(nid) {
                unsigned long start_pfn, end_pfn;
 
#11 lore raw
Quoted 30 lines · Nishanth Aravamudan

So if we compare to x86:

arch/x86/mm/numa.c::numa_init():

        nodes_clear(numa_nodes_parsed);
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
	...
	numa_register_memblks(...);

arch/x86/mm/numa.c::numa_register_memblks():

	node_possible_map = numa_nodes_parsed;

Basically, it looks like x86 NUMA init clears out possible map and online map, probably for a similar reason to what I gave in the changelog that by default, the possible map seems to be based off MAX_NUMNODES, rather than nr_node_ids or anything dynamic.

My patch was an attempt to emulate the same thing on powerpc. You are right that there is a window in which the node_possible_map and node_online_map are out of sync with my patch. It seems like it shouldn't matter given how early in boot we are, but perhaps the following would have been clearer:

arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..1a118b08fad2 100644

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 966

Quoted 9 lines
arch/powerpc/mm/numa.c +6 -0
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
        memblock_dump_all();
 
+       /*
+        * Reduce the possible NUMA nodes to the online NUMA nodes,
+        * since we do not support node hotplug. This ensures that  we
+        * lower the maximum NUMA node ID to what is actually present.
+        */
+       nodes_and(node_possible_map, node_possible_map, node_online_map);

If you don't support node hotplug, then a node should always be possible if it's online unless there are other tricks powerpc plays with node_possible_map. Shouldn't this just be
node_possible_map = node_online_map?

Quoted 6 lines
arch/powerpc/mm/numa.c +1 -0
+
        for_each_online_node(nid) {
                unsigned long start_pfn, end_pfn;
 
#12 lore raw

PATCH v2 1/1 powerpc/numa: set node_possible_map to only node_online_map during boot

Quoted 35 lines · David Rientjes
Quoted 33 lines · Nishanth Aravamudan

So if we compare to x86:

arch/x86/mm/numa.c::numa_init():

        nodes_clear(numa_nodes_parsed);
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
	...
	numa_register_memblks(...);

arch/x86/mm/numa.c::numa_register_memblks():

	node_possible_map = numa_nodes_parsed;

Basically, it looks like x86 NUMA init clears out possible map and online map, probably for a similar reason to what I gave in the changelog that by default, the possible map seems to be based off MAX_NUMNODES, rather than nr_node_ids or anything dynamic.

My patch was an attempt to emulate the same thing on powerpc. You are right that there is a window in which the node_possible_map and node_online_map are out of sync with my patch. It seems like it shouldn't matter given how early in boot we are, but perhaps the following would have been clearer:

arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..1a118b08fad2 100644
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
        memblock_dump_all();
 
Quoted 11 lines

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 966

Quoted 6 lines
arch/powerpc/mm/numa.c +6 -0
+       /*
+        * Reduce the possible NUMA nodes to the online NUMA nodes,
+        * since we do not support node hotplug. This ensures that  we
+        * lower the maximum NUMA node ID to what is actually present.
+        */
+       nodes_and(node_possible_map, node_possible_map, node_online_map);

If you don't support node hotplug, then a node should always be possible if it's online unless there are other tricks powerpc plays with node_possible_map. Shouldn't this just be
node_possible_map = node_online_map?

Yeah, but I was too dumb to think of that before sending :)

Updated version follows...

-Nish

Raghu noticed an issue with excessive memory allocation on power with a simple cgroup test, specifically, in mem_cgroup_css_alloc -> for_each_node -> alloc_mem_cgroup_per_zone_info(), which ends up blowing up the kmalloc-2048 slab (to the order of 200MB for 400 cgroup directories).

The underlying issue is that NODES_SHIFT on power is 8 (256 NUMA nodes possible), which defines node_possible_map, which in turn defines the value of nr_node_ids in setup_nr_node_ids and the iteration of for_each_node.

In practice, we never see a system with 256 NUMA nodes, and in fact, we do not support node hotplug on power in the first place, so the nodes that are online when we come up are the nodes that will be present for the lifetime of this kernel. So let's, at least, drop the NUMA possible map down to the online map at runtime. This is similar to what x86 does in its initialization routines.

mem_cgroup_css_alloc should also be fixed to only iterate over memory-populated nodes and handle hotplug, but that is a separate change.

To: Michael Ellerman <[email protected]>
Cc: [email protected]
Cc: Tejun Heo <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Anton Blanchard <[email protected]>
Cc: Raghavendra K T <[email protected]>

---
v1 -> v2:
Rather than clear node_possible_map and set it nid-by-nid, just directly assign node_online_map to it, as suggested by Michael Ellerman and Tejun Heo.

arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..0c1716cd271f 100644
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * Reduce the possible NUMA nodes to the online NUMA nodes,
+	 * since we do not support node hotplug. This ensures that  we
+	 * lower the maximum NUMA node ID to what is actually present.
+	 */
+	node_possible_map = node_online_map;
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
#13 lore raw

Re: [PATCH v2] powerpc/numa: set node_possible_map to only node_online_map during boot

Quoted 48 lines · Nishanth Aravamudan
Quoted 35 lines · David Rientjes
Quoted 33 lines · Nishanth Aravamudan

So if we compare to x86:

arch/x86/mm/numa.c::numa_init():

         nodes_clear(numa_nodes_parsed);
         nodes_clear(node_possible_map);
         nodes_clear(node_online_map);
	...
	numa_register_memblks(...);

arch/x86/mm/numa.c::numa_register_memblks():

	node_possible_map = numa_nodes_parsed;

Basically, it looks like x86 NUMA init clears out possible map and online map, probably for a similar reason to what I gave in the changelog that by default, the possible map seems to be based off MAX_NUMNODES, rather than nr_node_ids or anything dynamic.

My patch was an attempt to emulate the same thing on powerpc. You are right that there is a window in which the node_possible_map and node_online_map are out of sync with my patch. It seems like it shouldn't matter given how early in boot we are, but perhaps the following would have been clearer:

arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..1a118b08fad2 100644
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
         memblock_dump_all();
 
Quoted 11 lines

arch/powerpc/mm/numa.c void __init initmem_init(void)

Quoted 6 lines
arch/powerpc/mm/numa.c +6 -0
+       /*
+        * Reduce the possible NUMA nodes to the online NUMA nodes,
+        * since we do not support node hotplug. This ensures that  we
+        * lower the maximum NUMA node ID to what is actually present.
+        */
+       nodes_and(node_possible_map, node_possible_map, node_online_map);

If you don't support node hotplug, then a node should always be possible if it's online unless there are other tricks powerpc plays with node_possible_map. Shouldn't this just be
node_possible_map = node_online_map?

Quoted 6 lines

Yeah, but I was too dumb to think of that before sending :)

Updated version follows...

-Nish

---8<---

Quoted 6 lines

Raghu noticed an issue with excessive memory allocation on power with a simple cgroup test, specifically, in mem_cgroup_css_alloc -> for_each_node -> alloc_mem_cgroup_per_zone_info(), which ends up blowing up the kmalloc-2048 slab (to the order of 200MB for 400 cgroup directories).

should we also add after this patch it has reduced to around 2MB?

Quoted 13 lines

The underlying issue is that NODES_SHIFT on power is 8 (256 NUMA nodes possible), which defines node_possible_map, which in turn defines the value of nr_node_ids in setup_nr_node_ids and the iteration of for_each_node.

In practice, we never see a system with 256 NUMA nodes, and in fact, we do not support node hotplug on power in the first place, so the nodes that are online when we come up are the nodes that will be present for the lifetime of this kernel. So let's, at least, drop the NUMA possible map down to the online map at runtime. This is similar to what x86 does in its initialization routines.

Quoted 4 lines

mem_cgroup_css_alloc should also be fixed to only iterate over memory-populated nodes and handle hotplug, but that is a separate change.

Maybe we could fomally add

Quoted 21 lines

To: Michael Ellerman <[email protected]>
Cc: [email protected]
Cc: Tejun Heo <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Anton Blanchard <[email protected]>
Cc: Raghavendra K T <[email protected]>

---
v1 -> v2:
Rather than clear node_possible_map and set it nid-by-nid, just directly assign node_online_map to it, as suggested by Michael Ellerman and Tejun Heo.

arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..0c1716cd271f 100644

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 965

Quoted 8 lines
arch/powerpc/mm/numa.c +5 -0
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
  	memblock_dump_all();
 
+	/*
+	 * Reduce the possible NUMA nodes to the online NUMA nodes,
+	 * since we do not support node hotplug. This ensures that  we
+	 * lower the maximum NUMA node ID to what is actually present.
+	 */

Hope we remember this change when we add hotplug :)

Quoted 5 lines
arch/powerpc/mm/numa.c +2 -0
+	node_possible_map = node_online_map;
+
  	for_each_online_node(nid) {
  		unsigned long start_pfn, end_pfn;
 
#14 lore raw

Re: [PATCH v2] powerpc/numa: set node_possible_map to only node_online_map during boot

In reply to Nishanth Aravamudan
Quoted 5 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..0c1716cd271f 100644

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 966

Quoted 9 lines
arch/powerpc/mm/numa.c +6 -0
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * Reduce the possible NUMA nodes to the online NUMA nodes,
+	 * since we do not support node hotplug. This ensures that  we
+	 * lower the maximum NUMA node ID to what is actually present.
+	 */
+	node_possible_map = node_online_map;

That looks nice, but is it generating what we want?

ie. is the content of node_online_map being *copied* into node_possible_map.

Or are we changing node_possible_map to point at node_online_map?

cheers

#15 lore raw

PATCH v3 1/1 powerpc/numa: set node_possible_map to only node_online_map during boot

Quoted 18 lines · Michael Ellerman
Quoted 5 lines · Nishanth Aravamudan
arch/powerpc/mm/numa.c +0 -0
index 0257a7d659ef..0c1716cd271f 100644

arch/powerpc/mm/numa.c void __init initmem_init(void) · line 966

Quoted 9 lines
arch/powerpc/mm/numa.c +6 -0
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * Reduce the possible NUMA nodes to the online NUMA nodes,
+	 * since we do not support node hotplug. This ensures that  we
+	 * lower the maximum NUMA node ID to what is actually present.
+	 */
+	node_possible_map = node_online_map;

That looks nice, but is it generating what we want?

Quoted 3 lines

ie. is the content of node_online_map being *copied* into node_possible_map.

Or are we changing node_possible_map to point at node_online_map?

I think it ends up being the latter, which is probably fine in practice (I think node_online_map is static on power after boot), but perhaps it would be better to do:

nodes_and(node_possible_map, node_possible_map, node_online_map);

?

e.g.:

powerpc/numa: reset node_possible_map to only node_online_map

Raghu noticed an issue with excessive memory allocation on power with a simple cgroup test, specifically, in mem_cgroup_css_alloc -> for_each_node -> alloc_mem_cgroup_per_zone_info(), which ends up blowing up the kmalloc-2048 slab (to the order of 200MB for 400 cgroup directories).

The underlying issue is that NODES_SHIFT on power is 8 (256 NUMA nodes possible), which defines node_possible_map, which in turn defines the value of nr_node_ids in setup_nr_node_ids and the iteration of for_each_node.

In practice, we never see a system with 256 NUMA nodes, and in fact, we do not support node hotplug on power in the first place, so the nodes that are online when we come up are the nodes that will be present for the lifetime of this kernel. So let's, at least, drop the NUMA possible map down to the online map at runtime. This is similar to what x86 does in its initialization routines.

mem_cgroup_css_alloc should also be fixed to only iterate over memory-populated nodes and handle hotplug, but that is a separate change.

To: Michael Ellerman <[email protected]>
Cc: [email protected]
Cc: Tejun Heo <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Anton Blanchard <[email protected]>
Cc: Raghavendra K T <[email protected]>

---
v1 -> v2:
Rather than clear node_possible_map and set it nid-by-nid, just directly assign node_online_map to it, as suggested by Michael Ellerman and Tejun Heo.

v2 -> v3:
Rather than direct assignment (which is just repointing the pointer), modify node_possible_map in-place.

arch/powerpc/mm/numa.c +7 -0
index 0257a7d659ef..1a118b08fad2 100644
@@ -958,6 +958,13 @@ void __init initmem_init(void)
 
 	memblock_dump_all();
 
+	/*
+	 * Reduce the possible NUMA nodes to the online NUMA nodes,
+	 * since we do not support node hotplug. This ensures that  we
+	 * lower the maximum NUMA node ID to what is actually present.
+	 */
+	nodes_and(node_possible_map, node_possible_map, node_online_map);
+
 	for_each_online_node(nid) {
 		unsigned long start_pfn, end_pfn;
 
#16 lore raw
In reply to Nishanth Aravamudan
Quoted 5 lines · Nishanth Aravamudan

While looking at this, I noticed that nr_node_ids is actually a misnomer, it seems. It's not the number, but the maximum_node_id, as with sparse NUMA nodes, you might only have two NUMA nodes possible, but to make certain loops work, nr_node_ids will be, e.g., 17. Should it be changed?

It's the same for nr_cpu_ids. It's counting the number of valid IDs during that boot instance. In the above case, whether the nodes are sparse or not, there exist 17 node ids - 0 to 16. Maybe numa_max_id had been a better name (but would that equal the highest number or +1?) but nr_node_ids != nr_nodes so I don't think it's a misnomer either. Doesn't really matter at this point. Maybe add comments on top of both?

Thanks.

Signature · 1 line
tejun
#17 lore raw
Quoted 7 lines · Tejun Heo
Quoted 5 lines · Nishanth Aravamudan

While looking at this, I noticed that nr_node_ids is actually a misnomer, it seems. It's not the number, but the maximum_node_id, as with sparse NUMA nodes, you might only have two NUMA nodes possible, but to make certain loops work, nr_node_ids will be, e.g., 17. Should it be changed?

Quoted 7 lines

It's the same for nr_cpu_ids. It's counting the number of valid IDs during that boot instance. In the above case, whether the nodes are sparse or not, there exist 17 node ids - 0 to 16. Maybe numa_max_id had been a better name (but would that equal the highest number or +1?) but nr_node_ids != nr_nodes so I don't think it's a misnomer either. Doesn't really matter at this point. Maybe add comments on top of both?

Yes, I will consider that. To me, I guess it's more a matter of:

a) How does nr_node_ids relate to the number of possible NUMA node IDs at runtime?

They are identical.

b) How does nr_node_ids relate to the number of NUMA node IDs in use?

There is no relation.

c) How does nr_node_ids relate to the maximum NUMA node ID in use?

It is one larger than that value.

However, for a), at least, we don't care about that on power, really. We don't have node hotplug, so the "possible" is the "online" in practice, for a given system.

Iteration seems to generally not be a problem (since we have sparse iterators anyways) and we shouldn't be allocating for non-present nodes.

But we run into excessive allocations (I'm looking into a few others Dipankar has found now) with array allocations based of nr_node_ids or MAX_NUMNODES when the NUMA topology is sparse..

-Nish