Skip to content

Add opt-in transparent huge pages for scratch - #2111

Draft
ludfjig wants to merge 2 commits into
hyperlight-dev:mainfrom
ludfjig:ll/scratch-thp-opt-in
Draft

ludfjig wants to merge 2 commits into
hyperlight-dev:mainfrom
ludfjig:ll/scratch-thp-opt-in

Conversation

@ludfjig

@ludfjig ludfjig commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #2105, will mark ready when merged.

#2105 lets KVM and MSHV map scratch with 2 MiB pages, but only when the host backs scratch with transparent huge pages. Ubuntu and WSL set /sys/kernel/mm/transparent_hugepage/enabled to madvise, so scratch stays on 4 KiB pages there.

This change adds SandboxBuilder::scratch_transparent_huge_pages. When set, Hyperlight calls madvise(MADV_HUGEPAGE) on each new scratch mapping. Building the sandbox fails if the kernel lacks transparent huge page support. The default, false, leaves scratch to the host's policy.

The option is Linux-only. Windows and macOS have no equivalent AFAIK

…can map it with 2 MiB pages.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
…parent huge pages for scratch on Linux, so KVM and MSHV can map it with 2 MiB pages on hosts that use them only on request.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig ludfjig added C-enhancement For PRs adding features, improving functionality, docs, tests, etc. A-perf Addresses performance A-api Related to the API or public interface O-linux Linux host support labels Nov 25, 2026
@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: a5de41d22819
Baseline commit: c46735cd076c

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 307.36 ns (➖ 1.12x slower)
vec_bytes 79.48 ns (➖ 1.00x faster)
371.75 µs (➖ 1.00x faster)

payload_allocation

slot_pool_segmented
65536 141.54 ns (➖ 1.00x slower)
262144 549.81 ns (➖ 1.05x slower)

sandboxes

