Skip to content

Commit 1caba5c

Browse files
authored
feat: use hyperlight-host 0.16.0 from crates.io (#99)
* feat: adapt to hyperlight-host 0.16.0 from crates.io Switch from git dep (danbugs/hyperlight) to crates.io hyperlight-host 0.16.0. Key API changes: - Snapshot format: to_file/from_file_unchecked -> OCI save/load - snapshot.hls (single file) -> snapshot/ (OCI dir) - map_file_cow: 3-arg -> 2-arg (label param removed) - restore_preserving_file_mappings removed; re-map initrd after restore - Remove sparsify_snapshot (OCI format handles storage) - Remove whp-no-surrogate feature (now runtime env var) - Add max_surrogates API to configure_surrogates/InstallOptions/Runtime - Reduce default heap from 2560 MiB to 1280 MiB Signed-off-by: danbugs <danilochiarlone@gmail.com> * fix: remove extra blank line (fmt) Signed-off-by: danbugs <danilochiarlone@gmail.com> * fix: check index.json for OCI snapshot validity Address Copilot review: check snapshot/index.json instead of just testing snapshot/ directory existence. Catches interrupted installs and incomplete OCI layouts with an actionable error message. Signed-off-by: danbugs <danilochiarlone@gmail.com> * fix: re-add OCI blob sparsification for snapshot disk usage The OCI snapshot format writes guest memory as a dense raw blob. With CONFIG_PAGING=n in our Unikraft build, the heap pages retain their boot-time PTEs so the snapshot captures the full 1280 MiB heap even if most pages are untouched. Post-save sparsification punches holes in zero-filled 4K regions, reducing disk usage from ~1755 MiB back to ~656 MiB. Linux uses fallocate(PUNCH_HOLE), Windows uses FSCTL_SET_ZERO_DATA. Signed-off-by: danbugs <danilochiarlone@gmail.com> * fix: report real disk usage for sparse snapshots on Windows Use GetCompressedFileSizeW to measure actual on-disk allocation instead of apparent file size, so Windows benchmark reports match Linux (which already uses stat block count). Signed-off-by: danbugs <danilochiarlone@gmail.com> --------- Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 0350d64 commit 1caba5c

10 files changed

Lines changed: 463 additions & 220 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ jobs:
287287
- name: "Snapshot size"
288288
if: steps.kvm_check.outputs.available == 'true'
289289
run: |
290-
snap=".pyhl/snapshot.hls"
291-
apparent=$(($(stat -c '%s' "$snap") / 1024 / 1024))
292-
disk=$(($(stat -c '%b' "$snap") * 512 / 1024 / 1024))
290+
snap=".pyhl/snapshot"
291+
apparent=$(($(find "$snap" -type f -exec stat -c '%s' {} + | paste -sd+ | bc) / 1024 / 1024))
292+
disk=$(($(find "$snap" -type f -exec stat -c '%b' {} + | paste -sd+ | bc) * 512 / 1024 / 1024))
293293
echo "| Metric | Value |"
294294
echo "|--------|-------|"
295295
echo "| Apparent size | ${apparent} MiB |"
@@ -483,27 +483,29 @@ jobs:
483483
- name: "Snapshot size"
484484
shell: pwsh
485485
run: |
486-
$snap = ".pyhl\snapshot.hls"
487-
$f = Get-Item $snap
488-
$apparentMiB = [math]::Round($f.Length / 1MB)
489-
# GetCompressedFileSize returns actual on-disk allocation for sparse files
490-
$wide = $f.FullName
491486
Add-Type -TypeDefinition @"
492487
using System;
493488
using System.Runtime.InteropServices;
494-
public class SparseHelper {
495-
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
496-
public static extern uint GetCompressedFileSizeW(string lpFileName, out uint lpFileSizeHigh);
489+
public class SparseFileHelper {
490+
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
491+
public static extern uint GetCompressedFileSizeW(string lpFileName, out uint lpFileSizeHigh);
497492
}
498-
"@ -ErrorAction SilentlyContinue
499-
$high = [uint32]0
500-
$low = [SparseHelper]::GetCompressedFileSizeW($wide, [ref]$high)
501-
if ($low -ne [uint32]::MaxValue) {
502-
$diskBytes = ([uint64]$high -shl 32) -bor [uint64]$low
503-
$diskMiB = [math]::Round($diskBytes / 1MB)
504-
} else {
505-
$diskMiB = $apparentMiB
493+
"@
494+
function Get-CompressedSize($path) {
495+
$high = [uint32]0
496+
$low = [SparseFileHelper]::GetCompressedFileSizeW($path, [ref]$high)
497+
if ($low -eq 0xFFFFFFFF) {
498+
$err = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
499+
if ($err -ne 0) { return (Get-Item $path).Length }
500+
}
501+
return ([uint64]$high -shl 32) -bor [uint64]$low
506502
}
503+
$snap = ".pyhl\snapshot"
504+
$files = Get-ChildItem -Path $snap -Recurse -File
505+
$apparentMiB = [math]::Round(($files | Measure-Object -Property Length -Sum).Sum / 1MB)
506+
$diskBytes = [uint64]0
507+
foreach ($f in $files) { $diskBytes += Get-CompressedSize $f.FullName }
508+
$diskMiB = [math]::Round($diskBytes / 1MB)
507509
Write-Host "| Metric | Value |"
508510
Write-Host "|--------|-------|"
509511
Write-Host "| Apparent size | ${apparentMiB} MiB |"

0 commit comments

Comments
 (0)