Skip to content

Commit 2d5683a

Browse files
authored
Merge pull request #87 from hyperlight-dev/perf/whp-warm-start
perf: WHP warm-start optimizations
2 parents b15806c + 1e95cc0 commit 2d5683a

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

host/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

host/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ name = "pyhl"
2727
path = "src/bin/pyhl.rs"
2828

2929
[dependencies]
30-
# hyperlight-dev/hyperlight#1373 — Ludvig's Snapshot::to_file/from_file
31-
# Uses PAGE_READONLY mapping (no host commit charge per VM).
32-
hyperlight-host = { git = "https://github.com/hyperlight-dev/hyperlight", branch = "disk_snapshot_copy", features = ["executable_heap", "hw-interrupts"] }
30+
# danbugs/hyperlight perf/whp-warm-start — snapshot file support + WHP warm-start optimizations.
31+
hyperlight-host = { git = "https://github.com/danbugs/hyperlight", rev = "5cf37d92", features = ["executable_heap", "hw-interrupts", "whp-no-surrogate"] }
3332
clap = { version = "4", features = ["derive", "env"] }
3433
anyhow = "1"
3534
memmap2 = "0.9"

host/src/lib.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,10 +2008,9 @@ pub struct Sandbox {
20082008
inner: MultiUseSandbox,
20092009
/// Post-init snapshot for fast restore between calls.
20102010
snapshot: Option<Arc<Snapshot>>,
2011-
/// File mapping to re-register after snapshot restore.
2012-
/// Snapshot restore unmaps all non-snapshot regions.
2011+
/// When set, restore uses the preserving variant to keep the
2012+
/// read-only file mapping alive across restores.
20132013
file_mapping_path: Option<std::path::PathBuf>,
2014-
file_mapping_base: u64,
20152014
exit_code: Arc<AtomicI32>,
20162015
/// Shared socket table — cleared on [`Sandbox::restore`] so that
20172016
/// host-side fds don't leak across guest restore cycles.
@@ -2247,7 +2246,7 @@ impl Sandbox {
22472246
tools_ref.dispatch(&payload)
22482247
})?;
22492248

2250-
Self::finish_evolve(usbox, None, 0, exit_code, sleep_cancel, socket_table)
2249+
Self::finish_evolve(usbox, None, exit_code, sleep_cancel, socket_table)
22512250
}
22522251

22532252
/// Low-level: boot with a zero-copy mapped initrd file. Prefer the builder.
@@ -2304,7 +2303,6 @@ impl Sandbox {
23042303
Self::finish_evolve(
23052304
usbox,
23062305
initrd_path.map(|p| p.to_path_buf()),
2307-
INITRD_MAP_BASE,
23082306
exit_code,
23092307
sleep_cancel,
23102308
socket_table,
@@ -2314,7 +2312,6 @@ impl Sandbox {
23142312
fn finish_evolve(
23152313
usbox: UninitializedSandbox,
23162314
file_mapping_path: Option<std::path::PathBuf>,
2317-
file_mapping_base: u64,
23182315
exit_code: Arc<AtomicI32>,
23192316
sleep_cancel: SleepCancel,
23202317
socket_table: Option<Arc<Mutex<SocketTable>>>,
@@ -2325,7 +2322,6 @@ impl Sandbox {
23252322
inner,
23262323
snapshot,
23272324
file_mapping_path,
2328-
file_mapping_base,
23292325
exit_code,
23302326
socket_table,
23312327
sleep_cancel,
@@ -2338,15 +2334,12 @@ impl Sandbox {
23382334
/// guest memory to the state captured after init.
23392335
pub fn restore(&mut self) -> Result<()> {
23402336
if let Some(ref snap) = self.snapshot {
2341-
self.inner.restore(snap.clone())?;
2342-
}
2343-
// Re-register file mapping after restore (snapshot restore
2344-
// unmaps all non-snapshot regions including file mappings)
2345-
if let Some(ref path) = self.file_mapping_path {
2346-
self.inner
2347-
.map_file_cow(path, self.file_mapping_base, Some("initrd"))?;
2337+
if self.file_mapping_path.is_some() {
2338+
self.inner.restore_preserving_file_mappings(snap.clone())?;
2339+
} else {
2340+
self.inner.restore(snap.clone())?;
2341+
}
23482342
}
2349-
// Close leaked host-side sockets the guest "forgot" about.
23502343
if let Some(ref table) = self.socket_table {
23512344
table.lock().unwrap().clear();
23522345
}
@@ -2543,7 +2536,6 @@ impl Sandbox {
25432536
inner,
25442537
snapshot: Some(arc),
25452538
file_mapping_path: initrd,
2546-
file_mapping_base: INITRD_MAP_BASE,
25472539
exit_code,
25482540
socket_table,
25492541
sleep_cancel,

0 commit comments

Comments
 (0)