Skip to content

feat(virtq): use Rc pointer equality instead if generation for pools - #1945

Open
andreiltd wants to merge 1 commit into
hyperlight-dev:mainfrom
andreiltd:virtq-pool-inst
Open

andreiltd wants to merge 1 commit into
hyperlight-dev:mainfrom
andreiltd:virtq-pool-inst

Conversation

@andreiltd

Copy link
Copy Markdown
Member

Instead of threading generation through pools it's actually simpler to use Rc::ptr_eq to check if pool belongs to current snapshot generation and swap pools on restore.

Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:10
@andreiltd andreiltd added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Oct 16, 2026
@andreiltd andreiltd changed the title feat(virtq): use Rc pointer equality instead generation for pools feat(virtq): use Rc pointer equality instead if generation for pools Oct 16, 2026

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

Reservation validation rejects every nonempty pool swap, causing restore failures with retained buffers and posted chains.

1 open finding
What changed in this PR

This PR uses shared pool identity to track virtqueue allocation ownership across snapshot restores.

Changes:

  • Replace pool generation counters with Rc pointer identity and pool swaps.
  • Keep retained leases tied to their original pools.
  • Expand swap tests and update transport documentation.
File Description
src/​hyperlight_host/​tests/​integration_test.rs Rename the retained-buffer test.
src/​hyperlight_guest/​src/​transport/​context.rs Clarify pool ownership and restore safety comments.
src/​hyperlight_guest/​src/​transport/​backing.rs Update alias allocator terminology.
src/​hyperlight_common/​src/​virtq/​producer.rs Swap pools while preserving posted chains.
src/​hyperlight_common/​src/​virtq/​pool/​tests.rs Test swap reservations, ordering, and validation.
src/​hyperlight_common/​src/​virtq/​pool/​slot.rs Implement pool identity and replacement allocation state.
src/​hyperlight_common/​src/​virtq/​buffer.rs Return leases to their original pools.
docs/​virtio-host-guest-communication.md Document pool swaps and retained ownership.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hyperlight_common/src/virtq/pool/slot.rs
@hyperlight-gh-bot

This comment has been minimized.

@andreiltd
andreiltd force-pushed the virtq-pool-inst branch 2 times, most recently from 8de61b5 to 4062922 Compare October 19, 2026 13:47
Instead of threading generation through pools it's actually simpler to
use Rc::ptr_eq to check if pool belongs to current snapshot generation
and swap pools on restore.

Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 97d57b1900a4
Baseline commit: 8a311248f0ab

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 761.44 ns (➖ 1.00x faster)
vec_bytes 582.34 ns (➖ 1.02x faster)
377.11 µs (➖ 1.01x slower)

payload_allocation

slot_pool_segmented
262144 553.46 ns (➖ 1.30x faster)
65536 142.65 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 82.08 ms (➖ 1.01x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
7.86 ns (➖ 1.00x slower) 7.72 ns (➖ 1.04x faster) 7.72 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 93.66 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.02 µs (➖ 1.46x faster) 7.42 µs (➖ 1.16x faster)
65536 2.05 µs (➖ 1.06x slower) 1.92 µs (➖ 1.10x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.33 µs (➖ 1.03x faster) 6.94 µs (➖ 1.04x slower)
8192 1.14 µs (➖ 1.08x slower) 1.04 µs (➖ 1.04x faster)
262144 28.62 µs (➖ 1.03x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 791.26 ns (➖ 1.04x faster)
vec_bytes 594.18 ns (➖ 1.04x faster)
719.92 µs (➖ 1.03x faster)

payload_allocation

slot_pool_segmented
262144 604.55 ns (➖ 1.04x faster)
65536 161.15 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 83.27 ms (➖ 1.02x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.17 ns (➖ 1.02x faster) 8.10 ns (➖ 1.03x faster) 8.26 ns (➖ 1.03x faster)

snapshot_files

load_snapshot_unverified
small 50.43 µs (➖ 1.01x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.93 µs (➖ 1.01x faster) 8.73 µs (➖ 1.04x faster)
65536 2.47 µs (➖ 1.02x faster) 2.47 µs (➖ 1.02x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.15 µs (➖ 1.08x faster) 8.12 µs (➖ 1.08x faster)
8192 870.39 ns (➖ 1.08x faster) 860.77 ns (➖ 1.06x faster)
262144 36.23 µs (➖ 1.03x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 933.67 ns (➖ 1.01x faster)
vec_bytes 712.15 ns (➖ 1.00x faster)
315.97 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 678.74 ns (➖ 1.01x slower)
65536 188.12 ns (➖ 1.03x slower)

sandboxes

create_initialized_and_drop
medium 58.12 ms (➖ 1.00x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
9.96 ns (➖ 1.00x slower) 9.94 ns (➖ 1.01x faster) 9.95 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 86.30 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.14 µs (➖ 1.01x faster) 9.21 µs (➖ 1.10x faster)
65536 2.64 µs (➖ 1.04x faster) 2.46 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.00 µs (➖ 1.06x faster) 8.03 µs (➖ 1.03x faster)
8192 1.39 µs (➖ 1.01x faster) 1.34 µs (➖ 1.01x faster)
262144 35.21 µs (➖ 1.01x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 970.14 ns (➖ 1.06x slower)
vec_bytes 659.71 ns (➖ 1.02x faster)
702.81 µs (➖ 1.46x faster)

payload_allocation

slot_pool_segmented
262144 637.07 ns (➖ 1.04x faster)
65536 172.10 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 66.20 ms (➖ 1.09x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.79 ns (➖ 1.10x faster) 9.51 ns (➖ 1.01x slower) 8.86 ns (➖ 1.07x faster)

snapshot_files

load_snapshot_unverified
small 49.63 µs (➖ 1.00x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.01 µs (➖ 1.00x slower) 7.94 µs (➖ 1.00x faster)
65536 2.34 µs (➖ 1.02x slower) 2.29 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.48 µs (➖ 1.02x faster) 7.44 µs (➖ 1.05x faster)
8192 922.70 ns (➖ 1.02x faster) 913.31 ns (➖ 1.00x faster)
262144 37.12 µs (➖ 1.16x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.15 µs (➖ 1.01x faster)
vec_bytes 784.69 ns (➖ 1.00x slower)
2.01 ms (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 792.48 ns (➖ 1.00x slower)
65536 232.40 ns (➖ 1.03x faster)

sandboxes

create_initialized_and_drop
medium 87.56 ms (➖ 1.00x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
11.11 ns (➖ 1.09x slower) 10.15 ns (➖ 1.04x faster) 9.90 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 662.09 µs (➖ 1.17x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.56 µs (➖ 1.04x slower) 9.61 µs (➖ 1.07x slower)
65536 2.42 µs (➖ 1.02x slower) 2.38 µs (➖ 1.02x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 9.11 µs (➖ 1.01x faster) 8.82 µs (➖ 1.01x faster)
8192 1.37 µs (➖ 1.01x faster) 1.30 µs (➖ 1.02x faster)
262144 39.63 µs (➖ 1.06x faster)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.22 µs (➖ 1.00x slower)
vec_bytes 808.40 ns (➖ 1.04x faster)
4.18 ms (➖ 1.06x faster)

payload_allocation

slot_pool_segmented
262144 748.26 ns (➖ 1.01x faster)
65536 216.72 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 127.49 ms (➖ 1.15x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.38 ns (➖ 1.04x slower) 10.12 ns (➖ 1.01x slower) 10.47 ns (➖ 1.05x slower)

snapshot_files

load_snapshot_unverified
small 615.42 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.82 µs (➖ 1.00x faster) 7.84 µs (➖ 1.01x faster)
65536 2.34 µs (➖ 1.00x faster) 2.35 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.35 µs (➖ 1.06x faster) 8.42 µs (➖ 1.06x faster)
8192 1.10 µs (➖ 1.16x faster) 1.08 µs (➖ 1.04x faster)
262144 41.83 µs (➖ 1.10x faster)

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants