A Linux 7.4 Fix Cuts One Early-Boot Operation From 268 Seconds to 50 Milliseconds
Among the roughly 19,700 commits in the 7.4 merge window, one changelog entry stands out: an early-boot memblock operation that went from about 268 seconds to roughly 50 milliseconds.
Four and a half minutes to one twentieth of a second. It reads like a typo.
What memblock does
memblock is the allocator the kernel uses before the normal page allocator exists. During early boot there is no kmalloc, no slab, no page tables in their final form. Something still has to track which physical memory regions are usable, which are reserved by firmware, and which belong to devices.
That something is memblock: a pair of simple arrays of memory regions, with operations to add, reserve and remove ranges. Simple structures are the right choice when nothing more sophisticated is available yet.
The cost of simple structures is that some operations are quadratic in the number of regions.
Why it took this long to matter
On an ordinary machine the firmware hands over a handful of memory regions, and a quadratic operation over a handful of entries is free.
The pathological case needs many regions, which happens with particular firmware memory maps, certain large-memory configurations, and some virtualised setups where memory is presented in many separate chunks. Get into the thousands of regions and the quadratic behaviour becomes the dominant cost of early boot.
Anyone affected experienced it as a machine that appeared to hang for minutes after the bootloader handed off, with no output explaining why. That is a difficult thing to diagnose, because the usual tools do not exist yet at that point in boot. Our boot process guide covers how little is available that early.
The pattern worth taking away
This is a recurring shape in kernel performance work, and it is more instructive than the number itself.
An algorithm is chosen when the input is small. The input grows, for reasons unrelated to that code: more memory, different firmware, a new class of hardware. The algorithm is still correct, so nothing fails and no test breaks. It simply becomes slow on a configuration nobody had when it was written.
The dentry reference counting fix in the same cycle is the same story at a smaller scale: a redundant pair of atomic operations that cost nothing on a four-core machine and 39% of open throughput on a twenty-core one.
Neither fix added a feature. Both removed work that was never needed, which is where a surprising amount of kernel performance improvement comes from.
Whether it affects you
Almost certainly not, unless your boot already takes an unexplained few minutes between the bootloader and the first kernel messages.
# where is your boot time actually going
systemd-analyze
systemd-analyze blame | head -20
systemd-analyze critical-chain
# kernel versus userspace split
systemd-analyze time
If systemd-analyze reports a large kernel time, this class of problem is worth considering. If it reports a large userspace time, the kernel is not your issue and our systemd service guide is a better starting point.