Skip to content

X02 - Warm start

Purpose: How long a macOS guest takes to restore from saved state with a vsock device and a file-handle network attachment, and whether one saved state can be restored more than once.

Brief: B16-warm-startB16-warm-start: How fast does a suspended VM come back, and can one saved state be restored more than once?Yes, with conditions.

From X00-indexX00-index: SpikesThe open questions that must be answered by a throwaway prototype before work builds on them, in the order they are taken up.: measure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment. Can a saved state be reused (cloned with its disks) more than once?

Yes, with conditions. The configuration that S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does. describes passes validateSaveRestoreSupport, saves in about 3 s at 4 GiB, and restores to a guest that answers on the network in 3.7 s (p50) and 3.9 s (p95) when the state file is not in the host’s page cache. One saved state was restored 30 times from fresh clones. Every restore worked that kept the saved identity while no other VM with that identity ran (conditions 2 and 3). The conditions:

  1. A fresh clone for every restore. Virtualization does not check that the disks match the state. A state restored a second time onto disks the guest had already run from for 10 s came up and ran without an error, so the guest’s memory can be older than its disks and nothing reports it. A state is only restored onto the disks it was saved with, or onto APFS clones of them taken together with the state.
  2. The same identity. A restore with a different machine identifier, or with a different MAC address on the network device, fails with “invalid argument”.
  3. One running VM per identity during a restore. A restore fails while another VM with the same machine identifier runs: 4 failures in 4 tries. Three of the tries were pairs of concurrent restores of one state, where one restore of each pair failed. The fourth was a restore next to a cold-booted VM with the same identifier. Cold boots of two clones that share an identifier both run, and clones of states with different identifiers restore side by side. The work VM and the isolated VM have their own identities, so this does not affect S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.’s two slots.
  4. The host must be unlocked to save. The save file is encrypted with a key that Virtualization creates in the Secure Enclave when it saves, with the access class “only while unlocked, only on this device”. With the screen locked, the save failed with “permission denied”, and the log shows the key creation refused (errSecInteractionNotAllowed). After an unlock, the same binary on the same bundle saved 21 times without an error. The error text and the lock state are in results/save-locked-run.md on the spike branch. That run’s own output file was overwritten by the run after the unlock, so the error text there is transcribed from the session.
  5. Bound to the host. Apple’s header for restoreMachineStateFromURL says the file must have been written on the same host, and that a restore can fail after a host software update. A saved state can’t be part of an image or move between machines. A restore that fails for one of these reasons deletes the state and cold boots. A host update gives “invalid argument” according to Apple’s VZVirtualMachine.h, which this spike didn’t test. An identifier in use gives the same error, as measured under condition 3. The host tells the two apart by whether a VM with that identifier runs.

Host: Apple M2, 8 cores, 16 GB, macOS 27.0.1. Guest: macOS 27.0.1 (26A434), installed from Apple’s restore image and left at Setup Assistant. 4 vCPU, a 64 GiB system disk and an 8 GiB data disk (both sparse), VZVirtioSocketDevice, VZFileHandleNetworkDeviceAttachment on a datagram socket pair, entropy, one display. 20 runs per row.

“Answering” is the guest kernel replying to an ICMPv6 echo that the host writes into the file-handle attachment. The clock starts before the VZVirtualMachine is created, so restore times include building the configuration (7 to 15 ms) and resume (about 120 ms). “Fresh clone” means the bundle was APFS-cloned just before the run, so its files are not in the host page cache, which is the case after an idle period.

Measurement 4 GiB p50 4 GiB p95 8 GiB p50 8 GiB p95
Restore to answering, fresh clone 3.71 s 3.92 s 4.11 s 4.58 s
Restore to answering, state just saved 1.97 s 2.02 s 2.39 s 2.47 s
Cold boot to answering, fresh clone 5.04 s 5.38 s
Cold boot to answering, same files 4.76 s 5.08 s 5.02 s 5.92 s
pause 7 ms 13 ms 7 ms 16 ms
saveMachineStateTo 2.94 s 3.20 s 4.78 s 5.16 s
Saved state size 1.41 GB 1.41 GB 1.41 GB 1.41 GB
  • The state file holds the memory the guest has used, not the memory it was given: 1.41 GB at both 4 and 8 GiB for an idle guest. A guest running Claude Code and builds writes a larger file and restores more slowly.
  • The network is back the moment the guest runs: the first echo reply comes within 11 ms of resume, on a new socket pair that the host passes in the configuration of the restored VM.
  • A cold boot first answers at about 5 s, the moment the guest’s DHCP client also starts. That is early in boot: the rest of the guest’s startup still runs after it. A restore saves about 1.3 s at that point, and the guest it returns has finished starting up.
  • Concurrent restores of clones of two different states (4 GiB each) took about 5 s each.
  • Installing macOS from the restore image took 256 s. The system disk then used 26 GiB.

A guest process answering on vsock. Nothing in a stock guest listens on vsock: 60 s after boot, connects to all 65535 ports were refused. Getting a listener into the guest means writing it to the guest’s disk from the host, which B44-data-disk-durabilityB44-data-disk-durability: What may the host do with a guest's disks, and how much of the data disk may a crash lose?Write a new security control now that the host never mounts or parses a disk after the guest has booted from it. allows only before the image’s first boot, or going through Setup Assistant by hand, which needs the maintainer.

This spike wrote such a host-side injector: guest/inject.sh on spike/x02-warm-start at commit 2abe903. It was meant to attach the guest’s system disk image with hdiutil attach, mount the guest’s Data volume with diskutil mount, and copy the probe and a LaunchDaemon into it. The permission check of the agent’s session blocked it before it ran, and commit 4979ba1 removed it. No guest disk was mounted.

X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM? answers how wb-guestd gets into the guest, and X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest? already tests vsock connections across save and restore (its step 4), so the time from restore to wb-guestd answering is measured there.

A vsock connect from the host to an unbound port is refused within 30 ms of start, before the guest kernel has booted. The refusal comes from the host side of the device, so it says nothing about the guest.

Restore while the host is locked, and restore after a host restart or a host update. Restore while locked is assumed to fail as saving does, measured since in X18-vsock-handoffX18-vsock-handoff: Host-guest socket and descriptor hand-offCan wb-guestd, written in Go, open AFVSOCK sockets in a macOS guest?. NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. already excludes the first boot after a host restart.

A working guest. Every state here came from a guest idle at Setup Assistant, with 1.41 GB of memory in use. Reading the state file is most of the restore time (1.97 s with the file in the host’s memory, 3.71 s without), so a guest running Claude Code and builds, with more memory in use, restores more slowly.

Branch spike/x02-warm-start, at aadb90a: a Swift command-line tool that installs, boots, saves, and restores the VM, the clone and series scripts, and the raw results in results/ with their p50 and p95 in results/stats.txt.

Status: Answered 2026-10-04: yes, with conditions. Decided 2026-10-04 (I16I16 (closed): X02-warm-start: Warm startHow long does it take to restore a macOS guest from saved state with a vsock device and a file-handle network attachment?): an idle VM keeps running while the host is locked and is saved after unlock