[PATCH v2 RESEND 2/3] mm: memblock: show all region flags in debugfs
From: Meijing Zhao
Date: Thu Aug 20 2026 - 22:10:30 EST
From: Meijing Zhao <zhaomeijing@xxxxxxxxxxx>
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 the remaining flags
are hidden from debugfs.
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@xxxxxxxxxxx>
---
mm/memblock.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index f2952d725c10..36a8d2a9378d 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2895,7 +2895,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];
@@ -2909,16 +2911,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