* [PATCH v2 1/3] mm: memblock: add missing HugeTLB flag name
2026-08-20 7:51 [PATCH v2 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
@ 2026-08-20 7:51 ` Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Meijing Zhao
2 siblings, 0 replies; 4+ messages in thread
From: Meijing Zhao @ 2026-08-20 7:51 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
Commit 7d163a75f821 ("memblock: make HugeTLB bootmem allocation work
with KHO") added MEMBLOCK_RSRV_HUGETLB but did not add the corresponding
entry to flagname[]. As a result, memblock debugfs cannot report the
flag by name.
Add the missing RSV_HUGETLB entry.
Fixes: 7d163a75f821 ("memblock: make HugeTLB bootmem allocation work with KHO")
Signed-off-by: Meijing Zhao <zhaomeijing@lixiang.com>
---
mm/memblock.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/memblock.c b/mm/memblock.c
index 09b84d1cdb92..99f8e1bc60a8 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2902,6 +2902,7 @@ static const char * const flagname[] = {
[ilog2(MEMBLOCK_RSRV_NOINIT)] = "RSV_NIT",
[ilog2(MEMBLOCK_RSRV_KERN)] = "RSV_KERN",
[ilog2(MEMBLOCK_KHO_SCRATCH)] = "KHO_SCRATCH",
+ [ilog2(MEMBLOCK_RSRV_HUGETLB)] = "RSV_HUGETLB",
[ilog2(MEMBLOCK_NODUMP)] = "NODUMP",
};
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] mm: memblock: show all region flags in debugfs
2026-08-20 7:51 [PATCH v2 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
@ 2026-08-20 7:51 ` Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Meijing Zhao
2 siblings, 0 replies; 4+ messages in thread
From: Meijing Zhao @ 2026-08-20 7:51 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
Commit 493f349e38d0 ("memblock: Add flags and nid info in memblock
debugfs") made memblock_debug_show() stop after finding the first set
flag. A memblock region can carry multiple flags, so debugfs hides all
but the lowest set bit.
In particular, memory allocated for HugeTLB pages is reserved with both
MEMBLOCK_RSRV_KERN and MEMBLOCK_RSRV_HUGETLB, but debugfs only reports
RSV_KERN.
Walk all bits in the region flags and print every set flag separated by
"|". Keep walking beyond flagname[] so that a set flag without a known
name is reported as UNKNOWN rather than silently ignored.
A HugeTLB reservation is now shown as:
RSV_KERN|RSV_HUGETLB
instead of:
RSV_KERN
Fixes: 493f349e38d0 ("memblock: Add flags and nid info in memblock debugfs")
Signed-off-by: Meijing Zhao <zhaomeijing@lixiang.com>
---
mm/memblock.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index 99f8e1bc60a8..7eddcc412618 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2912,7 +2912,9 @@ static int memblock_debug_show(struct seq_file *m, void *private)
struct memblock_region *reg;
int i, j, nid;
unsigned int count = ARRAY_SIZE(flagname);
+ unsigned int flags;
phys_addr_t end;
+ bool first;
for (i = 0; i < type->cnt; i++) {
reg = &type->regions[i];
@@ -2926,16 +2928,20 @@ static int memblock_debug_show(struct seq_file *m, void *private)
else
seq_printf(m, "%4c ", 'x');
if (reg->flags) {
- for (j = 0; j < count; j++) {
- if (reg->flags & (1U << j)) {
- seq_printf(m, "%s\n", flagname[j]);
- break;
- }
+ flags = reg->flags;
+ first = true;
+ for (j = 0; flags; j++, flags >>= 1) {
+ if (!(flags & 1))
+ continue;
+ if (!first)
+ seq_putc(m, '|');
+ seq_puts(m, j < count && flagname[j] ?
+ flagname[j] : "UNKNOWN");
+ first = false;
}
- if (j == count)
- seq_printf(m, "%s\n", "UNKNOWN");
+ seq_putc(m, '\n');
} else {
- seq_printf(m, "%s\n", "NONE");
+ seq_puts(m, "NONE\n");
}
}
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 3/3] mm: memblock: synchronize debugfs reads with memory hotplug
2026-08-20 7:51 [PATCH v2 0/3] mm: memblock: fix debugfs flag reporting and synchronization Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 1/3] mm: memblock: add missing HugeTLB flag name Meijing Zhao
2026-08-20 7:51 ` [PATCH v2 2/3] mm: memblock: show all region flags in debugfs Meijing Zhao
@ 2026-08-20 7:51 ` Meijing Zhao
2 siblings, 0 replies; 4+ messages in thread
From: Meijing Zhao @ 2026-08-20 7:51 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton
Cc: linux-mm, linux-kernel, Wandun Chen, Meijing Zhao
From: Meijing Zhao <zhaomeijing@lixiang.com>
memblock_debug_show() walks a memblock region array without
synchronization. With CONFIG_ARCH_KEEP_MEMBLOCK, memory hotplug can
concurrently add a region. If the array has to grow,
memblock_double_array() replaces type->regions and frees the old
allocation while the debugfs reader may still be using it.
Hold mem_hotplug_lock in read mode while producing the debugfs output.
Memory hotplug updates already hold the write side of this lock, so the
region array remains stable throughout the walk. The helpers are no-ops
when CONFIG_MEMORY_HOTPLUG is disabled.
Fixes: f9126ab9241f ("memory-hotplug: fix wrong edge when hot add a new node")
Signed-off-by: Meijing Zhao <zhaomeijing@lixiang.com>
---
mm/memblock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/memblock.c b/mm/memblock.c
index 7eddcc412618..620a5dd7f5f8 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -14,6 +14,7 @@
#include <linux/pfn.h>
#include <linux/debugfs.h>
#include <linux/kmemleak.h>
+#include <linux/memory_hotplug.h>
#include <linux/seq_file.h>
#include <linux/memblock.h>
#include <linux/mutex.h>
@@ -2916,6 +2917,7 @@ static int memblock_debug_show(struct seq_file *m, void *private)
phys_addr_t end;
bool first;
+ get_online_mems();
for (i = 0; i < type->cnt; i++) {
reg = &type->regions[i];
end = reg->base + reg->size - 1;
@@ -2944,6 +2946,7 @@ static int memblock_debug_show(struct seq_file *m, void *private)
seq_puts(m, "NONE\n");
}
}
+ put_online_mems();
return 0;
}
DEFINE_SHOW_ATTRIBUTE(memblock_debug);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread