Skip to content

qemu: 0009, the vmlinux copied into guest RAM beside the main loop (#698) - #706

Closed
aledbf wants to merge 2 commits into
mainfrom
qemu-698-rom-copy-beside
Closed

aledbf wants to merge 2 commits into
mainfrom
qemu-698-rom-copy-beside

Conversation

@aledbf

@aledbf aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member

Why

The goal is a cold boot to the first SSH login in under 100 ms. Since #645 QEMU loads the release's vmlinux for PVH, and #698 asked what that load costs QEMU's start.

load_elf already maps the file. Upstream has done that since QEMU 4.2 (816b9fe450, Garzarella, 2019), so mapping it, the change #646 made for the bzImage, was not left to do. What is left is the machine's first reset. It copies the 37.4 MB of segments from the mapping into guest RAM on the main thread, and the monitor answers nothing until the copy is done. Traced on the bench, the copy took 9.1 ms p50 (p95 9.3, 20 boots, lab 45257214350, with a probe on branch exp/698-romcopy that is never merged). #697's ledger read the vmlinux's QEMU start at +8.4 ms over a bzImage's (lab 45260129735).

What

  • qemu/patches/0009: at the first reset, before any vCPU has run, the ELF segments that lie wholly in one RAM region are copied in a rom-copy thread. QEMU waits for the thread before the vCPUs start (a VM state handler that runs first), before a migration's setup, before the next reset (a snapshot load begins with one) and at exit. A machine made for an incoming migration copies nothing at reset, as before. Later resets copy on the main thread, as before.
  • qemu/Dockerfile: a held TCG machine with named threads is given a 256 MiB stub ELF, and the build checks that rom-copy appears. The released QEMU fails that check and the patched one passes (laptop, 3 of 3 each).
  • docs/boot-time.md gets the phase row and a carried row with prior art. qemu/README.md gets the row for 0009. docs/log.md gets the dated entry.

Measured

Bench (c8id.4xlarge, nested), spin's shape and login. v20261123.07 against the same release with this QEMU (parts run 45257975711), interleaved:

Δp50 [95%] run
first login, 60 a side −8.6 [−11.0, −4.0], 351 → 342 lab 45260098299
sshd accepting −9.1 [−12.4, −5.9] the same
QEMU's RSS +0.2, within noise the same
restored login, evicted, 40 a side −0.1 [−1.1, +0.7] lab 45260694485
restored login, cached −0.3 [−2.1, +0.9] the same
cold login in the restore run −6.9 [−12.9, −0.8] the same

The gain matches the whole traced copy. The restore does not move, as expected: under -incoming defer the reset copies nothing.

The record

The record does not move. The patch adds no device, property, -machine option or RAM block. boot:record passes on the patched tree (lab 45261567066). A resumed guest keeps its saved kernel: rom_reset still skips every ROM while the machine is in inmigrate, and the thread only starts for the copies it queues.

Caveat

A monitor command that reads guest memory while the machine is held, before its first cont (pmemsave, dump-guest-memory), can see a kernel that is only partly copied. The patch header says so. spin issues neither.

Found along the way: #705 (not-affected). QEMU's load_elf hits SIGFPE on a note segment with p_align 0.

🤖 Generated with Claude Code

)

Since #645 the machine boots its vmlinux through PVH. load_elf has
mapped the file since QEMU 4.2, but the machine's first reset copies its
37.4 MB of segments into guest RAM on the main thread before the monitor
answers: 9.1 ms p50 on the bench (lab 45257214350). 0009 copies them in
a thread at the first reset and waits for it before the vCPUs start, a
migration's setup, the next reset and QEMU's exit.

Bench, spin's shape, against v20261123.07: first login -8.6
[-11.0, -4.0] at 60 a side (lab 45260098299); restored -0.1
[-1.1, +0.7] evicted at 40 (lab 45260694485). boot:record passes on the
patched tree (lab 45261567066). The QEMU build asserts the thread runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/boot-time.md
#	qemu/Dockerfile
#	qemu/README.md
@aledbf

aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Merged main, which dropped QEMU 0007 (#660). The arms measured here carried 0007. It touches only the bzImage path, which a vmlinux boot never takes, and #660 measured taking it back as within noise. So the numbers above stand for the series as it is now (inferred). 0001-0006, 0008 and 0009 apply to 11.2.0-rc0 with --fuzz=0.

@aledbf

aledbf commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Replaced by 710: the branch merged main, which a rebase merge refuses; the same net change as one linear commit on current main, the patch byte-identical; no force-push.

@aledbf aledbf closed this Nov 23, 2026
@aledbf
aledbf deleted the qemu-698-rom-copy-beside branch November 24, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant