Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/boot-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rule 3).

**The restore is under 100 ms when QEMU is started ahead, and the cold boot is not close.** A
cold boot cannot reach 100 ms by userspace work alone: QEMU, the firmware and the kernel take
~140 ms before PID 1 runs (budget below). Without systemd, sshd accepted at 189 ms in spin's shape
~140 ms before PID 1 runs (budget below), ~150 once two of its clocks are corrected (#665, #666). Without systemd, sshd accepted at 189 ms in spin's shape
(lab 44750322384, 2026-11-20). Every phase before PID 1 has to shrink as well.

### What spin runs, and what the probes boot
Expand Down Expand Up @@ -130,9 +130,9 @@ not a measurement: it says how far each phase has to move.
|---|---|---|---|---|
| QEMU's exec to a guest ready to run | ~28 | cold 456 less the boot into a QEMU started ahead, 428 (report 44811347183) | by difference, one run | 0, started ahead |
| … of it, QMP: QEMU's main loop free to `cont` answered, 14 commands | 6.2 | `transport` `cold_qmp`, lab 44912471522 (v20261121.01); 4.5 of it QEMU waiting on spin-machine's next command | measured | |
| qboot and the bzImage's decompression, to the kernel's clock | 33.6 | `boot:firmware-stages`, lab 44787491631 (v20261120.02's kernel); ~21 of it is the decompression KASLR needs | measured, another run | 5 |
| The kernel's clock to "Freeing unused kernel image" | 79.9 | report 44811347183 | measured | 25 |
| PID 1 to sshd accepting | ~255 | sshd accepts 396 (lab 44841266997) less the three rows above | by difference, across runs | 35 |
| qboot and the bzImage's decompression, to the kernel's clock | 33.6 | `boot:firmware-stages`, lab 44787491631 (v20261120.02's kernel); ~21 of it is the decompression KASLR needs. Its end, KVM_SET_CLOCK plus the sched offset, is 2.8 ms after the kernel's 0 on bench, so ~31 (#665) | measured, another run; its anchor late | 5 |
| The kernel's clock to "Freeing unused kernel image" | 79.9 | report 44811347183, on dmesg's clock, which from late_initcall on is 13-15 ms behind the kernel's on bench, so ~93 (#666) | measured on a clock that reads short | 25 |
| PID 1 to sshd accepting | ~255 | sshd accepts 396 (lab 44841266997) less the three rows above; ~244 with the two corrections above | by difference, across runs | 35 |
| sshd's accept to the first login | 68.4 | `ssh-first` `accept_to_login`, lab 44841266997 | measured | 35 |
| … of it, what any login costs (a second login) | 35.9 | `ssh-first` `second_login`, the same | measured | |
| … of a login, vsock: 10 round trips of 57.5 µs through the forwarder | 0.6 | `transport` `login_turns`, `forward_rtt`, lab 44912471522 | measured | |
Expand All @@ -141,7 +141,7 @@ not a measurement: it says how far each phase has to move.
**PID 1 to sshd is more than half the cold boot.** On one vCPU, everything systemd starts before
sshd accepts is on the login's path. The groups in "What the machine carries" show how much
masks, generators and the coldplug filter took off it. The no-systemd floor accepted at 189 ms in
spin's shape. Before PID 1, ~140 ms of QEMU, firmware and kernel remain, ~113 of them with QEMU
spin's shape. Before PID 1, ~140 ms of QEMU, firmware and kernel remain (~150 corrected, #665, #666), ~113 of them with QEMU
started ahead. Each phase from the first row to the fourth has to shrink to reach 100 ms.

### Restore, QEMU started ahead
Expand Down Expand Up @@ -485,7 +485,7 @@ The rows are ranked by ceiling. A row stays here until it is decided, and then m
| A workspace's cgroup at a higher `cpu.weight` while it boots or restores, on a busy host (spin's runner owns the cgroup) | restore, as a busy host sees it | with 16 workspaces keeping the 16 CPUs busy, the restored first login is 306 ms against 115 idle, and QEMU's threads wait 282 ms for a CPU (lab 44925573288). The same weight ratio as QEMU at nice −10, set as the crowd at nice 10: restored −79.3 [−93.5, −71.0], cold −104.7 [−258.3, +150.9], within noise (lab 44927312303) | spin's `restore-together` or a crowd on its runner, with the weight raised through the workspace's cgroup and set back after the login, against without it | a proposal for spin. Measured in one cgroup, where each thread competes alone. In spin each workspace is a cgroup, and the weight is shared by its threads. The idle host has nothing to win (Measured and rejected, "Memory and the host") |
| journald's, logind's and `user@`'s seccomp and sandbox settings emptied: `SystemCallFilter=`, `Restrict*=`, `Protect*=`, `MemoryDenyWriteExecute=`, `LockPersonality=` (#574, experiment 4, a bound) | cold | the executors' CPU before the login: journald 6.0, logind 10.3, `user@0` 2.8 ms, p50 of 5 ledgers (lab 45120692382) | the bound read first login −14.1 [−18.5, −11.5], sshd accepting −13.2 [−16.0, −10.9] at 60 a side (lab 45121038332). Next: split it into its seccomp and namespace halves, then one seccomp filter per unit in systemd, which keeps the function (#637) | open, #637. A bound and never a candidate: the settings are function |
| The restore with more than 2 GiB of RAM | restore | unmeasured (#242's checklist) | `restore-first` with `plugged` above 2048 | open |
| A workspace's 2048 MiB at boot (`memory=2048 plugged=0`) instead of 128 plugged to 2048 through virtio-mem during the boot (#561) | cold | the plug and the onlining of 2048 MiB on the one vCPU while the boot runs; separate runs read −15 nested and −8 metal (v20261122.06, labs 45074465204, 45074579100, 45074680619, 45078339515), so the ceiling is ~15 ms. Prior art: the kernel onlines hotplugged memory strictly in sequence, one memory block after another, and deferred struct page init, which spreads the boot's own memory over threads, does not apply to it (David Hildenbrand on linux-mm, [lore](https://lore.kernel.org/linux-mm/87v9disj2s.fsf@oracle.com/T/)). Squeezy (arXiv 2411.12893, 2024) measured virtio-mem's operations in seconds at GiB sizes and found init_on_free slows a plug. Neither measured a boot. The kernel has init_on_alloc and init_on_free off | `ssh-first`, the two shapes as two trees of one run (`--opt` on a tree), 40 a side on bench and on bench-metal, `restore-first` beside them; 3 ledgers of each shape for the onlining's CPU | a proposal for spin, spin-stack/spin#1660. Measured as two trees of one run (v20261123.04, spin's login): cold first login −5.5 [−10.9, −0.7] nested at 80 a side (lab 45111507862; −2.5 [−7.3, +2.0] at 40, lab 45110554589), −7.0 [−11.4, −3.4] on metal at 40 (lab 45110570912); restored login −2.5 [−3.7, −1.0], the state −17.6 MiB, QEMU's RSS −26 MiB (labs 45110562994, 45111507862). The ledger (lab 45110580480, 3 boots each) shows `kworker/0:1` on the vCPU ~8 ms before PID 1 when plugged and not at all when the memory is at boot, which costs the kernel's own setup ~4.5 ms more: PID 1 −3.4 ms. The probes keep spin's shape until spin changes it |
| A workspace's 2048 MiB at boot (`memory=2048 plugged=0`) instead of 128 plugged to 2048 through virtio-mem during the boot (#561) | cold | the plug and the onlining of 2048 MiB on the one vCPU while the boot runs; separate runs read −15 nested and −8 metal (v20261122.06, labs 45074465204, 45074579100, 45074680619, 45078339515), so the ceiling is ~15 ms. Prior art: the kernel onlines hotplugged memory strictly in sequence, one memory block after another, and deferred struct page init, which spreads the boot's own memory over threads, does not apply to it (David Hildenbrand on linux-mm, [lore](https://lore.kernel.org/linux-mm/87v9disj2s.fsf@oracle.com/T/)). Squeezy (arXiv 2411.12893, 2024) measured virtio-mem's operations in seconds at GiB sizes and found init_on_free slows a plug. Neither measured a boot. The kernel has init_on_alloc and init_on_free off | `ssh-first`, the two shapes as two trees of one run (`--opt` on a tree), 40 a side on bench and on bench-metal, `restore-first` beside them; 3 ledgers of each shape for the onlining's CPU | a proposal for spin, spin-stack/spin#1660. Measured as two trees of one run (v20261123.04, spin's login): cold first login −5.5 [−10.9, −0.7] nested at 80 a side (lab 45111507862; −2.5 [−7.3, +2.0] at 40, lab 45110554589), −7.0 [−11.4, −3.4] on metal at 40 (lab 45110570912); restored login −2.5 [−3.7, −1.0], the state −17.6 MiB, QEMU's RSS −26 MiB (labs 45110562994, 45111507862). The ledger (lab 45110580480, 3 boots each) shows `kworker/0:1` on the vCPU ~8 ms before PID 1 when plugged and not at all when the memory is at boot, which costs the kernel's own setup ~4.5 ms more: PID 1 −4.0 ms on the kernel's clock (−3.4 on CLOCK_MONOTONIC, before #644). The probes keep spin's shape until spin changes it |

The floor is a bound and never a candidate: systemd stays (AGENTS.md, "What must not break").

Expand Down
2 changes: 1 addition & 1 deletion docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ idle CPU and IO classes), since it reports on a guest whose CPU may be what is s
because a trigger with a window under 2 s is root's alone. Out of the OOM killer's way
(`OOMScoreAdjust=-900`), which otherwise took it in the OOM it was reporting (`task boot:pressure`,
2026-11-21); it holds a few MiB. Started with `multi-user.target`, which `spin-machine-boot-rest.service` starts
once the first login's units are up (#581): in a ledger of spin's shape it started at 0.37-0.38 s
once the first login's units are up (#581): in a ledger of spin's shape it started at 0.39-0.40 s
on the kernel's clock, after the login (lab 45120692382, 5 boots). Moving it there from a timer 10 s
after the boot moved neither number: bench, spin's shape and login, 20 a side against v20261123.04,
first login −0.8 [−7.8, +4.8] (lab 45120950183), restored −0.8 [−2.9, +2.1] evicted and −0.4
Expand Down
2 changes: 2 additions & 0 deletions docs/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ Checked against the probe it replaced on the bench fleet, `lab dispatch ssh-firs
**11-23 · image · the dynamic linker's share of PID 1, journald, logind and `user@0` is ~1 ms (labs 45180400607, 45180856158, #638, this change).** #574's runner-up: the four map and relocate `libsystemd-shared` (PID 1 and `user@0` also `libsystemd-core`), and nobody had measured ld.so's share before porting to v262's multicall build (#42304) or a static one (#42820). *Instrument* (branch `exp-ldso`, tagged `archive/exp-ldso`, its `ldso` edit): `LD_DEBUG=statistics` for PID 1 from spin's handoff, which execs it (`systemd.setenv=` does not reach PID 1), and for journald, logind and `user@0` from a drop-in each. PID 1 and journald report on `/dev/kmsg` with `printk.devkmsg=on`, logind and `user@0` on their stderr, the journal: the first run had logind's on `/dev/kmsg` too, its `DevicePolicy=` refused the executor the open, and logind failed at STDERR (lab 45180400607, discarded). glibc 2.43 counts in TSC cycles, 2700 MHz in every boot. *Measured* (bench, nested, spin's shape and login, v20261123.05 on its traceable kernel, the ledger with and without the edit, 8 a side, lab 45180856158), ld.so's total start-up, p50 [range]: PID 1 0.48 [0.46, 0.56] ms, of it loading objects 0.32 and relocation 0.08; journald 0.20 [0.14, 0.31]; logind 0.20 [0.11, 0.31]; `user@0` 0.21 [0.15, 0.36]. Relocations: PID 1 and `user@0` 2,522 symbol (911 from cache) and 16,589 relative; journald 1,157 and 10,518; logind 1,238 and 11,297. Objects at start, from the release's image (`ldd`): 7 for PID 1 and `user@0` (the binary, libsystemd-core, libsystemd-shared, libc, libm, libcrypt, ld.so), 6 for journald and logind, all `BIND_NOW`. The four come to ~1.1 ms, under #638's ~5 ms, so no build was made. *The instrument:* against the ledger alone in the same run, first login +3.4 [−23.0, +11.9], PID 1's CPU −1.1 [−5.1, +0.6], unattributed +0.3 [−0.1, +1.1]; each ld.so total is well inside the trace's wall time from the process's exec to its first sleep. It does not see the kernel's execve before ld.so runs, nor the libraries' pages faulted in later by `main`, which a static build would partly pay too (not measured). `user@0`'s environment generator inherits the variable and reports 0.13 ms more. *Inferred:* the multicall build would not reach even that: it keeps libsystemd-core and libsystemd-shared dynamic, leaves journald and logind alone and makes the executor, static here, dynamic. *Status:* measured and rejected; #638 closed.
**11-23 · qemu · a bzImage mapped, not read into QEMU's heap (#646, labs 45182382388, 45182382864, 45183618987, this change).** `x86_load_linux` read the whole 16.7 MB bzImage into a buffer that only fw_cfg reads, 6.2-6.9 ms of QEMU's init traced (labs 45177818419, 45177817516, #611), and qboot copies the same bytes again by fw_cfg DMA. `qemu/patches/0007` maps the file read-only (`g_mapped_file_new_from_fd`), as upstream has mapped the initrd since 4.2; a kernel with a dtb appended keeps its buffer. The setup header QEMU patches is already a copy of its own, so nothing writes to the mapping. The QEMU build asserts that a held TCG machine's maps name a stub bzImage given to it; the published QEMU fails that check. *Prior art* is in docs/boot-time.md's row: Garzarella's 2019 series mapped the ELF kernel and the initrd but not the bzImage. *Measured* (bench, nested, spin's shape and login, v20261123.05 against the same release with the patched QEMU, parts run 45180746171, 40 a side, interleaved): first login 380 → 367, −13.4 [−16.9, −7.3], sshd accepting −13.3 [−18.7, −7.5], the console prompt −10.6 [−14.2, −6.3]; QEMU's anonymous RSS −15.9 MiB and its file RSS +16.1, total unmoved (lab 45182382388). Restored, 40 a side: login −9.3 [−11.2, −6.1] evicted and −7.7 [−8.9, −5.1] cached, `running` −8.8 and −7.9, the state unmoved (lab 45182382864): a restore starts QEMU, which loads the kernel into fw_cfg there too. The gain is twice the traced read; what else the anonymous buffer cost nested (its page faults, presumably) was not measured. *A lead, not a decision:* an uncompressed payload (#326's kernel patch, renumbered, branch `exp/646-uncompressed`, parts run 45180892535) against LZ4, both on the patched QEMU: first login −4.0 [−7.9, +0.3], within noise at 40, QEMU's RSS +32 MiB (lab 45183618987). The mapping removes the "+6-7 in QEMU's start" half of #326's rejection; whether the rest is a gain needs more boots, which is #645's. *Status:* in place; the record does not move, as the kernel reaches the guest through fw_cfg.

**11-23 · lab · the ledger's kernel_zero on the kernel's sched clock (#644, labs 45229897350, 45230233764, this change).** The ledger's `kernel_zero` landed 19.5 ms (bench) and 12.6 ms (metal) after a port write at the sched clock's 0 (#611). *Found:* the ledger took CLOCK_MONOTONIC's 0, the trace's clock, for the kernel's. CLOCK_MONOTONIC runs on jiffies from timekeeping_init until the switch to kvm-clock and loses the ticks it misses. The kernel prints both clocks at one tick at late_initcall ("sched_clock: Marking stable"), and their difference was the whole error in all 24 boots of labs 45177818419 and 45177817516, to within 0.15 ms. *Changed:* the ledger moves the trace and the journal forward by that lag (`monotonic_lag`, 18-25 ms nested, 11-14 metal) and refuses a journal without the line. *Checked:* with the marker kernel, `kernel_zero` lands 0.03 to 0.14 ms before QEMU's trace stamps the marker, 10 boots on bench and 10 on metal (spin's shape, v20261123.04). *What moved*, recomputed from the runs' kept journals: docs/measuring.md's split of lab 45110630795, `kernel_zero` 97-114 → 77-95 and `qemu_start` 49.4 → 29.3 (`before_qemu` and `guest_to_zero` do not move); QEMU's exec to the kernel's clock untraced on the workspace's machine is 73.4 ms on bench and 68.7 on metal (labs 45177818419, 45177817516), against firmware-stages' 73.7; PID 1 in #561's ledgers −3.4 → −4.0 ms; the pressure sender's start 0.37-0.38 → 0.39-0.40 s (docs/image.md). #611's comment is corrected. No cold-budget row used the ledger's anchor. Two of its rows use clocks with errors of their own, now noted beside them: firmware-stages' anchor is ~2.8 ms late on bench (#665), and dmesg's clock reads the kernel 13-15 ms short from late_initcall on (#666). *Status:* in place.

## 2. Rework cycles

Each cycle: the sequence, what each step measured, and the lesson.
Expand Down
Loading