kho: exclude hugetlb memory from scratch size calculation

HugeTLB pages can be preserved memory. So they are never allocated from
scratch. Instead, they are allocated from the memory blocks with no
preserved memory. These areas are detected at runtime on each boot.

But since they are allocated via memblock, they show up as RSRV_KERN,
and blow up the scratch size when scratch scale is in use.

All hugetlb pages are marked RSRV_HUGETLB. Subtract their size from
RSRV_KERN when calculating scratch sizes.

Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Link: https://patch.msgid.link/20260801084833.1897543-23-pratyush@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
This commit is contained in:
Pratyush Yadav (Google) 2026-08-01 10:48:31 +02:00 committed by Mike Rapoport (Microsoft)
parent c9b7ec87e3
commit fdd843f2be

View File

@ -744,19 +744,24 @@ early_param("kho_scratch", kho_parse_scratch_size);
static void __init scratch_size_update(void)
{
/*
* If fixed sizes are not provided via command line, calculate them
* now.
* If fixed sizes are not provided via command line, calculate them now.
* Remove HugeTLB allocations from it because they never get allocated
* from scratch.
*/
if (scratch_scale) {
phys_addr_t size;
size = memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT,
NUMA_NO_NODE);
size -= memblock_reserved_hugetlb_size(ARCH_LOW_ADDRESS_LIMIT,
NUMA_NO_NODE);
size = size * scratch_scale / 100;
scratch_size_lowmem = size;
size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE,
NUMA_NO_NODE);
size -= memblock_reserved_hugetlb_size(MEMBLOCK_ALLOC_ANYWHERE,
NUMA_NO_NODE);
size = size * scratch_scale / 100 - scratch_size_lowmem;
scratch_size_global = size;
}
@ -776,6 +781,9 @@ static phys_addr_t __init scratch_size_node(int nid)
if (scratch_scale) {
size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE,
nid);
/* Do not count HugeTLB pages. */
size -= memblock_reserved_hugetlb_size(MEMBLOCK_ALLOC_ANYWHERE,
nid);
size = size * scratch_scale / 100;
} else {
size = scratch_size_pernode;