Repository navigation
perf(vm): stop repeating per-launch overlay writes and hashes before the VM starts - #6056
Open
balajinvda wants to merge 3 commits into
Open
balajinvda wants to merge 3 commits into
balajinvda wants to merge 3 commits into
Conversation
A sandbox launch writes its per-sandbox files into the overlay ext4 (the init drop-ins and their manifest, the mount manifest, then the boundary configuration, certificate and key) with one `debugfs -w -R` process per command: a mkdir per parent directory, rm and write per file, set_inode_field per mode. That is about thirty debugfs processes per launch. Measured with the same debugfs, overlay template and commands on an x86-64 workstation: 152 to 183 ms as separate processes, 7 to 9 ms as one `debugfs -f` run. RootfsImageBatch stages the same commands in the same order and runs them as one `debugfs -w -f` process (the existing run_debugfs_batch): one run for the guest overlay files, one for the boundary bundle (the boundary provisioning sits between the two), and one for the three removals of a runtime generation's material. debugfs reports a failing command (an existing directory, a missing file) on stderr and exits 0 in both modes, so a batch leaves the same disk contents and the same success or failure as the separate runs. A path debugfs would read as two lines is refused when it is staged, before anything is written, and staged contents are removed when the batch has run or is dropped. The vm.prepare_guest span moves to prepare_guest_overlay, which stages the drop-ins and the mount manifest and writes them, so it now covers the mount manifest and the write itself. Test: rootfs_image_batch_writes_what_one_debugfs_per_command_wrote applies the launch's shape of writes, modes and removals (including the harmless failures) both ways to copies of one image and compares every entry's mode, owner, size and contents; rootfs_image_batch_refuses_a_path_debugfs_reads_as_two_lines covers the refusal and the cleanup of a dropped batch. Closes ai-openshell#6054 Signed-off-by: Balaji Ganesan <bganesan@nvidia.com>
Every bootstrap root disk's image cache key includes sandbox_guest_runtime_identity(), a SHA-256 over the embedded sandbox, vm-init and umoci blobs and the guest init script. It was computed on every call, and every launch resolves its root disk in a fresh image preparation worker process, so every launch hashed the embedded blobs again, even on a cache hit. On an x86-64 host without SHA instructions most of the 90 ms between the worker's "ensuring cached root disk image" and its cache hit is this hash (inferred from the driver log gap, not profiled). build.rs now hashes exactly the files the crate embeds (from OUT_DIR, plus the init script, which build.rs now watches) and the function returns that constant. The value is unchanged, so cached root disks stay valid. Test: guest_runtime_identity_built_once_matches_the_embedded_bytes holds the build-time value equal to the hash of the embedded bytes computed at run time, as before. Closes ai-openshell#6054 Signed-off-by: Balaji Ganesan <bganesan@nvidia.com>
Every launch validates the cached host supervisor in host_supervisor_binary by hashing all of it (about 50 MB) on an async runtime thread. On an x86-64 host without SHA instructions the driver log shows about 280 ms between "launcher spawned" and the host supervisor's start, consistent with a software SHA-256 of that file (inferred, not profiled). It runs while the guest boots, so it is mostly hidden today, but it becomes the floor of a launch once the guest boots faster, and it holds a runtime thread meanwhile. A file this driver process hashed and found good is not hashed again while its device, inode, size, mode, mtime and ctime are unchanged. Any write, chmod, chown, rename or replacement changes the ctime (set by the kernel; no caller can set it back) or the inode, and the file is hashed again. The kernel stamps ctime from a coarse clock, so a rewrite in the same tick as the file's last change can keep its ctime: only a file whose ctime is at least 1 s old is remembered (git's "racily clean" rule), so any later change gets a later ctime. Only a file unchanged across its own hash is remembered, a refused file never is, the memory is per embedded supervisor digest, and a new driver process hashes again on its first launch. Test: host_supervisor_validated_once_per_file_version counts the hashes across a just-written file (not remembered), a settled file (hashed once), a same-size rewrite in place, a replacement by rename, a chmod that drops the execute bit, another embedded digest and a fresh process. Closes ai-openshell#6054 Signed-off-by: Balaji Ganesan <bganesan@nvidia.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes three pieces of per-launch bookkeeping the VM driver repeats on every sandbox create with an unchanged result: one
debugfsprocess per overlay command, hashing the embedded guest binaries for the image cache key, and hashing the ~50 MB cached host supervisor. One commit per change; behaviour is unchanged apart from timing.Related Issue
Closes #6054
Changes
perf(vm): write a launch's overlay files in one debugfs run:RootfsImageBatch(inrootfs.rs) stages the samemkdir/rm/write/set_inode_fieldcommands in the same order and runs them through the existingrun_debugfs_batch(debugfs -w -f): one run for the guest overlay files, one for the boundary bundle, one for the generation cleanup. debugfs reports a failing command on stderr and exits 0 in both modes, so the disk contents and the success or failure are the same as with separate runs. A path debugfs would read as two lines is refused when staged, before anything is written; staged temp files are removed when the batch runs or is dropped.write_rootfs_image_filekeeps its signature (used byruntime.rs) and becomes a one-file batch;run_debugfsis now test-only. Thevm.prepare_guestspan moves to a newprepare_guest_overlayand so also covers the mount manifest and the write.perf(vm): hash the guest runtime identity at build time:build.rshashes exactly the bytes the crate embeds (fromOUT_DIR, plus the init script, which it now watches) andsandbox_guest_runtime_identity()returns that constant. Same value, so existing cached root disks stay valid. Addssha2as a build dependency (already a dependency;Cargo.lockunchanged).perf(vm): hash the cached host supervisor once per file version:validate_host_supervisorremembers the last file it hashed and found good, keyed by path, dev, inode, size, mode, mtime, ctime and the embedded digest. Any write, chmod, chown, rename or replacement changes ctime or inode and is hashed again. Because ctime comes from a coarse clock, a file is remembered only once its ctime is at least 1 s old (git's "racily clean" rule), and only if its stamp did not change while it was hashed. A refused file is never remembered; a new driver process hashes again.create_sandbox received→launcher spawned367 → 41–67 ms; the overlay writes take 13–27 ms of that. These measurements were taken on the v0.1.7 driver with the same changes; the code paths are unchanged onmain, which this branch is based on (659b45f3b). Per-item numbers and which are inferred are in VM driver repeats per-launch bookkeeping before the VM starts: a debugfs process per overlay command, guest identity and host supervisor re-hashed #6054.Testing
cargo fmt -p openshell-driver-vm -- --check,cargo clippy -p openshell-driver-vm --all-targets -- -D warnings,cargo test -p openshell-driver-vm(lib: 305 passed),cargo check -p openshell-driver-vm --no-default-featuresrootfs_image_batch_writes_what_one_debugfs_per_command_wrote: applies the launch's shape of writes, modes and removals (a replaced file, a new nested directory, a path with a space, harmless failures on a missing file) onedebugfs -Rper command to one copy of an image and as one batch to another, then compares every entry's mode, owner, size and contents; checks the staged files are gone.rootfs_image_batch_refuses_a_path_debugfs_reads_as_two_lines: newline/CR paths are refused at staging, only valid commands are staged, a dropped batch removes its staged files.guest_runtime_identity_built_once_matches_the_embedded_bytes: the build-time value equals the hash of the embedded bytes computed at run time.host_supervisor_validated_once_per_file_version: counts hashes across a just-written file (not remembered), a settled file (hashed once), a same-size rewrite in place, replacement by rename, a chmod that drops the execute bit, another embedded digest and a fresh process.post_overlay_provisioning_stages_record_child_spansupdated forprepare_guest_overlay.The unit tests ran on Linux x86-64 with e2fsprogs installed; the build used stub embedded runtime artifacts (
OPENSHELL_VM_RUNTIME_COMPRESSED_DIRunset). The same three changes, on the v0.1.7 driver, booted VM sandboxes from a cached digest-pinned image on an x86-64 KVM host, and the unit tests above (in their v0.1.7 form) also passed on arm64.Checklist