Skip to contentSkip to conversation

handle memoryless nodes more appropriately

PATCH Superseded Qi Zheng 4 participants 14 messages Oct 19, 2023 – Oct 23, 2023

Subsystems (3)

v3 of 4 Superseded 1 of 2 applied Latest is v4 →

lore
Share & tools
lore

Qi Zheng

author
#0 lore raw

v3 cover handle memoryless nodes more appropriately

Hi all,

Currently, in the process of initialization or offline memory, memoryless nodes will still be built into the fallback list of itself or other nodes.

This is not what we expected, so this patch series removes memoryless nodes from the fallback list entirely.

This series is based on the next-20231018.

Comments and suggestions are welcome.

Thanks,
Qi

Changlog in v2 -> v3:
- add a comment in [PATCH v2 2/2] (suggested by David Hildenbrand)
- collect Acked-bys

Changlog in v1 -> v2:
- modify the commit message in [PATCH 1/2], mention that it can also fix the specific crash. (suggested by Ingo Molnar)
- rebase onto the next-20231018

Qi Zheng (2):
mm: page_alloc: skip memoryless nodes entirely
mm: memory_hotplug: drop memoryless node from fallback lists

 mm/memory_hotplug.c | 6 +++++-
 mm/page_alloc.c     | 7 +++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.2
author
#1 lore raw

PATCH v3 1/2 mm: page_alloc: skip memoryless nodes entirely

In find_next_best_node(), We skipped the memoryless nodes when building the zonelists of other normal nodes (N_NORMAL), but did not skip the memoryless node itself when building the zonelist. This will cause it to be traversed at runtime.

For example, say we have node0 and node1, node0 is memoryless node, then the fallback order of node0 and node1 as follows:

[    0.153005] Fallback order for Node 0: 0 1
[    0.153564] Fallback order for Node 1: 1

After this patch, we skip memoryless node0 entirely, then the fallback order of node0 and node1 as follows:

[    0.155236] Fallback order for Node 0: 1
[    0.155806] Fallback order for Node 1: 1

So it becomes completely invisible, which will reduce runtime overhead.

And in this way, we will not try to allocate pages from memoryless node0, then the panic mentioned in [1] will also be fixed. Even though this problem has been solved by dropping the NODE_MIN_SIZE constrain in x86 [2], it would be better to fix it in core MM as well.

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

---
 mm/page_alloc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/page_alloc.c +5 -2
index ee392a324802..e978272699d3 100644
@@ -5052,8 +5052,11 @@ int find_next_best_node(int node, nodemask_t *used_node_mask)
 	int min_val = INT_MAX;
 	int best_node = NUMA_NO_NODE;
 
-	/* Use the local node if we haven't already */
-	if (!node_isset(node, *used_node_mask)) {
+	/*
+	 * Use the local node if we haven't already. But for memoryless local
+	 * node, we should skip it and fallback to other nodes.
+	 */
+	if (!node_isset(node, *used_node_mask) && node_state(node, N_MEMORY)) {
 		node_set(node, *used_node_mask);
 		return node;
 	}
Signature · 1 line
2.30.2
Acked-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] mm: page_alloc: skip memoryless nodes entirely

Quoted 1 line · Qi Zheng

In find_next_best_node(), We skipped the memoryless nodes

s/We
/we

s/the memoryless nodes
/memoryless nodes

Quoted 4 lines

when building the zonelists of other normal nodes (N_NORMAL), but did not skip the memoryless node itself when building the zonelist. This will cause it to be traversed at runtime.

Quoted 8 lines

For example, say we have node0 and node1, node0 is memoryless node, then the fallback order of node0 and node1 as follows:

[    0.153005] Fallback order for Node 0: 0 1
[    0.153564] Fallback order for Node 1: 1

After this patch, we skip memoryless node0 entirely, then the fallback order of node0 and node1 as follows:

s/fallback
/fall back

Quoted 11 lines
[    0.155236] Fallback order for Node 0: 1
[    0.155806] Fallback order for Node 1: 1

So it becomes completely invisible, which will reduce runtime overhead.

And in this way, we will not try to allocate pages from memoryless node0, then the panic mentioned in [1] will also be fixed. Even though this problem has been solved by dropping the NODE_MIN_SIZE constrain in x86 [2], it would be better to fix it in core MM as well.

s/in core MM
/in the core MM

mm/page_alloc.c int find_next_best_node(int node, nodemask_t *used_node_mask) · line 5057

Quoted 9 lines

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

mm/page_alloc.c +3 -0
+	/*
+	 * Use the local node if we haven't already. But for memoryless local
+	 * node, we should skip it and fallback to other nodes.

s/fallback
/fall back

s/already. But
/already, but

Thanks,

Ingo

author
#3 lore raw

Re: [PATCH v3 1/2] mm: page_alloc: skip memoryless nodes entirely

Quoted 55 lines · Ingo Molnar
Quoted 1 line · Qi Zheng

In find_next_best_node(), We skipped the memoryless nodes

s/We
/we

s/the memoryless nodes
/memoryless nodes

Quoted 4 lines

when building the zonelists of other normal nodes (N_NORMAL), but did not skip the memoryless node itself when building the zonelist. This will cause it to be traversed at runtime.

Quoted 8 lines

For example, say we have node0 and node1, node0 is memoryless node, then the fallback order of node0 and node1 as follows:

[    0.153005] Fallback order for Node 0: 0 1
[    0.153564] Fallback order for Node 1: 1

After this patch, we skip memoryless node0 entirely, then the fallback order of node0 and node1 as follows:

s/fallback
/fall back

Quoted 11 lines
[    0.155236] Fallback order for Node 0: 1
[    0.155806] Fallback order for Node 1: 1

So it becomes completely invisible, which will reduce runtime overhead.

And in this way, we will not try to allocate pages from memoryless node0, then the panic mentioned in [1] will also be fixed. Even though this problem has been solved by dropping the NODE_MIN_SIZE constrain in x86 [2], it would be better to fix it in core MM as well.

s/in core MM
/in the core MM

mm/page_alloc.c int find_next_best_node(int node, nodemask_t *used_node_mask) · line 5057

Quoted 9 lines

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

mm/page_alloc.c +3 -0
+	/*
+	 * Use the local node if we haven't already. But for memoryless local
+	 * node, we should skip it and fallback to other nodes.

s/fallback
/fall back

Quoted 2 lines

s/already. But
/already, but

Will fix the typos above.

Quoted 2 lines

Thanks.

Quoted 4 lines

Thanks,

Ingo

author
#4 lore raw

PATCH v3 2/2 mm: memory_hotplug: drop memoryless node from fallback lists

In reply to Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes. This will incur some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

---
 mm/memory_hotplug.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memory_hotplug.c +5 -1
index d4a364fdaf8f..f019f7d6272c 100644
@@ -2036,12 +2036,16 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,
 	/* reinitialise watermarks and update pcp limits */
 	init_per_zone_wmark_min();
 
+	/*
+	 * Make sure to mark the node as memory-less before rebuilding the zone
+	 * list. Otherwise this node would still appear in the fallback lists.
+	 */
+	node_states_clear_node(node, &arg);
 	if (!populated_zone(zone)) {
 		zone_pcp_reset(zone);
 		build_all_zonelists(NULL);
 	}
 
-	node_states_clear_node(node, &arg);
 	if (arg.status_change_nid >= 0) {
 		kcompactd_stop(node);
 		kswapd_stop(node);
Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

For fallback list, do you mean pgdat->node_zonelists[]? If so, in

build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node

populated_zone() will be checked before adding zone into zonelist.

So, IIUC, we will not try to allocate from the memory less node.

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]

--
Best Regards,
Huang, Ying

author
#6 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Hi Ying,

Quoted 16 lines · Ying
Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

For fallback list, do you mean pgdat->node_zonelists[]? If so, in

build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node

Quoted 3 lines

populated_zone() will be checked before adding zone into zonelist.

So, IIUC, we will not try to allocate from the memory less node.

Normally yes, but if it is the weird topology mentioned in [1], it's possible to allocate memory from it, it is a memoryless node, but it also has memory.

In addition to the above case, I think it's reasonable to remove memory less node from node_order[] in advance. In this way it will not to be traversed in build_zonelists_in_node_order().

[1]. https://lore.kernel.org/all/[email protected]/

Thanks,
Qi

Quoted 20 lines

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]

--
Best Regards,
Huang, Ying

#7 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Quoted 23 lines · Qi Zheng

Hi Ying,

Quoted 7 lines · Ying
Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

Quoted 8 lines

For fallback list, do you mean pgdat->node_zonelists[]? If so, in build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node
populated_zone() will be checked before adding zone into zonelist. So, IIUC, we will not try to allocate from the memory less node.

Normally yes, but if it is the weird topology mentioned in [1], it's possible to allocate memory from it, it is a memoryless node, but it also has memory.

Quoted 5 lines

In addition to the above case, I think it's reasonable to remove memory less node from node_order[] in advance. In this way it will not to be traversed in build_zonelists_in_node_order().

[1]. https://lore.kernel.org/all/[email protected]/

Got it! Thank you for information. I think that it may be good to include this in the patch description to avoid potential confusing in the future.

--
Best Regards,
Huang, Ying

Quoted 20 lines

Thanks,
Qi

Quoted 16 lines

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]
--
Best Regards,
Huang, Ying

author
#8 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Hi Ying,

Quoted 29 lines · Ying
Quoted 27 lines · Qi Zheng

Hi Ying,

Quoted 7 lines · Ying
Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

Quoted 8 lines

For fallback list, do you mean pgdat->node_zonelists[]? If so, in build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node
populated_zone() will be checked before adding zone into zonelist. So, IIUC, we will not try to allocate from the memory less node.

Normally yes, but if it is the weird topology mentioned in [1], it's possible to allocate memory from it, it is a memoryless node, but it also has memory.

In addition to the above case, I think it's reasonable to remove memory less node from node_order[] in advance. In this way it will not to be traversed in build_zonelists_in_node_order().

Quoted 5 lines
Quoted 1 line

[1]. https://lore.kernel.org/all/[email protected]/

Got it! Thank you for information. I think that it may be good to include this in the patch description to avoid potential confusing in the future.

OK, maybe the commit message can be changed to the following:

```
In offline_pages(), if a node becomes memoryless, we
will clear its N_MEMORY state by calling node_states_clear_node().
But we do this after rebuilding the zonelists by calling
build_all_zonelists(), which will cause this memoryless node to
still be in the fallback nodes (node_order[]) of other nodes.

To drop memoryless nodes from fallback nodes in this case, just
call node_states_clear_node() before calling build_all_zonelists().

In this way, we will not try to allocate pages from memoryless
node0, then the panic mentioned in [1] will also be fixed. Even though
this problem has been solved by dropping the NODE_MIN_SIZE constrain
in x86 [2], it would be better to fix it in the core MM as well.

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

```

Thanks,
Qi

Quoted 25 lines

--
Best Regards,
Huang, Ying

Quoted 20 lines

Thanks,
Qi

Quoted 16 lines

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]
--
Best Regards,
Huang, Ying

#9 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Quoted 50 lines · Qi Zheng

Hi Ying,

Quoted 25 lines · Ying
Quoted 23 lines · Qi Zheng

Hi Ying,

Quoted 7 lines · Ying
Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

Quoted 8 lines

For fallback list, do you mean pgdat->node_zonelists[]? If so, in build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node
populated_zone() will be checked before adding zone into zonelist. So, IIUC, we will not try to allocate from the memory less node.

Normally yes, but if it is the weird topology mentioned in [1], it's possible to allocate memory from it, it is a memoryless node, but it also has memory.

Quoted 8 lines
Quoted 5 lines

In addition to the above case, I think it's reasonable to remove memory less node from node_order[] in advance. In this way it will not to be traversed in build_zonelists_in_node_order().

[1]. https://lore.kernel.org/all/[email protected]/

Got it! Thank you for information. I think that it may be good to include this in the patch description to avoid potential confusing in the future.

OK, maybe the commit message can be changed to the following:

```
In offline_pages(), if a node becomes memoryless, we
will clear its N_MEMORY state by calling node_states_clear_node().
But we do this after rebuilding the zonelists by calling
build_all_zonelists(), which will cause this memoryless node to
still be in the fallback nodes (node_order[]) of other nodes.

To drop memoryless nodes from fallback nodes in this case, just
call node_states_clear_node() before calling build_all_zonelists().

In this way, we will not try to allocate pages from memoryless
Quoted 8 lines
node0, then the panic mentioned in [1] will also be fixed. Even though
this problem has been solved by dropping the NODE_MIN_SIZE constrain
in x86 [2], it would be better to fix it in the core MM as well.

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

```

This is helpful. Thanks!

--
Best Regards,
Huang, Ying

Quoted 27 lines

Thanks,
Qi

Quoted 24 lines

--
Best Regards,
Huang, Ying

Quoted 20 lines

Thanks,
Qi

Quoted 16 lines

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]
--
Best Regards,
Huang, Ying

author
#10 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Quoted 56 lines · Ying
Quoted 54 lines · Qi Zheng

Hi Ying,

Quoted 25 lines · Ying
Quoted 23 lines · Qi Zheng

Hi Ying,

Quoted 7 lines · Ying
Quoted 5 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes.

