treewide, mm: initialize node_possible_map like the other node maps
Subsystems (6)
cover treewide, mm: initialize node_possible_map like the other node maps
While reviewing an earlier series [1], Andrew asked why we carefully initialize node_possible_map at compile time, then zero it within __init code anyway.
node_possible_map, aliased by node_states[N_POSSIBLE], is initialized to NODE_MASK_ALL at compile time, unlike the other entries, which are initialized with only node 0 set.
Architectures that use numa_memblks set node_possible_map from numa_nodes_parsed, so the compile-time value is meaningless for them.
However, a few architectures that do not use numa_memblks do not set node_possible_map on their own. Once these architectures set node_possible_map to match their own topology, the NODE_MASK_ALL initialization can be removed.
Patches 1-2 handle sparc64 and sh, which do not set node_possible_map themselves. Both set node_online_map from their topology, so set node_possible_map from node_online_map.
Patch 3 handles powerpc, which sets node_possible_map by intersecting it with node_online_map. Nothing sets node_possible_map before this, so it is still NODE_MASK_ALL and the intersection is just node_online_map. Once patch 4 changes that initial value, the intersection would no longer be node_online_map, so assign node_online_map directly.
Patch 4 initializes node_possible_map with only node 0 set, like the other node_states[] entries. NODE_MASK_ALL is then no longer used, so remove it and its only helper NODE_MASK_LAST_WORD.
[1] https://lore.kernel.org/all/[email protected]/
Sang-Heon Jeon (4):
sparc64: set node_possible_map in bootmem_init_numa()
sh: set node_possible_map in do_init_bootmem() powerpc/numa: set node_possible_map from node_online_map mm/page_alloc: initialize node_possible_map like the other node maps
arch/powerpc/mm/numa.c | 2 +- arch/sh/mm/init.c | 2 ++ arch/sparc/mm/init_64.c | 2 ++ include/linux/nodemask.h | 20 -------------------- mm/page_alloc.c | 2 +- 5 files changed, 6 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 sparc64: set node_possible_map in bootmem_init_numa()
Unlike other NUMA architectures, sparc64 never sets node_possible_map. bootmem_init_numa() marks all nodes online and node_online_map does not change afterwards, so set node_possible_map from node_online_map.
--- arch/sparc/mm/init_64.c | 2 ++ 1 file changed, 2 insertions(+)
arch/sparc/mm/init_64.c +2 -0
@@ -1559,6 +1559,8 @@ static int __init bootmem_init_numa(void)else err =numa_parse_sun4u (); } +if (!err) + node_possible_map = node_online_map;return err; }
Signature · 1 line
2.43.0
PATCH 2/4 sh: set node_possible_map in do_init_bootmem()
In reply to Sang-Heon JeonUnlike other NUMA architectures, sh never sets node_possible_map. do_init_bootmem() marks node 0 online and plat_mem_setup() marks the rest online, after which node_online_map does not change, so set node_possible_map from node_online_map.
--- arch/sh/mm/init.c | 2 ++ 1 file changed, 2 insertions(+)
arch/sh/mm/init.c +2 -0
@@ -227,6 +227,8 @@ static void __init do_init_bootmem(void)node_set_online (0 );plat_mem_setup (); + + node_possible_map = node_online_map; }static void __init early_reserve_mem (void )
Signature · 1 line
2.43.0
PATCH 3/4 powerpc/numa: set node_possible_map from node_online_map
In reply to Sang-Heon Jeonmem_topology_setup() intersects node_possible_map with node_online_map. Nothing sets node_possible_map before this, so it is NODE_MASK_ALL and the result is just node_online_map.
In preparation for changing node_possible_map's initial value, mem_topology_setup() no longer depends on it.
No functional change.
--- arch/powerpc/mm/numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/numa.c +1 -1
@@ -1179,7 +1179,7 @@ void __init mem_topology_setup(void)* that we expect to make use of for this platform's affinity * calculations. */ -nodes_and (node_possible_map, node_possible_map, node_online_map); + node_possible_map = node_online_map;find_possible_nodes ();
Signature · 1 line
2.43.0
Yury Norov
maintainerRe: [PATCH 3/4] powerpc/numa: set node_possible_map from node_online_map
Quoted 19 lines · Sang-Heon Jeon
mem_topology_setup()intersectsnode_possible_mapwithnode_online_map. Nothing setsnode_possible_mapbefore this, so it isNODE_MASK_ALLand the result is justnode_online_map.In preparation for changing node_possible_map's initial value,
mem_topology_setup()no longer depends on it.No functional change.
Signed-off-by Sang-Heon Jeon <[email protected]>--- arch/powerpc/mm/numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/mm/numa.c +0
-0
arch/powerpc/mm/numa.c void __init mem_topology_setup(void) · line 1184
Quoted 7 lines
arch/powerpc/mm/numa.c +1
-1@@ -1179,7 +1179,7 @@ void __init mem_topology_setup(void)* that we expect to make use of for this platform's affinity * calculations. */ -nodes_and (node_possible_map, node_possible_map, node_online_map); + node_possible_map = node_online_map;find_possible_nodes ();
And in find_possible_nodes():
for (i = 0; i < max_nodes; i++) {
if (!node_possible(i))
node_set(i, node_possible_map);
}So, assuming the code reaches to that point, you unconditionally online all the offlined nodes.
This doesn't look correct at the first glance, and definitely it's not a "No functional change" type of things.
Re: [PATCH 3/4] powerpc/numa: set node_possible_map from node_online_map
Hi Yury,
Quoted 31 lines · Yury Norov
Quoted 19 lines · Sang-Heon Jeon
mem_topology_setup()intersectsnode_possible_mapwithnode_online_map. Nothing setsnode_possible_mapbefore this, so it isNODE_MASK_ALLand the result is justnode_online_map.In preparation for changing node_possible_map's initial value,
mem_topology_setup()no longer depends on it.No functional change.
Signed-off-by Sang-Heon Jeon <[email protected]>--- arch/powerpc/mm/numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/mm/numa.c +0
-0arch/powerpc/mm/numa.c void __init mem_topology_setup(void) · line 1184
Quoted 7 lines
arch/powerpc/mm/numa.c +1
-1@@ -1179,7 +1179,7 @@ void __init mem_topology_setup(void)* that we expect to make use of for this platform's affinity * calculations. */ -nodes_and (node_possible_map, node_possible_map, node_online_map); + node_possible_map = node_online_map;find_possible_nodes ();And in
find_possible_nodes():
Quoted 7 lines
for (i = 0; i < max_nodes; i++) { if (!node_possible(i)) node_set(i, node_possible_map); }So, assuming the code reaches to that point, you unconditionally online all the offlined nodes.
This loop only sets bits in node_possible_map, not in node_online_map, so I can't find how it onlines the offlined nodes unexpectedly. Please correct me if I'm wrong or missing something.
Or are you talking about the case where max_nodes exceeds MAX_NUMNODES, which was also noticed by sashiko? I think it is a pre-existing issue, and this patch does not affect it.
Quoted 2 lines
This doesn't look correct at the first glance, and definitely it's not a "No functional change" type of things.
Best Regards,
Sang-Heon Jeon
Yury Norov
maintainerRe: [PATCH 3/4] powerpc/numa: set node_possible_map from node_online_map
Quoted 42 lines · Sang-Heon Jeon
Hi Yury,
Quoted 31 lines · Yury Norov
Quoted 19 lines · Sang-Heon Jeon
mem_topology_setup()intersectsnode_possible_mapwithnode_online_map. Nothing setsnode_possible_mapbefore this, so it isNODE_MASK_ALLand the result is justnode_online_map.In preparation for changing node_possible_map's initial value,
mem_topology_setup()no longer depends on it.No functional change.
Signed-off-by Sang-Heon Jeon <[email protected]>--- arch/powerpc/mm/numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/mm/numa.c +0
-0arch/powerpc/mm/numa.c void __init mem_topology_setup(void) · line 1184
Quoted 7 lines
arch/powerpc/mm/numa.c +1
-1@@ -1179,7 +1179,7 @@ void __init mem_topology_setup(void)* that we expect to make use of for this platform's affinity * calculations. */ -nodes_and (node_possible_map, node_possible_map, node_online_map); + node_possible_map = node_online_map;find_possible_nodes ();And in
find_possible_nodes():Quoted 7 lines
for (i = 0; i < max_nodes; i++) { if (!node_possible(i)) node_set(i, node_possible_map); }So, assuming the code reaches to that point, you unconditionally online all the offlined nodes.
Quoted 7 lines
This loop only sets bits in
node_possible_map, not innode_online_map, so I can't find how it onlines the offlined nodes unexpectedly. Please correct me if I'm wrong or missing something.Or are you talking about the case where
max_nodesexceedsMAX_NUMNODES, which was also noticed by sashiko? I think it is a pre-existing issue, and this patch does not affect it.
Oops, sorry, It's my bad. They are nodemask_t, not pointers, so in "node_possible_map = node_online_map" you copy by value.
Thanks,
Yury
PATCH 4/4 mm/page_alloc: initialize node_possible_map like the other node maps
In reply to Sang-Heon Jeonnode_states[N_POSSIBLE], aliased by node_possible_map, is initialized to NODE_MASK_ALL, unlike the other entries, which are initialized with only node 0 set.
On !NUMA, MAX_NUMNODES == 1, so initializing node_possible_map to NODE_MASK_ALL is equivalent to initializing it with only node 0 set.
On NUMA, every architecture now sets node_possible_map after parsing its NUMA topology, so nothing relies on the initial value.
So, instead of initializing node_possible_map to NODE_MASK_ALL, set only node 0, like the other entries. Then NODE_MASK_ALL is no longer used, so remove it and its only helper NODE_MASK_LAST_WORD.
No functional change.
--- include/linux/nodemask.h | 20 -------------------- mm/page_alloc.c | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-)
include/linux/nodemask.h +0 -20
@@ -47,7 +47,6 @@* MAX_NUMNODES * * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set -* NODE_MASK_ALL Initializer - all bits set * NODE_MASK_NONE Initializer - no bits set * unsigned long *nodes_addr(mask) Array of unsigned long's in mask *
@@ -296,25 +295,6 @@ static __always_inline unsigned int __first_unset_node(const nodemask_t *maskp)return min (MAX_NUMNODES ,find_first_zero_bit (maskp->bits,MAX_NUMNODES )); } -#define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES) - -#if MAX_NUMNODES <=BITS_PER_LONG - -#define NODE_MASK_ALL \ -((nodemask_t) { { \ - [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \ -} }) - -#else - -#define NODE_MASK_ALL \ -((nodemask_t) { { \ - [0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL, \ - [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \ -} }) - -#endif -#define NODE_MASK_NONE \ ((nodemask_t) { { \ [0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] = 0UL \
mm/page_alloc.c +1 -1
@@ -191,7 +191,7 @@ EXPORT_SYMBOL(latent_entropy);* Array of node states. */ nodemask_t node_states[NR_NODE_STATES ]__read_mostly = { - [N_POSSIBLE ] =NODE_MASK_ALL , + [N_POSSIBLE ] = { { [0 ] =1UL } }, [N_ONLINE ] = { { [0 ] =1UL } }, #ifndef CONFIG_NUMA [N_NORMAL_MEMORY] = { { [0] = 1UL } },
Signature · 1 line
2.43.0