Repository navigation
Conversation
Pack live snapshot pages into one memory layer, optionally retaining identical immutable base layers. Preserve execution state, page-table topology, metadata, transport state, and cached hashes without changing the OCI snapshot format. Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Snapshot compaction breaks debug x86_64 builds with the gdb feature, and compact(None) can produce saved snapshots that both loaders reject when packed live data is smaller than the code region.
2 open issues
What changed in this PR
This PR adds opt-in snapshot compaction to Hyperlight’s host library, helping callers bound retained memory layers without changing the OCI persistence format.
Changes:
- Add
Snapshot::compactwith optional preservation of identical base layers. - Preserve snapshot state and document compaction and persistence behavior.
- Extend tests for aliases, permissions, multiple page-table roots, and repeated capture/compact/restore cycles.
| File | Description |
|---|---|
src/hyperlight_host/src/sandbox/snapshot/mod.rs |
Register compaction, enable state cloning, and extend multi-root tests. |
src/hyperlight_host/src/sandbox/snapshot/file_tests.rs |
Test persistence, execution continuity, and retained hash-cache reuse. |
src/hyperlight_host/src/sandbox/snapshot/compact.rs |
Implement compaction, base-layer matching, and focused tests. |
src/hyperlight_host/src/mem/virtq/mod.rs |
Enable cloning of captured transport state. |
src/hyperlight_host/src/mem/layout.rs |
Enable layout equality checks for base compatibility. |
docs/snapshot-oci-format.md |
Document compaction modes and self-contained persistence. |
Review effort: Balanced
Keep the loader code-span invariant through packed-layer placement and minimal padding when all live pages reside in preserved base layers. Copy from the backing-independent slice accessor and cover sparse persistence plus debug gdb compaction. Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
ludfjig
left a comment
There was a problem hiding this comment.
LGTM. The 30 layer limit is arbitrary, we might want to add a config on sandbox to customize this

Motivation
Repeated snapshot capture retains immutable memory layers and can eventually reach the layer limit. Give callers an explicit way to bound live snapshot memory without depending on intermediate checkpoints or changing the persistence format.
Changes
Snapshot::compact(&self, base: Option<&Snapshot>) -> Result<Arc<Self>>.Validation
cargo +1.99.1 test --offline --locked -p hyperlight-host --lib -- compact sandbox::snapshot::file_tests --test-threads=1cargo +1.99.1 test --offline --locked -p hyperlight-host --lib capture_and_restore_preserve_multiple_page_table_rootscargo +1.99.1 clippy --offline --locked -p hyperlight-host --lib --tests -- -D warnings