create_initialized_and_drop
medium 13.76 ms (➖ 1.00x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
7.68 ns (➖ 1.17x faster) 7.68 ns (➖ 1.00x faster) 7.69 ns (➖ 1.00x faster)

snapshot_files

load_snapshot_unverified
small 107.40 µs (➖ 1.05x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 1.90 µs (➖ 1.13x faster) 2.04 µs (➖ 1.07x slower)
262144 7.11 µs (➖ 1.07x faster) 7.11 µs (➖ 1.01x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 6.19 µs (➖ 1.01x faster) 6.14 µs (➖ 1.07x faster)
262144 27.07 µs (➖ 1.01x faster)
8192 1.01 µs (➖ 1.00x faster) 1.03 µs (➖ 1.02x slower)
kvm / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 279.88 ns (➖ 1.15x faster)
vec_bytes 83.20 ns (➖ 1.18x faster)
673.05 µs (➖ 1.09x faster)

payload_allocation

slot_pool_segmented
65536 157.78 ns (➖ 1.02x slower)
262144 585.33 ns (➖ 1.02x slower)

sandboxes

create_initialized_and_drop
medium 14.75 ms (➖ 1.05x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.03 ns (➖ 1.00x faster) 8.05 ns (➖ 1.01x faster) 8.05 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 56.67 µs (➖ 1.08x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.46 µs (➖ 1.03x faster) 2.49 µs (➖ 1.01x faster)
262144 8.81 µs (➖ 1.00x faster) 8.78 µs (➖ 1.00x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.21 µs (➖ 1.02x faster) 8.18 µs (➖ 1.03x faster)
262144 35.38 µs (➖ 1.01x faster)
8192 819.69 ns (➖ 1.02x faster) 837.52 ns (➖ 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 391.89 ns (➖ 1.01x faster)
vec_bytes 102.64 ns (➖ 1.06x slower)
311.67 µs (➖ 1.16x slower)

payload_allocation

slot_pool_segmented
65536 191.35 ns (➖ 1.01x faster)
262144 748.44 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 63.12 ms (➖ 1.04x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
9.90 ns (➖ 1.00x slower) 9.88 ns (➖ 1.01x faster) 9.86 ns (➖ 1.02x faster)

snapshot_files

load_snapshot_unverified
small 99.83 µs (➖ 1.09x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.22 µs (➖ 1.01x faster) 2.39 µs (➖ 1.02x faster)
262144 9.68 µs (➖ 1.03x faster) 9.84 µs (➖ 1.02x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.27 µs (➖ 1.17x faster) 8.27 µs (➖ 1.25x faster)
262144 36.19 µs (➖ 1.06x faster)
8192 1.21 µs (➖ 1.01x slower) 1.29 µ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 383.24 ns (➖ 1.08x slower)
vec_bytes 89.66 ns (➖ 1.01x faster)
715.35 µs (➖ 1.08x slower)

payload_allocation

slot_pool_segmented
65536 175.12 ns (➖ 1.02x slower)
262144 629.88 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 53.60 ms (➖ 1.33x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
8.79 ns (➖ 1.01x slower) 9.36 ns (➖ 1.02x slower) 8.73 ns (➖ 1.15x faster)

snapshot_files

load_snapshot_unverified
small 50.15 µs (➖ 1.02x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.25 µs (➖ 1.01x faster) 2.24 µs (➖ 1.01x faster)
262144 7.92 µs (➖ 1.00x slower) 7.87 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 7.41 µs (➖ 1.00x faster) 7.40 µs (➖ 1.02x faster)
262144 38.86 µs (➖ 1.02x faster)
8192 891.89 ns (➖ 1.03x faster) 897.88 ns (➖ 1.02x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 571.64 ns (➖ 1.03x slower)
vec_bytes 164.88 ns (➖ 1.01x slower)
1.89 ms (➖ 1.01x faster)

payload_allocation

slot_pool_segmented
65536 228.71 ns (➖ 1.02x faster)
262144 794.10 ns (➖ 1.09x faster)

sandboxes

create_initialized_and_drop
medium 13.65 ms (➖ 1.09x slower)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.43 ns (➖ 1.01x slower) 10.10 ns (➖ 1.00x slower) 10.39 ns (➖ 1.00x slower)

snapshot_files

load_snapshot_unverified
small 694.36 µs (➖ 1.24x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.37 µs (➖ 1.01x slower) 2.33 µs (➖ 1.01x faster)
262144 9.28 µs (➖ 1.01x faster) 8.99 µs (➖ 1.04x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.66 µs (➖ 1.02x faster) 8.77 µs (➖ 1.02x faster)
262144 39.08 µs (➖ 1.01x slower)
8192 1.26 µs (➖ 1.03x faster) 1.27 µs (➖ 1.01x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 572.05 ns (➖ 1.07x faster)
vec_bytes 176.67 ns (➖ 1.10x slower)
3.08 ms (➖ 1.02x faster)

payload_allocation

slot_pool_segmented
65536 215.22 ns (➖ 1.01x slower)
262144 770.87 ns (➖ 1.01x slower)

sandboxes

create_initialized_and_drop
medium 13.91 ms (➖ 1.04x faster)

slot_pool

alloc_dealloc_4096 alloc_dealloc_1500 alloc_dealloc_128
10.12 ns (➖ 1.09x faster) 9.79 ns (➖ 1.00x slower) 9.88 ns (➖ 1.08x faster)

snapshot_files

load_snapshot_unverified
small 589.05 µs (➖ 1.03x faster)

virtq_readonly

slot_pool_segmented slot_pool_segmented_fragmented
65536 2.33 µs (➖ 1.01x slower) 2.26 µs (➖ 1.02x faster)
262144 7.81 µs (➖ 1.01x slower) 7.62 µs (➖ 1.01x faster)

virtq_readwrite

slot_pool_segmented slot_pool_segmented_fragmented
65536 8.25 µs (➖ 1.03x faster) 8.62 µs (➖ 1.04x slower)
262144 40.95 µs (➖ 1.01x faster)
8192 1.03 µs (➖ 1.16x faster) 1.11 µs (➖ 1.05x slower)

Reported by cargo ci bench-report --candidate run:45724983314 --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

A-api Related to the API or public interface A-perf Addresses performance C-enhancement For PRs adding features, improving functionality, docs, tests, etc. O-linux Linux host support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant