fix(restore): replace scratch zero with fresh allocation on Windows - #1765
Merged
danbugs merged 1 commit intoAug 26, 2026
Merged
Conversation
danbugs
requested review from
andreiltd,
jprendes,
ludfjig,
simongdavies,
squillace and
syntactically
as code owners
August 25, 2026 18:03
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes snapshot restore behavior in hyperlight-host by avoiding full zeroing of large scratch regions on Windows, instead relying on fresh demand-zero allocations to reduce RSS spikes and restore latency.
Changes:
- On Windows,
restore_snapshot()allocates a new scratch region even when the scratch size is unchanged, avoiding a full-regionfill(0)/memset. - Adds an in-code rationale explaining the Windows-specific performance motivation and why Linux behavior is unchanged.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
3 times, most recently
from
August 25, 2026 18:29
0a18a36 to
4565fd5
Compare
jsturtevant
previously approved these changes
Aug 25, 2026
syntactically
previously approved these changes
Aug 25, 2026
syntactically
left a comment
Member
There was a problem hiding this comment.
This looks like the functionally correct change to unblock the Windows unikraft performance issues. I do have a couple of minor nits below, especially around communicating why we are using (and that we should replace) this fairly odd heuristic.
danbugs
dismissed stale reviews from syntactically and jsturtevant
via
August 25, 2026 20:04
ded51f4
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
from
August 25, 2026 20:04
4565fd5 to
ded51f4
Compare
ludfjig
reviewed
Aug 25, 2026
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
from
August 25, 2026 21:33
ded51f4 to
385173c
Compare
syntactically
previously approved these changes
Aug 25, 2026
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
from
August 25, 2026 21:46
385173c to
89c24b2
Compare
ludfjig
approved these changes
Aug 25, 2026
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
from
August 25, 2026 23:21
89c24b2 to
7c879b4
Compare
danbugs
enabled auto-merge (squash)
August 26, 2026 00:26
restore_snapshot() zeroed scratch memory via scratch_mem.zero() when the size was unchanged. On Linux, KVM-only builds use MADV_DONTNEED (lazy zero) and mshv3 builds fall through to fill(0). On Windows there was no lazy path at all — zeroing memsets the entire region. For a Node.js guest with 448 MiB scratch, this caused: - RSS spike from ~9 MiB to ~453 MiB on each restore - Rewind time of ~138 ms (Windows) Gate the fresh-allocation path behind Windows only. On Windows, ExclusiveSharedMemory::new provides demand-zero pages (page-file- backed), so physical memory is consumed only as the guest touches pages. On Linux, keep the existing zero() path (KVM: MADV_DONTNEED, mshv3: fill(0)). Signed-off-by: danbugs <danilochiarlone@gmail.com>
danbugs
force-pushed
the
danbugs/fix-restore-rss-v0.16
branch
from
August 26, 2026 01:04
7c879b4 to
2a76cbc
Compare
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.
When restoring a snapshot,
restore_snapshot()can fall into two paths:zero()on the existing regionUnless you exclude default features and use KVM only,
zero()falls to a codepath thatmemsets the entire scratch region with zeroes. With big scratch regions like is often the case with Hyperlight+Unikraft guests (e.g., 448 MiB for Node.js), this causes a massive RSS spike and significantly increases restore time.With this change, the default path on Windows uses the same fresh-allocation strategy as when the scratch sizes differ — the OS provides demand-zero pages (page-file-backed), so physical memory is consumed only as the guest touches pages.
This is gated behind Windows only. The MSHV path on Linux is left unchanged for now to avoid accidentally regressing small MSHV workloads, and may be updated in the future after more thorough benchmarking.