[PATCH v2 2/2] kho: count bootmem in CmaTotal

From: Chris Down

Date: Sun Nov 29 2026 - 23:19:37 EST


/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 1070844 kB 998984 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. This happens
long after mem_init_print_info(), so the "Memory:" boot line doesn't
change.

With this applied, CmaTotal has bootmem accounted correctly after both
boots:

cold boot after KHO kexec
CmaTotal 1081344 kB 1081344 kB
CmaFree 1063116 kB 983884 kB

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

diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
index ac9f101b00b8..15fb892a4412 100644
--- a/kernel/liveupdate/kho_core.c
+++ b/kernel/liveupdate/kho_core.c
@@ -1890,6 +1890,7 @@ static void __init kho_account_incoming_bootmem(void)
continue;

page_zone(page)->cma_pages += pageblock_nr_pages;
+ totalcma_pages += pageblock_nr_pages;
}
}
}
@@ -1949,6 +1950,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