Skip to content

perf: WHP warm-start optimizations#87

Merged
danbugs merged 3 commits into
mainfrom
perf/whp-warm-start
May 27, 2026
Merged

perf: WHP warm-start optimizations#87
danbugs merged 3 commits into
mainfrom
perf/whp-warm-start

Conversation

@danbugs
Copy link
Copy Markdown
Contributor

@danbugs danbugs commented May 27, 2026

Summary

Optimizes WHP snapshot-restore latency on Windows (~8x cold load, ~6x steady-state restore).

Hyperlight changes (danbugs/hyperlight@perf/whp-warm-start):

  • Batched vCPU register resets — single WHvSetVirtualProcessorRegisters call for GPR + debug + special registers instead of three separate calls
  • Cached xsave template — built once at VM creation, applied as a single write per restore instead of read-modify-write
  • restore_preserving_file_mappings — skips unmapping/remapping read-only file regions (e.g., initrd) during restore; safe because they are PAGE_READONLY at the hypervisor level and guest writes go through CoW via scratch
  • whp-no-surrogate feature — for single-partition-per-process scenarios: VirtualAlloc instead of CreateFileMappingA, WHvMapGpaRange instead of WHvMapGpaRange2; scratch zeroing uses fill(0) in-place (MEM_DECOMMIT+MEM_COMMIT was removed as it desyncs the WHP GPA mapping)

This repo:

  • Calls restore_preserving_file_mappings when an initrd mapping exists
  • Enables whp-no-surrogate

Test plan

  • Correct output over 100+ repeat invocations on Windows
  • Hermetic isolation verified (identical output per run)
  • CI benchmarks

Copilot AI review requested due to automatic review settings May 27, 2026 15:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces Windows WHP warm-start (snapshot restore) latency by adjusting the host-side restore path to preserve read-only initrd file mappings across restores, and by switching the embedded Hyperlight host dependency to a fork/branch that contains WHP warm-start optimizations (including whp-no-surrogate).

Changes:

  • Update Sandbox::restore() to use restore_preserving_file_mappings() when an initrd file mapping exists, avoiding unmap/remap on restore.
  • Remove stored initrd mapping base address from Sandbox/finish_evolve() since restores no longer re-register the file mapping.
  • Switch hyperlight-host dependency to danbugs/hyperlight perf/whp-warm-start and enable whp-no-surrogate (with corresponding lockfile updates).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
host/src/lib.rs Uses preserving restore variant when initrd mapping exists; removes now-unneeded initrd remap bookkeeping.
host/Cargo.toml Points hyperlight-host at the WHP warm-start optimization branch and enables whp-no-surrogate.
host/Cargo.lock Updates locked git revision and transitive deps from the new hyperlight-host source.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread host/Cargo.toml Outdated
Comment on lines 30 to 31
# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file
# Uses PAGE_READONLY mapping (no host commit charge per VM).
Comment thread host/Cargo.toml Outdated
# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file
# Uses PAGE_READONLY mapping (no host commit charge per VM).
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", branch = "disk_snapshot_copy", features = ["executable_heap", "hw-interrupts"] }
hyperlight-host = { git = "https://github.com/danbugs/hyperlight", branch = "perf/whp-warm-start", features = ["executable_heap", "hw-interrupts", "whp-no-surrogate"] }
danbugs added 2 commits May 27, 2026 16:00
Call restore_preserving_file_mappings when a file mapping (initrd)
exists, skipping the unmap/remap cycle on every snapshot restore.
Remove the now-unused file_mapping_base field.

Signed-off-by: danbugs <danilochiarlone@gmail.com>
Pin to rev 3ed18580 for reproducible builds. Enables whp-no-surrogate
for VirtualAlloc allocation, direct WHvMapGpaRange, and demand-zero
scratch reset.

Signed-off-by: danbugs <danilochiarlone@gmail.com>
@danbugs danbugs force-pushed the perf/whp-warm-start branch from 62e3785 to 3537f04 Compare May 27, 2026 16:00
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Linux Benchmarks

Details
Benchmark suite Current: 1e95cc0 Previous: b15806c Ratio
hello_world (median) 30 ms 20 ms 1.50
pandas (median) 110 ms 110 ms 1
density (per VM) 11 MB 11 MB 1
snapshot (disk) 656 MiB 656 MiB 1

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Windows Benchmarks

Details
Benchmark suite Current: 1e95cc0 Previous: b15806c Ratio
hello_world (median) 218 ms 347 ms 0.63
pandas (median) 213 ms 1044 ms 0.20
snapshot (disk) 279 MiB 663 MiB 0.42

This comment was automatically generated by workflow using github-action-benchmark.

The MEM_DECOMMIT+MEM_COMMIT optimization in zero() replaced physical
pages without notifying WHP, causing FC-aware dispatch (pyhl,
pydriver-run) to read stale input data on Windows.

Signed-off-by: danbugs <danilochiarlone@gmail.com>
@danbugs danbugs merged commit 2d5683a into main May 27, 2026
79 checks passed
@danbugs danbugs deleted the perf/whp-warm-start branch May 27, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants