Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/mm_init: don't subtract managed CMA pages twice
@ 2026-11-19 11:19 David Hildenbrand (Arm)
  2026-11-19 11:33 ` Muchun Song
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 11:19 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, Oscar Salvador, Muchun Song
  Cc: linux-mm, linux-kernel, Chris Mason, David Hildenbrand (Arm)

From: Chris Mason <mason@kernel.org>

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@kernel.org>
[ david: improve description and comment ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
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@kernel.org>



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-19 13:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 11:19 [PATCH] mm/mm_init: don't subtract managed CMA pages twice David Hildenbrand (Arm)
2026-11-19 11:33 ` Muchun Song
2026-11-19 11:39 ` Mike Rapoport
2026-11-19 11:51   ` David Hildenbrand (Arm)
2026-11-19 13:02 ` Mike Rapoport
2026-11-19 13:04 ` Oscar Salvador (SUSE)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox