[PATCH] mm/mm_init: don't subtract managed CMA pages twice

From: David Hildenbrand (Arm)

Date: Thu Nov 19 2026 - 06:19:22 EST


From: Chris Mason <mason@xxxxxxxxxx>

With hugetlb_cma_only, the "reserved" value in the "Memory:" boot message
can be wrong (small or underflowed).

When mem_init_print_info() calculates the reserved memory, it assumes that
no CMA pages are managed yet. However, some CMA pages from hugetlb might
already be managed at that point, so we end up subtracting them twice.

Fix it by only subtracting CMA pages that are not managed yet.

This has very low urgency, as it only affects a boot message.

Fixes: b1b7c045e808 ("mm/hugetlb: initialize gigantic bootmem hugepage struct pages earlier")
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
[ david: improve description and comment ]
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
This should go through the memblock tree.
---
mm/mm_init.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 27a50ecd5c20e..26033afa9bc05 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2608,6 +2608,12 @@ static void __init mem_init_print_info(void)
{
unsigned long physpages, codesize, datasize, rosize, bss_size;
unsigned long init_code_size, init_data_size;
+ unsigned long unmanaged_cma = totalcma_pages;
+ struct zone *zone;
+
+ /* Some CMA pages might already be managed. */
+ for_each_populated_zone(zone)
+ unmanaged_cma -= zone_cma_pages(zone);

physpages = get_num_physpages();
codesize = _etext - _stext;
@@ -2647,7 +2653,7 @@ static void __init mem_init_print_info(void)
K(nr_free_pages()), K(physpages),
codesize / SZ_1K, datasize / SZ_1K, rosize / SZ_1K,
(init_data_size + init_code_size) / SZ_1K, bss_size / SZ_1K,
- K(physpages - totalram_pages() - totalcma_pages),
+ K(physpages - totalram_pages() - unmanaged_cma),
K(totalcma_pages)
#ifdef CONFIG_HIGHMEM
, K(totalhigh_pages())

---
base-commit: d9a27fa1050902a6e38bdb780b0277cbf1dfa5a5
change-id: 20261119-cma_managed-2541ae8731ae

Best regards,
--
David Hildenbrand (Arm) <david@xxxxxxxxxx>