Skip to content

vmem: Add support for lazily zero-initialized memory regions - #1873

Merged
syntactically merged 1 commit into
mainfrom
lm/zero-init-rgns
Oct 2, 2026
Merged

syntactically merged 1 commit into
mainfrom
lm/zero-init-rgns

Conversation

@syntactically

Copy link
Copy Markdown
Member

This is useful for hyperlight-wasm, although it can't fully provide for all use cases in a uniform way until we have better support for hugepages.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 10:50
@syntactically syntactically added C-enhancement For PRs adding features, improving functionality, docs, tests, etc. S-needs-review PR is ready for (re-)review labels Oct 2, 2026
@syntactically
syntactically added this pull request to stack #1875 October 2, 2026 10:51

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.

Copilot review overview

🟡 Changes recommended

Snapshot compatibility, upper-half address decoding, and AArch64 instruction-fault handling need correction.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Adds lazy zero-initialized memory regions to Hyperlight’s virtual-memory system for hyperlight-wasm.

Changes:

  • Defines ZeroInit mappings and their page-table encodings.
  • Extends guest fault handlers to allocate pages on demand.
  • Preserves untouched lazy regions in snapshots without storing page contents.
File Description
src/​hyperlight_host/​src/​sandbox/​snapshot/​mod.rs Preserves untouched ZeroInit mappings.
src/​hyperlight_host/​src/​mem/​mgr.rs Converts ZeroInit permissions to region flags.
src/​hyperlight_guest_bin/​src/​arch/​amd64/​exception/​handle.rs Handles lazy-page allocation on AMD64.
src/​hyperlight_guest_bin/​src/​arch/​aarch64/​exception/​handle.rs Handles lazy-page allocation on AArch64.
src/​hyperlight_common/​src/​vmem.rs Defines ZeroInit and makes mappings copyable.
src/​hyperlight_common/​src/​arch/​amd64/​vmem.rs Encodes and decodes AMD64 lazy mappings.
src/​hyperlight_common/​src/​arch/​aarch64/​vmem.rs Encodes and decodes AArch64 lazy mappings.

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

jprendes
jprendes previously approved these changes Oct 2, 2026

@jprendes jprendes 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.

LGTM

@hyperlight-gh-bot

This comment has been minimized.

This is useful for hyperlight-wasm, although it can't fully provide
for all use cases in a uniform way until we have better support for
hugepages.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 187f419dc1fb
Baseline commit: 43cf3539bd10

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 773.08 ns (➖ 1.00x faster)
vec_bytes 583.54 ns (➖ 1.00x slower)
374.41 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
262144 523.95 ns (➖ 1.01x faster)
65536 142.06 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 79.03 ms (➖ 1.01x faster)

slot_pool

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

snapshot_files

load_snapshot_unverified
small 92.78 µs (➖ 1.00x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.23 µs (➖ 1.00x faster) 7.19 µs (➖ 1.02x faster)
65536 2.08 µs (➖ 1.01x slower) 1.93 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.25 µs (➖ 1.01x faster) 7.20 µs (➖ 1.06x slower)
8192 1.11 µs (➖ 1.05x slower) 1.07 µs (➖ 1.01x slower)
262144 26.73 µs (➖ 1.02x faster)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 691.38 ns (➖ 1.09x faster)
vec_bytes 512.73 ns (➖ 1.06x faster)
659.40 µs (➖ 1.05x faster)

payload_allocation

slot_pool_segmented
262144 507.87 ns (➖ 1.13x faster)
65536 137.10 ns (➖ 1.12x faster)

sandboxes

create_initialized_and_drop
medium 75.79 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
6.95 ns (➖ 1.08x faster) 6.94 ns (➖ 1.08x faster) 6.95 ns (➖ 1.08x faster)

snapshot_files

load_snapshot_unverified
small 46.42 µs (➖ 1.07x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.64 µs (➖ 1.11x faster) 7.71 µs (➖ 1.11x faster)
65536 2.16 µs (➖ 1.11x faster) 2.16 µs (➖ 1.10x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.22 µs (➖ 1.10x faster) 7.23 µs (➖ 1.09x faster)
8192 741.69 ns (➖ 1.13x faster) 736.27 ns (➖ 1.07x faster)
262144 30.42 µs (➖ 1.10x faster)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 942.94 ns (➖ 1.01x faster)
vec_bytes 710.25 ns (➖ 1.00x faster)
271.62 µs (➖ 1.30x faster)

payload_allocation

slot_pool_segmented
262144 769.88 ns (➖ 1.04x slower)
65536 201.51 ns (➖ 1.03x slower)

sandboxes

create_initialized_and_drop
medium 56.56 ms (➖ 1.02x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
9.86 ns (➖ 1.01x slower) 10.54 ns (➖ 1.08x slower) 9.68 ns (➖ 1.06x faster)

snapshot_files

load_snapshot_unverified
small 83.41 µs (➖ 1.00x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.80 µs (➖ 1.00x slower) 9.64 µs (➖ 1.08x slower)
65536 2.43 µs (➖ 1.08x slower) 2.24 µs (➖ 1.10x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.26 µs (➖ 1.01x slower) 8.33 µs (➖ 1.08x slower)
8192 1.35 µs (➖ 1.06x slower) 1.30 µs (➖ 1.02x faster)
262144 36.25 µ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 934.96 ns (➖ 1.00x faster)
vec_bytes 681.88 ns (➖ 1.02x slower)
676.65 µs (➖ 1.01x slower)

payload_allocation

slot_pool_segmented
262144 631.31 ns (➖ 1.01x faster)
65536 166.21 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 66.72 ms (➖ 1.07x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.81 ns (➖ 1.01x slower) 8.75 ns (➖ 1.00x faster) 11.24 ns (➖ 1.13x slower)

snapshot_files

load_snapshot_unverified
small 45.01 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.89 µs (➖ 1.01x slower) 8.00 µs (➖ 1.00x faster)
65536 2.28 µs (➖ 1.02x slower) 2.25 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.50 µs (➖ 1.00x slower) 7.58 µs (➖ 1.00x slower)
8192 863.65 ns (➖ 1.00x slower) 895.25 ns (➖ 1.01x slower)
262144 38.72 µs (➖ 1.02x slower)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.13 µs (➖ 1.00x slower)
vec_bytes 751.22 ns (➖ 1.27x faster)
2.03 ms (➖ 1.23x faster)

payload_allocation

slot_pool_segmented
262144 804.65 ns (➖ 1.01x faster)
65536 235.53 ns (➖ 1.02x slower)

sandboxes

create_initialized_and_drop
medium 81.46 ms (➖ 1.35x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.54 ns (➖ 1.31x faster) 10.75 ns (➖ 1.01x slower) 10.53 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 612.68 µs (➖ 1.30x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.68 µs (➖ 1.00x slower) 9.89 µs (➖ 1.06x slower)
65536 2.52 µs (➖ 1.00x faster) 2.55 µs (➖ 1.06x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.87 µs (➖ 1.01x slower) 9.20 µs (➖ 1.04x slower)
8192 1.39 µs (➖ 1.01x faster) 1.44 µs (➖ 1.02x slower)
262144 44.58 µs (➖ 1.14x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.27 µs (➖ 1.24x slower)
vec_bytes 896.76 ns (➖ 1.10x slower)
3.39 ms (➖ 1.09x slower)

payload_allocation

slot_pool_segmented
262144 741.21 ns (➖ 1.01x slower)
65536 211.63 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 111.49 ms (➖ 1.08x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.08 ns (➖ 1.00x slower) 10.19 ns (➖ 1.00x slower) 10.60 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 625.57 µs (➖ 1.04x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.76 µs (➖ 1.03x slower) 7.72 µs (➖ 1.01x faster)
65536 2.35 µs (➖ 1.03x slower) 2.33 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.65 µs (➖ 1.04x slower) 8.66 µs (➖ 1.01x slower)
8192 1.14 µs (➖ 1.10x faster) 1.22 µs (➖ 1.09x slower)
262144 56.97 µs (➖ 1.35x slower)

Reported by cargo ci bench-report --candidate run:37007006067 --baseline run:36945564806 --config-file bench_report.toml.

@syntactically
syntactically merged commit 187f419 into main Oct 2, 2026
62 checks passed
@syntactically
syntactically deleted the lm/zero-init-rgns branch October 2, 2026 14:55
@github-actions github-actions Bot removed the S-needs-review PR is ready for (re-)review label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-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