Skip to content

test(sandbox): check held buffers survive resized snapshots - #1995

Merged
danbugs merged 1 commit into
mainfrom
held-buffer-resize-test
Oct 29, 2026
Merged

danbugs merged 1 commit into
mainfrom
held-buffer-resize-test

Conversation

@danbugs

@danbugs danbugs commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Follows up Ludvig's request on #1947 for a test of held buffers across resized snapshots. A held byte chunk keeps a pool slot live and an alias mapped into the transport arena. A resize moves the scratch base but not the arena, and the existing held-buffer tests only take same-size snapshots.

  • Holds guest- and host-originated chunks through 8 → 2 → 16 MiB snapshots, with other chunks held at each restore so only the snapshot can bring the held ones back
  • Reads the held bytes back after traffic through both pools, then checks release, slot reuse over more holds than the pools have slots, and a resize back to 8 MiB

@danbugs danbugs added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Oct 29, 2026
Copilot AI balanced review requested due to automatic review settings October 29, 2026 18:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not force scratch-slot reuse or directly verify release of restored owners, leaving aliasing and lease leaks undetected.

2 open issues
What changed in this PR

This PR adds sandbox regression coverage for held byte buffers across scratch-size changes, following up on #1947.

Changes:

  • Exercises guest- and host-originated buffers through 8 → 2 → 16 MiB snapshots.
  • Checks retained bytes after restore and traffic through both transport pools.
  • Exercises release and repeated holds, then restores an 8 MiB snapshot.
File Description
src/​hyperlight_host/​src/​sandbox/​initialized.rs Adds the held-buffer regression test for resized snapshots.

Review effort: Balanced

ludfjig
ludfjig previously approved these changes Oct 29, 2026

@ludfjig ludfjig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! nit: clanker comments

A held byte chunk keeps a transport pool slot live and an alias
mapped to it in the transport arena. A snapshot with another scratch
size moves the scratch base but leaves the arena at its fixed GPA, so
the held alias is the state most likely to break on a resize. The
held-buffer tests so far only take same-size snapshots.

Hold guest- and host-originated chunks in an 8 MiB sandbox, then
shrink it to 2 MiB and grow it to 16 MiB through snapshots taken with
the chunks held. The live sandbox holds other chunks at each restore,
so only the snapshot can bring the first ones back. After each
restore, move bytes through both pools and read the held bytes back.
Then check that release returns their length, that the freed slots
serve more holds than the pools have slots, and that the sandbox can
resize back to 8 MiB and hold chunks there.

Signed-off-by: danbugs <danilochiarlone@gmail.com>
@danbugs
danbugs enabled auto-merge (squash) October 29, 2026 19:28
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 9ca04d7ab305
Baseline commit: 8e4f59e65e8b

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
372.29 µs (➖ 1.00x slower)
byte_chunks 770.14 ns (➖ 1.01x slower)
vec_bytes 581.73 ns (➖ 1.01x slower)

payload_allocation

slot_pool_segmented
65536 145.94 ns (➖ 1.02x faster)
262144 552.59 ns (➖ 1.05x slower)

sandboxes