Quoted 8 lines

For fallback list, do you mean pgdat->node_zonelists[]? If so, in build_all_zonelists
__build_all_zonelists
build_zonelists
build_zonelists_in_node_order
build_zonerefs_node
populated_zone() will be checked before adding zone into zonelist. So, IIUC, we will not try to allocate from the memory less node.

Normally yes, but if it is the weird topology mentioned in [1], it's possible to allocate memory from it, it is a memoryless node, but it also has memory.

Quoted 8 lines
Quoted 5 lines

In addition to the above case, I think it's reasonable to remove memory less node from node_order[] in advance. In this way it will not to be traversed in build_zonelists_in_node_order().

[1]. https://lore.kernel.org/all/[email protected]/

Got it! Thank you for information. I think that it may be good to include this in the patch description to avoid potential confusing in the future.

OK, maybe the commit message can be changed to the following:

```
In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback nodes (node_order[]) of other nodes.

To drop memoryless nodes from fallback nodes in this case, just call node_states_clear_node() before calling build_all_zonelists().

In this way, we will not try to allocate pages from memoryless node0, then the panic mentioned in [1] will also be fixed. Even though this problem has been solved by dropping the NODE_MIN_SIZE constrain in x86 [2], it would be better to fix it in the core MM as well.

Quoted 4 lines
Quoted 4 lines

[1]. https://lore.kernel.org/all/[email protected]/
[2]. https://lore.kernel.org/all/[email protected]/

```

Hi Andrew, can you help modify the commit message to this? :)

Thanks,
Qi

Quoted 34 lines

This is helpful. Thanks!

--
Best Regards,
Huang, Ying

Quoted 27 lines

Thanks,
Qi

Quoted 24 lines

--
Best Regards,
Huang, Ying

Quoted 20 lines

Thanks,
Qi

Quoted 16 lines

--
Best Regards,
Huang, Ying

Quoted 8 lines

This will incur
some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

[snip]
--
Best Regards,
Huang, Ying

maintainer
#11 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Quoted 1 line · On Mon, 23 Oct 2023 11:17:03 +0800 Qi Zheng <[email protected]> wrote:

Hi Andrew, can you help modify the commit message to this? :)

Done, thanks.

Acked-by on v3 2/2
#12 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

In reply to Qi Zheng
Quoted 9 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes. This will incur some runtime overhead.

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

s/memoryless node
/memoryless nodes

Quoted 12 lines
---
 mm/memory_hotplug.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memory_hotplug.c +0 -0
index d4a364fdaf8f..f019f7d6272c 100644

mm/memory_hotplug.c int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, · line 2043

Quoted 8 lines
mm/memory_hotplug.c +5 -0
@@ -2036,12 +2036,16 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,
 	/* reinitialise watermarks and update pcp limits */
 	init_per_zone_wmark_min();
 
+	/*
+	 * Make sure to mark the node as memory-less before rebuilding the zone
+	 * list. Otherwise this node would still appear in the fallback lists.
+	 */
+	node_states_clear_node(node, &arg);

Thanks,

Ingo

author
#13 lore raw

Re: [PATCH v3 2/2] mm: memory_hotplug: drop memoryless node from fallback lists

Hi Ingo,

Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Qi Zheng

In offline_pages(), if a node becomes memoryless, we will clear its N_MEMORY state by calling node_states_clear_node(). But we do this after rebuilding the zonelists by calling build_all_zonelists(), which will cause this memoryless node to still be in the fallback list of other nodes. This will incur some runtime overhead.

Quoted 5 lines
Quoted 2 lines

To drop memoryless node from fallback lists in this case, just call node_states_clear_node() before calling build_all_zonelists().

s/memoryless node
/memoryless nodes

Will do.

Quoted 16 lines
Quoted 16 lines
---
  mm/memory_hotplug.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
mm/memory_hotplug.c +0 -0
index d4a364fdaf8f..f019f7d6272c 100644
@@ -2036,12 +2036,16 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,
  	/* reinitialise watermarks and update pcp limits */
  	init_per_zone_wmark_min();
 
Quoted 7 lines

mm/memory_hotplug.c int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, · line 2043

Quoted 5 lines
mm/memory_hotplug.c +5 -0
+	/*
+	 * Make sure to mark the node as memory-less before rebuilding the zone
+	 * list. Otherwise this node would still appear in the fallback lists.
+	 */
+	node_states_clear_node(node, &arg);

Thanks.

Quoted 4 lines

Thanks,

Ingo