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>,
sashiko-bot@kernel.org
Subject: [PATCH v2 1/2] kho: count bootmem in zoneinfo's cma after a KHO kexec
Date: Sun, 29 Nov 2026 20:19:25 -0800 [thread overview]
Message-ID: <a8ad9cbfe08caa2005a25ca50985ec6723e38fc8.1796006500.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1796006500.git.chris@chrisdown.name>
On a cold boot, kho_init() releases bootmem to the buddy allocator with
init_cma_reserved_pageblock(), which adds each pageblock to
zone->cma_pages.
A KHO boot takes a different path, because bootmem isn't reserved in
memblock:
1. kho_bootmem_migratetype() makes its pageblocks MIGRATE_CMA during
memmap init.
2. memblock_free_all() releases the free pages.
3. kho_init() bypasses bootmem initialisation.
Nothing adds bootmem to zone->cma_pages, so the cma line in
/proc/zoneinfo goes to 0 after a KHO kexec, even though the memory is
still MIGRATE_CMA and its free pages are still counted in CmaFree. For
example, with 4 GiB over two nodes and kho_bootmem=32M,512M,256M, in
pages:
cold boot after KHO kexec
Node 0, DMA32 65536 0
Node 1, DMA32 8192 0
Node 1, Normal 196608 0
zone->cma_pages is also what the auto-movable memory onlining policy
treats as movable memory, so after a KHO kexec it counts bootmem as
kernel memory instead.
Let's count the MIGRATE_CMA pageblocks in bootmem from kho_init() on a
KHO boot. With this applied, the cma line after a KHO kexec matches the
cold boot:
cold boot after KHO kexec
Node 0, DMA32 65536 65536
Node 1, DMA32 8192 8192
Node 1, Normal 196608 196608
You might wonder why we don't count pageblocks as they are made
MIGRATE_CMA in pageblock_migratetype_init_range() and
__init_deferred_page(). The reason is that, with deferred struct page
init, __init_deferred_page() makes bootmem MIGRATE_CMA on a cold boot
too, where init_cma_reserved_pageblock() then counts it again.
deferred_free_pages() also runs in several padata threads at once, which
would race on the counter.
Fixes: c609c144b0e8 ("kexec: add KHO parsing support")
Signed-off-by: Chris Down <chris@chrisdown.name>
---
kernel/liveupdate/kho_core.c | 37 ++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
index bbc0a0ac682b..ac9f101b00b8 100644
--- a/kernel/liveupdate/kho_core.c
+++ b/kernel/liveupdate/kho_core.c
@@ -1860,12 +1860,49 @@ static int __init kho_kexec_metadata_init(const void *fdt)
return err;
}
+static int __init kho_cma_area_intersects(struct cma *cma, void *data)
+{
+ phys_addr_t start = *(phys_addr_t *)data;
+
+ return cma_intersects(cma, start,
+ start + pageblock_nr_pages * PAGE_SIZE - 1);
+}
+
+static void __init kho_account_incoming_bootmem(void)
+{
+ for (int i = 0; i < kho_bootmem_cnt; i++) {
+ unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr);
+ unsigned long count = kho_bootmem[i].size >> PAGE_SHIFT;
+ unsigned long pfn;
+
+ for (pfn = base_pfn; pfn < base_pfn + count;
+ pfn += pageblock_nr_pages) {
+ struct page *page = pfn_to_page(pfn);
+ phys_addr_t start = PFN_PHYS(pfn);
+
+ if (!is_migrate_cma_page(page))
+ continue;
+ /*
+ * A KHO boot can reserve CMA areas inside bootmem, and
+ * those are already counted as part of their CMA area.
+ */
+ if (cma_for_each_area(kho_cma_area_intersects, &start))
+ continue;
+
+ page_zone(page)->cma_pages += pageblock_nr_pages;
+ }
+ }
+}
+
static __init int kho_init(void)
{
struct kho_radix_tree *tree = &kho_out.radix_tree;
const void *fdt = kho_get_fdt();
int err = 0;
+ if (is_kho_boot())
+ kho_account_incoming_bootmem();
+
if (!kho_enable)
return 0;
--
2.56.1
next prev parent reply other threads:[~2026-11-30 4:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 4:19 [PATCH v2 0/2] mm, kho: count KHO bootmem in CmaTotal and in zoneinfo's cma Chris Down
2026-11-30 4:19 ` Chris Down [this message]
2026-11-30 4:19 ` [PATCH v2 2/2] kho: count bootmem in CmaTotal Chris Down
2026-11-30 7:49 ` [PATCH v2 0/2] mm, kho: count KHO bootmem in CmaTotal and in zoneinfo's cma 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=a8ad9cbfe08caa2005a25ca50985ec6723e38fc8.1796006500.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 \
--cc=sashiko-bot@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®