create_initialized_and_drop
medium 81.46 ms (➖ 1.02x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
7.68 ns (➖ 1.00x faster) 7.68 ns (➖ 1.01x faster) 7.68 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 92.45 µs (➖ 1.00x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 1.93 µs (➖ 1.09x faster) 2.08 µs (➖ 1.09x slower)
262144 8.24 µs (➖ 1.16x slower) 7.22 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 1.02 µs (➖ 1.01x faster) 1.09 µs (➖ 1.09x slower)
65536 6.15 µs (➖ 1.03x faster) 6.25 µs (➖ 1.01x faster)
262144 27.21 µs (➖ 1.01x faster)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
668.63 µs (➖ 1.00x slower)
byte_chunks 683.78 ns (➖ 1.01x slower)
vec_bytes 515.59 ns (➖ 1.01x slower)

payload_allocation

slot_pool_segmented
65536 170.77 ns (➖ 1.01x faster)
262144 494.20 ns (➖ 1.06x faster)

sandboxes

create_initialized_and_drop
medium 74.58 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
6.76 ns (➖ 1.00x faster) 6.76 ns (➖ 1.00x faster) 6.84 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 44.83 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.15 µs (➖ 1.01x slower) 2.12 µs (➖ 1.01x faster)
262144 7.47 µs (➖ 1.01x faster) 7.50 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 722.31 ns (➖ 1.00x faster) 731.87 ns (➖ 1.11x faster)
65536 7.12 µs (➖ 1.01x slower) 6.99 µs (➖ 1.01x faster)
262144 29.07 µs (➖ 1.07x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
294.27 µs (➖ 1.04x slower)
byte_chunks 935.11 ns (➖ 1.01x faster)
vec_bytes 725.52 ns (➖ 1.00x slower)

payload_allocation

slot_pool_segmented
65536 192.94 ns (➖ 1.00x slower)
262144 728.93 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 58.68 ms (➖ 1.02x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
9.52 ns (➖ 1.00x slower) 9.51 ns (➖ 1.01x faster) 9.63 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 87.07 µs (➖ 1.01x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.25 µs (➖ 1.00x slower) 2.40 µs (➖ 1.03x faster)
262144 9.94 µs (➖ 1.02x slower) 10.15 µs (➖ 1.04x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 1.22 µs (➖ 1.00x slower) 1.23 µs (➖ 1.04x faster)
65536 8.38 µs (➖ 1.16x faster) 8.14 µs (➖ 1.18x faster)
262144 35.77 µs (➖ 1.06x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
701.34 µs (➖ 1.02x slower)
byte_chunks 900.40 ns (➖ 1.01x faster)
vec_bytes 651.84 ns (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 254.34 ns (➖ 1.03x faster)
262144 669.82 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 67.32 ms (➖ 1.03x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
8.70 ns (➖ 1.00x faster) 8.70 ns (➖ 1.00x faster) 8.70 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 45.85 µs (➖ 1.04x slower)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.30 µs (➖ 1.04x faster) 2.28 µs (➖ 1.01x faster)
262144 7.94 µs (➖ 1.02x faster) 7.99 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 901.27 ns (➖ 1.01x faster) 895.80 ns (➖ 1.03x faster)
65536 7.41 µs (➖ 1.01x faster) 7.44 µs (➖ 1.00x faster)
262144 39.59 µs (➖ 1.02x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
1.89 ms (➖ 1.02x faster)
byte_chunks 1.21 µs (➖ 1.02x slower)
vec_bytes 780.16 ns (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 256.63 ns (➖ 1.11x slower)
262144 790.47 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 82.57 ms (➖ 1.00x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
10.52 ns (➖ 1.06x slower) 10.01 ns (➖ 1.00x slower) 10.54 ns (➖ 1.07x slower)

snapshot_files

load_snapshot_unverified
small 701.13 µs (➖ 1.05x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.39 µs (➖ 1.07x faster) 2.44 µs (➖ 1.05x slower)
262144 9.49 µs (➖ 1.06x faster) 9.29 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 1.27 µs (➖ 1.06x faster) 1.39 µs (➖ 1.08x slower)
65536 8.77 µs (➖ 1.09x faster) 8.73 µs (➖ 1.02x faster)
262144 39.55 µs (➖ 1.23x faster)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

decode_vec_bytes_copy encode_control
2.94 ms (➖ 1.01x faster)
byte_chunks 1.19 µs (➖ 1.01x faster)
vec_bytes 770.05 ns (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 208.18 ns (➖ 1.02x faster)
262144 759.20 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 103.28 ms (➖ 1.09x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_128 alloc_dealloc_1500
10.29 ns (➖ 1.06x faster) 9.73 ns (➖ 1.04x faster) 9.63 ns (➖ 1.05x faster)

snapshot_files

load_snapshot_unverified
small 620.12 µs (➖ 1.05x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.46 µs (➖ 1.06x slower) 2.34 µs (➖ 1.04x slower)
262144 7.51 µs (➖ 1.02x faster) 7.65 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
8192 1.07 µs (➖ 1.01x slower) 1.07 µs (➖ 1.09x faster)
65536 8.38 µs (➖ 1.01x faster) 8.39 µs (➖ 1.01x slower)
262144 47.66 µs (➖ 1.02x faster)

Reported by cargo ci bench-report --candidate run:40936535666 --config-file bench_report.toml.

@danbugs
danbugs merged commit 93cd31c into main Oct 29, 2026
69 checks passed
@danbugs
danbugs deleted the held-buffer-resize-test branch October 29, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants