[PATCH 0/5] Mirror reserved memblock regions in linear time

From: Ayubjon Qosimov via B4 Relay

Date: Fri Dec 04 2026 - 10:29:36 EST


arm64, riscv and LoongArch each mirror memblock.reserved into
/proc/iomem at arch_initcall time with reserve_region_with_split(), once
per reserved range. Every insertion walks the parent's child list from
its head, so n ranges cost O(n^2). x86 is not affected: it reports the
e820 map in /proc/iomem, not memblock.reserved.

This matters once there are many reserved ranges, as in the kernel
booted by a kexec with Kexec HandOver (KHO). KHO reserves every
preserved folio separately, and memory preserved through the Live Update
Orchestrator, such as memfd/shmem folios or vmalloc pages, is scattered,
so the ranges do not merge. A host that preserves guest memory through
LUO ends up with about 3200 reserved ranges after each kexec, and this
initcall then takes 12 ms, which adds directly to the time the guests
are paused during a live update.

Patch 1 adds reserve_memblock_reserved_resources(), one helper for the
three architectures. It holds resource_lock once for the whole array of
memory resources and walks memblock.reserved for each of them with a
hint, so each insertion resumes at the child inserted or hit last: n
ranges cost O(n) insertions instead of O(n^2). The children it skips all
end below the new range, so the tree is identical. Patch 2 adds KUnit
cases that build the same tree with and without the hint, and compare
the helper with the old loop on a memblock table of their own. Patches
3-5 switch the architectures over. /proc/iomem is unchanged; dropping or
merging the KHO ranges there would be a visible change and can be
discussed separately.

The series is based on mm-new as of 2026-12-01. Patches 3-5 depend on
patch 1, so I'd suggest it goes through Andrew's tree (mm-nonmm), with
acks from the arch maintainers.

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. To get disjoint
reserved ranges, lib/test_kho.c was changed locally to preserve order-0
pages at fixed addresses with a free page between each (the stock test
preserves large folios that merge into a few ranges); that change is not
part of the series. 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 with and without the series is unchanged except for ranges
that also move between two boots of the same kernel.

Testing: the KUnit cases pass under UML and under arm64 QEMU with 4K,
16K and 64K pages. arm64 and x86_64 defconfig kernels build with no W=1
warnings in the touched files. riscv and LoongArch defconfig kernels
boot in QEMU with an unchanged /proc/iomem apart from the kernel image
size; those boots have few reserved ranges, so they only show that
nothing regressed.

Signed-off-by: Ayubjon Qosimov <ayubjon@xxxxxxxxx>
---
Ayubjon Qosimov (5):
resource: add reserve_memblock_reserved_resources()
resource, kunit: add test cases for reserve_memblock_reserved_resources()
arm64: Use reserve_memblock_reserved_resources()
riscv: use reserve_memblock_reserved_resources()
LoongArch: Use reserve_memblock_reserved_resources()

arch/arm64/kernel/setup.c | 24 +---
arch/loongarch/kernel/setup.c | 24 +---
arch/riscv/kernel/setup.c | 24 +---
include/linux/ioport.h | 2 +
kernel/resource.c | 96 +++++++++++++++-
kernel/resource_internal.h | 18 +++
kernel/resource_kunit.c | 254 ++++++++++++++++++++++++++++++++++++++++++
7 files changed, 370 insertions(+), 72 deletions(-)
---
base-commit: 1a7610248a3802e38124ce66b07eef12277be9a0
change-id: 20261204-b4-iomem-ev5-2e4483a4d290

Best regards,
--
Ayubjon Qosimov <ayubjon@xxxxxxxxx>