mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: Mike Rapoport <rppt@kernel.org>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>,
	kexec@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	David Hildenbrand <david@kernel.org>
Subject: [PATCH 2/2] kho: count bootmem in CmaTotal
Date: Sat, 28 Nov 2026 21:01:51 -0800	[thread overview]
Message-ID: <87b6c744e6413d49872df0ccbc8798c409df51b6.1795928397.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1795928397.git.chris@chrisdown.name>

/proc/meminfo shows totalcma_pages as CmaTotal, but cma_new_area(),
cma_drop_area() and cma_activate_area() only update it for their own
areas. As such, bootmem is never in CmaTotal. Bootmem pageblocks are
MIGRATE_CMA though, so their free pages are in CmaFree, and without any
other CMA areas CmaFree ends up larger than CmaTotal. For example, with
4 GiB over two nodes and kho_bootmem=32M,512M,256M, which is 1056 MiB of
bootmem:

                 cold boot   after KHO kexec
    CmaTotal          0 kB              0 kB
    CmaFree     1071076 kB         988188 kB

Let's add bootmem to totalcma_pages wherever kho_init() adds it to
zone->cma_pages, that is, after init_cma_reserved_pageblock() on a cold
boot, and in kho_account_incoming_bootmem() on a KHO boot. With this
applied, CmaTotal has bootmem accounted correctly after both boots.
This happens long after mem_init_print_info(), so the "Memory:" boot
line doesn't change.

Fixes: 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers")
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 kernel/liveupdate/kexec_handover.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 7cc87338df24..8efef4a37991 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -1886,6 +1886,7 @@ static void __init kho_account_incoming_bootmem(void)
 				continue;
 
 			page_zone(page)->cma_pages += pageblock_nr_pages;
+			totalcma_pages += pageblock_nr_pages;
 		}
 	}
 }
@@ -1950,6 +1951,7 @@ static __init int kho_init(void)
 		for (pfn = base_pfn; pfn < base_pfn + count;
 		     pfn += pageblock_nr_pages)
 			init_cma_reserved_pageblock(pfn_to_page(pfn));
+		totalcma_pages += count;
 	}
 
 	WARN_ON_ONCE(kho_debugfs_blob_add(&kho_out.dbg, "fdt",
-- 
2.56.1


  parent reply	other threads:[~2026-11-29  5:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  5:01 [PATCH 0/2] mm, kho: count KHO bootmem in CmaTotal and in zoneinfo's cma Chris Down
2026-11-29  5:01 ` [PATCH 1/2] kho: count bootmem in zoneinfo's cma after a KHO kexec Chris Down
2026-11-29 19:48   ` Mike Rapoport
2026-11-29  5:01 ` Chris Down [this message]
2026-11-29 19:50   ` [PATCH 2/2] kho: count bootmem in CmaTotal Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87b6c744e6413d49872df0ccbc8798c409df51b6.1795928397.git.chris@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=david@kernel.org \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®