From: Ayubjon Qosimov reserve_memblock_reserved_regions() adds a "reserved" child under each standard memory resource for every memblock.reserved range it overlaps, and each insertion walks the parent's child list from its head, so n ranges cost O(n^2). After a kexec with Kexec HandOver (KHO) that preserves many separate pages, for example memfd or vmalloc memory preserved through the Live Update Orchestrator, there are thousands of such ranges, and on a host that is live updated this way the initcall adds directly to the time the guests are paused. Use reserve_memblock_reserved_resources(), which does the same under one hold of resource_lock and with a hint per memory resource, so the insertions cost O(n). The resulting resource tree is unchanged. Measured in a 96-vCPU KVM guest on a Graviton4 host, standing in for a large host, in the kernel booted by a KHO kexec, with lib/test_kho.c changed locally to preserve order-0 pages with a free page between each (the stock test preserves large folios that merge into a few ranges). The time is the gap between the initcall_debug "calling" and "returned" lines for reserve_memblock_reserved_regions(), min-max over the boots: ranges before after boots 3223 11.9-12.3 ms 0.17-0.18 ms 5 /proc/iomem is unchanged except for ranges that also move between two boots of the same kernel. Signed-off-by: Ayubjon Qosimov --- arch/arm64/kernel/setup.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index a707deba6ae7..af16e68ab0f9 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -245,28 +245,8 @@ static void __init request_standard_resources(void) static int __init reserve_memblock_reserved_regions(void) { - u64 i, j; - - for (i = 0; i < num_standard_resources; ++i) { - struct resource *mem = &standard_resources[i]; - phys_addr_t r_start, r_end, mem_size = resource_size(mem); - - if (!memblock_is_region_reserved(mem->start, mem_size)) - continue; - - for_each_reserved_mem_range(j, &r_start, &r_end) { - resource_size_t start, end; - - start = max(PFN_PHYS(PFN_DOWN(r_start)), mem->start); - end = min(PFN_PHYS(PFN_UP(r_end)) - 1, mem->end); - - if (start > mem->end || end < mem->start) - continue; - - reserve_region_with_split(mem, start, end, "reserved"); - } - } - + reserve_memblock_reserved_resources(standard_resources, + num_standard_resources, "reserved"); return 0; } arch_initcall(reserve_memblock_reserved_regions); -- 2.47.3