Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
ludfjig
force-pushed
the
ll/scratch-gpa-alignment
branch
from
November 25, 2026 04:12
f3304c5 to
ddae45a
Compare
This comment has been minimized.
This comment has been minimized.
…can map it with 2 MiB pages. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
ludfjig
force-pushed
the
ll/scratch-gpa-alignment
branch
from
November 25, 2026 17:44
ddae45a to
147734e
Compare
ludfjig
marked this pull request as ready for review
November 25, 2026 17:44
ludfjig
requested review from
andreiltd,
danbugs,
dblnz,
devigned,
jprendes,
jsturtevant,
simongdavies,
squillace and
syntactically
as code owners
November 25, 2026 17:44
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the Linux scratch-memory alignment changes.
No open issues 🎉
What changed in this PR
This PR improves Linux scratch-memory performance by matching host and guest address offsets. This lets Hyperlight’s KVM and MSHV backends use 2 MiB mappings when transparent huge pages are set to always.
Changes:
- Aligns scratch allocations of at least 2 MiB while preserving usable bounds and guard pages.
- Applies alignment during snapshot-based sandbox creation and scratch resizing.
- Adds alignment checks and documents scratch-size guidance and performance benefits.
| File | Description |
|---|---|
src/hyperlight_host/src/sandbox/initialized.rs |
Checks scratch alignment during sandbox creation and snapshot restore. |
src/hyperlight_host/src/sandbox/config.rs |
Documents scratch-size guidance for MSHV performance. |
src/hyperlight_host/src/sandbox/builder.rs |
Adds the same guidance to the builder API documentation. |
src/hyperlight_host/src/mem/shared_mem.rs |
Implements aligned allocations, separates reservation ownership from logical bounds, and tests alignment and guards. |
src/hyperlight_host/src/mem/mgr.rs |
Uses aligned allocations for snapshot creation and scratch resizing. |
CHANGELOG.md |
Records Linux alignment behavior and measured KVM performance benefits. |
Review effort: Balanced
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) (✅ 1.89x)Top improvements
Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (❌ 1.53x)Top regressions
Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
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.
Guest scratch memory on Linux is mapped with 4 KiB pages on KVM and MSHV even when transparent huge pages are set to
always. Hypervisors can use 2 MiB pages only when a region's host virtual address and guest physical address have the same offset within a 2 MiB boundary. Plainmmapplaces scratch at an arbitrary page address, so those offsets rarely match.From the KVM API docs:
This change aligns Linux scratch allocations of 2 MiB or more to match their guest physical address offset:
PROT_NONEso they extend the guard pages and use no extra physical memory.This does not enable huge pages inside the guest. Guest page tables still use 4 KiB pages, and only the host hypervisor mappings use 2 MiB pages when transparent huge pages are enabled on the host.
Benchmark results with transparent huge pages set to
always:heap_first_touch_new_sandbox/largeheap_first_touch_new_sandbox/mediumcall_with_restore/largeheap_random_access/largeheap_first_touch_new_sandbox/largeheap_random_access/largeheap_first_touch_new_sandbox/largeheap_random_access/largeCI's KVM runners do not set transparent huge pages to
always, so the CI benchmark comment shows no change.