handle memoryless nodes more appropriately
Subsystems (3)
v2 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 v1 -> v2:
- modify the commit message in [PATCH 1/2], mention that it can also fix the specific crash. (suggested by Ingo Molnar)
Qi Zheng (2):
mm: page_alloc: skip memoryless nodes entirely
mm: memory_hotplug: drop memoryless node from fallback lists
mm/memory_hotplug.c | 2 +- mm/page_alloc.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 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
@@ -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
Re: [PATCH v2 1/2] mm: page_alloc: skip memoryless nodes entirely
Quoted 41 lines · Qi Zheng
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: 1After 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: 1So 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_SIZEconstrain 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]/Signed-off-by Qi Zheng <[email protected]>--- mm/page_alloc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)mm/page_alloc.c +0
-0@@ -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 ;
mm/page_alloc.c int find_next_best_node(int node, nodemask_t *used_node_mask) · line 5062
Quoted 10 lines
mm/page_alloc.c +5
-2-/* 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; }
Makes sense to me; I suspect that online_pages() will just to the right thing and call build_all_zonelists() to fix it up.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 1/2] mm: page_alloc: skip memoryless nodes entirely
Hi David,
Quoted 48 lines · David Hildenbrand
Quoted 47 lines · Qi Zheng
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: 1After 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: 1So 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_SIZEconstrain 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]/Signed-off-by Qi Zheng <[email protected]>---
mm/page_alloc.c| 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)mm/page_alloc.c +2
-2@@ -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.
Quoted 8 lines
Quoted 6 lines
+ */
+ if (!node_isset(node,*used_node_mask) &&node_state(node, N_MEMORY)) {
node_set(node, *used_node_mask);
return node;
}Makes sense to me; I suspect that
online_pages()will just to the right thing and callbuild_all_zonelists()to fix it up.
Yes, the find_next_best_node() will be called by build_all_zonelists().
Quoted 2 lines
Thanks.
Quoted 1 line
PATCH v2 2/2 mm: memory_hotplug: drop memoryless node from fallback lists
In reply to Qi ZhengIn 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
@@ -2036,12 +2036,12 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,/* reinitialise watermarks and update pcp limits */ init_per_zone_wmark_min (); +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
Re: [PATCH v2 2/2] mm: memory_hotplug: drop memoryless node from fallback lists
Quoted 23 lines · Qi Zheng
In
offline_pages(), if a node becomes memoryless, we will clear itsN_MEMORYstate by callingnode_states_clear_node(). But we do this after rebuilding the zonelists by callingbuild_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 callingbuild_all_zonelists().Signed-off-by Qi Zheng <[email protected]>--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +0
-0@@ -2036,12 +2036,12 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,/* reinitialise watermarks and update pcp limits */ init_per_zone_wmark_min ();
mm/memory_hotplug.c int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, · line 2047
Quoted 10 lines
mm/memory_hotplug.c +1
-1+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);
Probably worth a comment.
/*
* Make sure to mark the node as memory-less before rebuilding the zone
* list. Otherwise this node would still appear in the fallback lists. */
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 2/2] mm: memory_hotplug: drop memoryless node from fallback lists
Hi David,
Quoted 36 lines · David Hildenbrand
Quoted 22 lines · Qi Zheng
In
offline_pages(), if a node becomes memoryless, we will clear itsN_MEMORYstate by callingnode_states_clear_node(). But we do this after rebuilding the zonelists by callingbuild_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 callingbuild_all_zonelists().Signed-off-by Qi Zheng <[email protected]>---
mm/memory_hotplug.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)mm/memory_hotplug.c +0
-0@@ -2036,12 +2036,12 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages, /* reinitialise watermarks and update pcp limits */mm/memory_hotplug.c int __ref offline_pages(unsigned long · line 2046
Quoted 10 lines
mm/memory_hotplug.c +1
-1init_per_zone_wmark_min(); + 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);Probably worth a comment.
Quoted 4 lines
/*
* Make sure to mark the node as memory-less before rebuilding the zone
* list. Otherwise this node would still appear in the fallback lists. */
OK, will add it in the v3.
Quoted 2 lines
Thanks.
Quoted 1 line
Quoted 7 lines · Qi Zheng
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.
What's the end result of this change -- IOW why do we care? Patch #1 mentions "which will reduce runtime overhead." and patch #2 mentions "This will incur some runtime overhead.". IIUC the comment in patch #1 correctly, these changes don't fix anything, correct?
Did you look into showing a performance gain?
Signature · 3 lines
Cheers, David / dhildenb
Hi David,
Quoted 10 lines · David Hildenbrand
Quoted 7 lines · Qi Zheng
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.
What's the end result of this change -- IOW why do we care? Patch #1 mentions "which will reduce runtime overhead." and patch #2 mentions "This will incur some runtime overhead.". IIUC the comment in patch #1 correctly, these changes don't fix anything, correct?
Yes, after dropping the NODE_MIN_SIZE constrain in x86, the panic problem fixed by this patch no longer exists (Unless there are other architectures that have this constrain).
The reason I am re-sending this patch is that I agree with Ingo's point of view:
``` While I agree with dropping the limitation, and I agree that 9391a3f9c7f1 should have provided more of a justification, I believe a core MM fix is in order as well, for it to not crash. ```
I also think that core MM should be safe (not crash) even in some weird topology.
Quoted 3 lines
Did you look into showing a performance gain?
No, and I think the performance gain should be small, after all it just traverses one less node. ;)
Thanks,
Qi