* [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* Re: [PATCH] mm/mm_init: don't subtract managed CMA pages twice
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
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Muchun Song @ 2026-11-19 11:33 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Mike Rapoport, Andrew Morton, Oscar Salvador, linux-mm,
linux-kernel, Chris Mason
> On Nov 19, 2026, at 19:19, David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> 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>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/mm_init: don't subtract managed CMA pages twice
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)
3 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2026-11-19 11:39 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Andrew Morton, Oscar Salvador, Muchun Song, linux-mm,
linux-kernel, Chris Mason
On Thu, Nov 19, 2026 at 12:19:06PM +0100, David Hildenbrand (Arm) wrote:
> 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,
How about I change it to
However, hugetlb may have already initialized its bootmem CMA areas,
when applying?
> 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.
Agree :)
> 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(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/mm_init: don't subtract managed CMA pages twice
2026-11-19 11:39 ` Mike Rapoport
@ 2026-11-19 11:51 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 11:51 UTC (permalink / raw)
To: Mike Rapoport
Cc: Andrew Morton, Oscar Salvador, Muchun Song, linux-mm,
linux-kernel, Chris Mason
On 11/19/26 12:39, Mike Rapoport wrote:
> On Thu, Nov 19, 2026 at 12:19:06PM +0100, David Hildenbrand (Arm) wrote:
>> 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,
>
> How about I change it to
>
> However, hugetlb may have already initialized its bootmem CMA areas,
sure, why not. Thanks!
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm/mm_init: don't subtract managed CMA pages twice
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 13:02 ` Mike Rapoport
2026-11-19 13:04 ` Oscar Salvador (SUSE)
3 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-11-19 13:02 UTC (permalink / raw)
To: Andrew Morton, Oscar Salvador, Muchun Song,
David Hildenbrand (Arm)
Cc: Mike Rapoport, linux-mm, linux-kernel, Chris Mason
From: Mike Rapoport (Microsoft) <rppt@kernel.org>
On Thu, 19 Nov 2026 12:19:06 +0100, David Hildenbrand (Arm) wrote:
> 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.
>
> [...]
Applied to for-next branch of memblock.git tree, thanks!
[1/1] mm/mm_init: don't subtract managed CMA pages twice
commit: 3a348bd13cd3bc5ae6d1f564473f40166cc2009d
tree: https://git.kernel.org/pub/scm/linux/kernel/git/mm/memblock
branch: for-next
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/mm_init: don't subtract managed CMA pages twice
2026-11-19 11:19 [PATCH] mm/mm_init: don't subtract managed CMA pages twice David Hildenbrand (Arm)
` (2 preceding siblings ...)
2026-11-19 13:02 ` Mike Rapoport
@ 2026-11-19 13:04 ` Oscar Salvador (SUSE)
3 siblings, 0 replies; 6+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-11-19 13:04 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Mike Rapoport, Andrew Morton, Oscar Salvador, Muchun Song,
linux-mm, linux-kernel, Chris Mason
On Thu, Nov 19, 2026 at 12:19:06PM +0100, David Hildenbrand (Arm) wrote:
> 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>
Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [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