* [PATCH 0/9] treewide, numa_memblks: remove redundant work during NUMA init
@ 2026-06-28 13:58 Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk() Sang-Heon Jeon
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-28 13:58 UTC (permalink / raw)
To: Andrew Morton, Andy Lutomirski, Borislav Petkov, Danilo Krummrich,
Dave Hansen, Greg Kroah-Hartman, Huacai Chen, Ingo Molnar,
Mike Rapoport, Peter Zijlstra, Rafael J. Wysocki, Rob Herring,
Saravana Kannan, Thomas Gleixner
Cc: Sang-Heon Jeon, devicetree, driver-core, H. Peter Anvin,
Len Brown, linux-acpi, linux-mm, loongarch, WANG Xuerui, x86,
linux-kernel
Every existing numa_add_memblk() caller passes a valid node id and
separately marks that node in numa_nodes_parsed with node_set(). In
addition, numa_nodemask_from_meminfo() recomputes the same "nodes that own
memory" set from numa_meminfo, which numa_nodes_parsed already contains.
This redundancy implicitly depends on the callers' node_set(). So, before
removing the redundancy, make numa_add_memblk() set the node in
numa_nodes_parsed explicitly. Then remove the per-caller node_set() and
numa_nodemask_from_meminfo().
Also, since the generic numa_register_meminfo() already sets
node_possible_map to numa_nodes_parsed, remove the duplicate assignment in
arch_numa's numa_register_nodes().
Patch 1 adds the node_set() to numa_add_memblk() itself, so every memblk's
node is set in numa_nodes_parsed on add.
Patches 2-6 depend on patch 1 and remove the redundant per-caller node_set()
from all callers.
Patch 7 removes both numa_nodemask_from_meminfo() call sites and the unused
function itself.
Patch 8 removes the duplicate node_possible_map assignment in arch_numa.
Patch 9 is a minor cleanup, using the existing numa_add_reserved_memblk()
wrapper in numa_cleanup_meminfo().
No functional change.
Sang-Heon Jeon (9):
mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk()
ACPI: NUMA: remove redundant numa_nodes_parsed node_set()
of/numa: remove redundant numa_nodes_parsed node_set()
x86/numa: remove redundant numa_nodes_parsed node_set()
arch_numa: remove redundant numa_nodes_parsed node_set()
LoongArch: remove redundant numa_nodes_parsed node_set()
mm: numa_memblks: remove redundant numa_nodemask_from_meminfo()
arch_numa: remove redundant node_possible_map assignment
mm: numa_memblks: use numa_add_reserved_memblk() in
numa_cleanup_meminfo()
arch/loongarch/kernel/numa.c | 1 -
arch/x86/mm/amdtopology.c | 1 -
arch/x86/mm/numa.c | 1 -
drivers/acpi/numa/srat.c | 2 --
drivers/base/arch_numa.c | 4 ----
drivers/of/of_numa.c | 5 +----
mm/numa_memblks.c | 41 +++++++++++++++---------------------
7 files changed, 18 insertions(+), 37 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk()
2026-06-28 13:58 [PATCH 0/9] treewide, numa_memblks: remove redundant work during NUMA init Sang-Heon Jeon
@ 2026-06-28 13:58 ` Sang-Heon Jeon
[not found] ` <178298867638.1436291.11279946475033863942.b4-review@b4>
2026-06-28 13:58 ` [PATCH 7/9] mm: numa_memblks: remove redundant numa_nodemask_from_meminfo() Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 9/9] mm: numa_memblks: use numa_add_reserved_memblk() in numa_cleanup_meminfo() Sang-Heon Jeon
2 siblings, 1 reply; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-28 13:58 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport; +Cc: Sang-Heon Jeon, linux-mm
Every existing numa_add_memblk() caller separately marks the new node in
numa_nodes_parsed with node_set(). Set the node in numa_add_memblk() itself
on a successful add, so this no longer depends on each caller.
numa_add_memblk_to() now returns -EINVAL for an out-of-range node id, so a
zero return implies @nid was valid. No existing caller passes an
invalid one, so existing callers are unaffected.
The per-caller node_set() calls are removed in later patches.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/numa_memblks.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c
index 3c3c4eac3514..2d92ca38c02a 100644
--- a/mm/numa_memblks.c
+++ b/mm/numa_memblks.c
@@ -135,14 +135,17 @@ EXPORT_SYMBOL(__node_distance);
static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
struct numa_meminfo *mi)
{
- /* ignore zero length blks */
- if (start == end)
- return 0;
-
/* whine about and ignore invalid blks */
- if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
+ if (nid < 0 || nid >= MAX_NUMNODES) {
pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
nid, start, end - 1);
+ return -EINVAL;
+ }
+
+ /* ignore zero length or invalid blks */
+ if (start >= end) {
+ pr_warn("Warning: invalid memblk node size %d [mem %#010Lx-%#010Lx]\n",
+ nid, start, end - 1);
return 0;
}
@@ -193,13 +196,20 @@ static void __init numa_move_tail_memblk(struct numa_meminfo *dst, int idx,
* @end: End address of the new memblk
*
* Add a new memblk to the default numa_meminfo.
+ * On success @nid is also set in numa_nodes_parsed.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int __init numa_add_memblk(int nid, u64 start, u64 end)
{
- return numa_add_memblk_to(nid, start, end, &numa_meminfo);
+ int ret;
+
+ ret = numa_add_memblk_to(nid, start, end, &numa_meminfo);
+ if (!ret)
+ node_set(nid, numa_nodes_parsed);
+
+ return ret;
}
/**
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 7/9] mm: numa_memblks: remove redundant numa_nodemask_from_meminfo()
2026-06-28 13:58 [PATCH 0/9] treewide, numa_memblks: remove redundant work during NUMA init Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk() Sang-Heon Jeon
@ 2026-06-28 13:58 ` Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 9/9] mm: numa_memblks: use numa_add_reserved_memblk() in numa_cleanup_meminfo() Sang-Heon Jeon
2 siblings, 0 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-28 13:58 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport; +Cc: Sang-Heon Jeon, linux-mm
numa_add_memblk() now sets each added node in numa_nodes_parsed, so
numa_nodes_parsed already contains every node that owns memory. The nodes
numa_nodemask_from_meminfo() adds from numa_meminfo are already set, so the
calls in numa_alloc_distance() and numa_register_meminfo() are redundant.
So remove both call sites and the unused function itself.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/numa_memblks.c | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c
index 2d92ca38c02a..edc231538954 100644
--- a/mm/numa_memblks.c
+++ b/mm/numa_memblks.c
@@ -17,20 +17,6 @@ nodemask_t numa_nodes_parsed __initdata;
static struct numa_meminfo numa_meminfo __initdata_or_meminfo;
static struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
-/*
- * Set nodes, which have memory in @mi, in *@nodemask.
- */
-static void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
- const struct numa_meminfo *mi)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
- if (mi->blk[i].start != mi->blk[i].end &&
- mi->blk[i].nid != NUMA_NO_NODE)
- node_set(mi->blk[i].nid, *nodemask);
-}
-
/**
* numa_reset_distance - Reset NUMA distance table
*
@@ -56,7 +42,6 @@ static int __init numa_alloc_distance(void)
/* size the new table and allocate it */
nodes_parsed = numa_nodes_parsed;
- numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo);
for_each_node_mask(i, nodes_parsed)
cnt = i;
@@ -411,7 +396,6 @@ static int __init numa_register_meminfo(struct numa_meminfo *mi)
/* Account for nodes with cpus and no memory */
node_possible_map = numa_nodes_parsed;
- numa_nodemask_from_meminfo(&node_possible_map, mi);
if (WARN_ON(nodes_empty(node_possible_map)))
return -EINVAL;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 9/9] mm: numa_memblks: use numa_add_reserved_memblk() in numa_cleanup_meminfo()
2026-06-28 13:58 [PATCH 0/9] treewide, numa_memblks: remove redundant work during NUMA init Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk() Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 7/9] mm: numa_memblks: remove redundant numa_nodemask_from_meminfo() Sang-Heon Jeon
@ 2026-06-28 13:58 ` Sang-Heon Jeon
2 siblings, 0 replies; 5+ messages in thread
From: Sang-Heon Jeon @ 2026-06-28 13:58 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport; +Cc: Sang-Heon Jeon, linux-mm
numa_cleanup_meminfo() calls the internal numa_add_memblk_to() to add a
block to numa_reserved_meminfo, even though numa_add_reserved_memblk()
wraps exactly that.
Use the wrapper instead, so numa_add_memblk_to() is only called through
its two wrappers.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/numa_memblks.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c
index edc231538954..86b84a89fd9e 100644
--- a/mm/numa_memblks.c
+++ b/mm/numa_memblks.c
@@ -251,8 +251,7 @@ int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
/* preserve info for non-RAM areas above 'max_pfn': */
if (bi->end > high) {
- numa_add_memblk_to(bi->nid, high, bi->end,
- &numa_reserved_meminfo);
+ numa_add_reserved_memblk(bi->nid, high, bi->end);
bi->end = high;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk()
[not found] ` <CABFDxMF4B5cYYw5h+JWwBMFfz9XMVZMJdEwwy3ksRysYBTAZGw@mail.gmail.com>
@ 2026-07-02 15:54 ` Mike Rapoport
0 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport @ 2026-07-02 15:54 UTC (permalink / raw)
To: Sang-Heon Jeon; +Cc: Andrew Morton, linux-mm
On Thu, Jul 02, 2026 at 10:43:40PM +0900, Sang-Heon Jeon wrote:
> Hi, Mike
>
> On Thu, Jul 2, 2026 at 7:38 PM Mike Rapoport <rppt@kernel.org> wrote:
> >
> > > Every existing numa_add_memblk() caller separately marks the new node in
> > > numa_nodes_parsed with node_set(). Set the node in numa_add_memblk() itself
> > > on a successful add, so this no longer depends on each caller.
> > >
> > > numa_add_memblk_to() now returns -EINVAL for an out-of-range node id, so a
> > > zero return implies @nid was valid. No existing caller passes an
> > > invalid one, so existing callers are unaffected.
> > >
> > > The per-caller node_set() calls are removed in later patches.
> > >
> > > Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
> > >
> > > diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c
> > > index 3c3c4eac3514..2d92ca38c02a 100644
> > > --- a/mm/numa_memblks.c
> > > +++ b/mm/numa_memblks.c
> > > @@ -135,14 +135,17 @@ EXPORT_SYMBOL(__node_distance);
> > > static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
> > > struct numa_meminfo *mi)
> > > {
> > > - /* ignore zero length blks */
> > > - if (start == end)
> > > - return 0;
> > > -
> > > /* whine about and ignore invalid blks */
> > > - if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
> > > + if (nid < 0 || nid >= MAX_NUMNODES) {
> > > pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
> > > nid, start, end - 1);
> > > + return -EINVAL;
> > > + }
> > > +
> > > + /* ignore zero length or invalid blks */
> > > + if (start >= end) {
> > > + pr_warn("Warning: invalid memblk node size %d [mem %#010Lx-%#010Lx]\n",
> > > + nid, start, end - 1);
> >
> > Nit: any reason to put this check here instead of replacing
> >
> > if (start == end)
> >
> > ?
>
> Reordering is needed to ensure the following node_set() is not called
> with an invalid nid.
> While doing that, I thought the start == end condition is the same
> kind of invalid blk, so I moved it into the warning block.
> But no strong opinion here though. Should I go back to not printing
> the warning for start == end in v2?
Yeah, please skip the warning in v2.
> > --
> > Sincerely yours,
> > Mike.
> >
>
> Best Regards,
> Sang-Heon Jeon
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-03 1:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-28 13:58 [PATCH 0/9] treewide, numa_memblks: remove redundant work during NUMA init Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 1/9] mm: numa_memblks: set numa_nodes_parsed in numa_add_memblk() Sang-Heon Jeon
[not found] ` <178298867638.1436291.11279946475033863942.b4-review@b4>
[not found] ` <CABFDxMF4B5cYYw5h+JWwBMFfz9XMVZMJdEwwy3ksRysYBTAZGw@mail.gmail.com>
2026-07-02 15:54 ` Mike Rapoport
2026-06-28 13:58 ` [PATCH 7/9] mm: numa_memblks: remove redundant numa_nodemask_from_meminfo() Sang-Heon Jeon
2026-06-28 13:58 ` [PATCH 9/9] mm: numa_memblks: use numa_add_reserved_memblk() in numa_cleanup_meminfo() Sang-Heon Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox