Skip to content

Commit 20ccc2d

Browse files
authored
Reduce default --memory to 32Mi, set examples to measured minimums (#77)
* reduce default memory from 512Mi to 64Mi every example already specifies its own --memory value in its Justfile, so nothing depends on the CLI default. 64Mi comfortably covers the lightweight examples (helloworld-c needs 4Mi, rust/go/dotnet/shell need 16Mi) while heavier workloads (python 512Mi, powershell 1Gi) continue to set their own. Signed-off-by: danbugs <danilochiarlone@gmail.com> * set example memory to measured minimums, derive CI values from Justfiles binary-searched the minimum --memory each example needs to produce its expected output: helloworld-c: 2Mi rust: 16Mi go: 16Mi shell: 16Mi dotnet: 16Mi dotnet-nativeaot: 8Mi hostfs-posix-c: 2Mi hostfs-posix-py: 512Mi python: 512Mi python-tools: 512Mi nodejs: 512Mi powershell: 1Gi networking-py: 32Mi python-agent: 1Gi update each example's Justfile to use its measured minimum, and have CI read the memory value from the Justfile instead of hardcoding it in the workflow matrix. this makes the Justfile the single source of truth. also fixes two under-provisioned examples that were silently relying on headroom: hostfs-posix-py (was 96Mi, needs 512Mi) and python-tools (was 96Mi, needs 512Mi). lower the CLI default from 512Mi to 32Mi — covers every lightweight example with headroom while giving an honest signal that heavy runtimes (python, nodejs, powershell) need explicit --memory. Signed-off-by: danbugs <danilochiarlone@gmail.com> --------- Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 7b07be6 commit 20ccc2d

8 files changed

Lines changed: 38 additions & 45 deletions

File tree

.github/workflows/test-examples.yml

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ jobs:
153153
# Full matrix — every example actually runs and its expected output is
154154
# greped from the guest console. This is the real regression gate;
155155
# build-example above only catches link-time errors.
156+
#
157+
# Memory values are read from each example's Justfile at runtime
158+
# (the `memory` variable), so the matrix only carries args/expect.
156159
runtime-test:
157160
runs-on: ubuntu-latest
158161
needs: build-example
@@ -165,76 +168,59 @@ jobs:
165168
matrix:
166169
include:
167170
- example: helloworld-c
168-
memory: "4Mi"
169171
args: ""
170172
expect: "Hello from C on Hyperlight"
171173
- example: rust
172-
memory: "16Mi"
173174
args: ""
174175
expect: "Hello from Rust on Hyperlight"
175176
- example: go
176-
memory: "96Mi"
177177
args: ""
178178
expect: "Hello from Go on Hyperlight"
179179
- example: shell
180-
memory: "16Mi"
181180
args: "-- /demo.sh"
182181
expect: "Hello from Shell on Hyperlight"
183182
- example: python
184-
memory: "512Mi"
185183
args: "-- /hello.py"
186184
expect: "Hello from Python on Hyperlight"
187185
- example: python-tools
188-
memory: "1Gi"
189186
args: "--enable-tools -- /test_tools.py"
190187
expect: "Tool returned"
191188
- example: nodejs
192-
memory: "512Mi"
193189
args: "-- /app/hello.js"
194190
expect: "Hello from Node.js on Hyperlight"
195191
- example: dotnet
196-
memory: "512Mi"
197192
args: ""
198193
expect: "Hello, World! From .NET on Hyperlight"
199194
- example: dotnet-nativeaot
200-
memory: "512Mi"
201195
args: ""
202196
expect: "Hello, World! From .NET NativeAOT on Hyperlight"
203197
- example: hostfs-posix-c
204-
memory: "16Mi"
205198
args: ""
206199
expect: "done\\."
207200
needs_mount: true
208201
- example: hostfs-posix-py
209-
memory: "512Mi"
210202
args: "-- /hostfs_demo.py"
211203
expect: "done\\."
212204
needs_mount: true
213205
- example: multifn-c
214-
memory: "4Mi"
215206
args: ""
216207
expect: "RUN: world"
217208
driver: multifn-test
218209
- example: python-agent
219-
memory: "1Gi"
220210
args: "-- /agent.py"
221211
expect: "done\\."
222212
needs_mount: true
223213
- example: python-agent-driver
224-
memory: "2Gi"
225214
args: ""
226215
expect: "hello from driver"
227216
driver: pydriver-run
228217
- example: powershell
229-
memory: "1Gi"
230218
args: "-- -NoProfile -File /scripts/hello.ps1"
231219
expect: "Hello, World! From PowerShell on Hyperlight"
232220
- example: networking-py
233-
memory: "512Mi"
234221
args: "--net -- /urllib_get.py"
235222
expect: "SUCCESS: urllib GET worked!"
236223
- example: networking-py
237-
memory: "512Mi"
238224
args: "--port 8080 -- /echo_server_test.py"
239225
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
240226
steps:
@@ -340,6 +326,11 @@ jobs:
340326
ls -la .unikraft/build/ *.cpio 2>&1 | head -40 || true
341327
exit 1
342328
fi
329+
# Read memory from the example's Justfile (single source of truth).
330+
memory=$(grep '^memory' Justfile | sed 's/memory.*:= *"//' | sed 's/".*//')
331+
if [ -z "$memory" ]; then
332+
echo "::notice::No memory variable in Justfile, using binary default"
333+
fi
343334
expect='${{ matrix.expect }}'
344335
mount_args=""
345336
if [ "${{ matrix.needs_mount }}" = "true" ]; then
@@ -355,7 +346,11 @@ jobs:
355346
cmd=(timeout 120 /home/runner/work/hyperlight-unikraft/hyperlight-unikraft/host/target/release/pydriver-run "$kernel" "$cpio" /tmp/tiny.py)
356347
;;
357348
*)
358-
cmd=(timeout 120 hyperlight-unikraft -q -m "${{ matrix.memory }}" "$kernel" --initrd "$cpio" $mount_args ${{ matrix.args }})
349+
mem_args=""
350+
if [ -n "$memory" ]; then
351+
mem_args="-m $memory"
352+
fi
353+
cmd=(timeout 120 hyperlight-unikraft -q $mem_args "$kernel" --initrd "$cpio" $mount_args ${{ matrix.args }})
359354
;;
360355
esac
361356
set +e
@@ -490,6 +485,8 @@ jobs:
490485
# The only difference is we can't build the images on Windows (no
491486
# kraft-hyperlight + no Linux docker), so we download them from the
492487
# package-images-for-windows job.
488+
#
489+
# Memory values are read from each example's Justfile at runtime.
493490
runtime-test-windows:
494491
runs-on: windows-latest
495492
needs: package-images-for-windows
@@ -502,76 +499,59 @@ jobs:
502499
matrix:
503500
include:
504501
- example: helloworld-c
505-
memory: "4Mi"
506502
args: ""
507503
expect: "Hello from C on Hyperlight"
508504
- example: rust
509-
memory: "16Mi"
510505
args: ""
511506
expect: "Hello from Rust on Hyperlight"
512507
- example: go
513-
memory: "96Mi"
514508
args: ""
515509
expect: "Hello from Go on Hyperlight"
516510
- example: shell
517-
memory: "16Mi"
518511
args: "-- /demo.sh"
519512
expect: "Hello from Shell on Hyperlight"
520513
- example: python
521-
memory: "512Mi"
522514
args: "-- /hello.py"
523515
expect: "Hello from Python on Hyperlight"
524516
- example: python-tools
525-
memory: "1Gi"
526517
args: "--enable-tools -- /test_tools.py"
527518
expect: "Tool returned"
528519
- example: nodejs
529-
memory: "512Mi"
530520
args: "-- /app/hello.js"
531521
expect: "Hello from Node.js on Hyperlight"
532522
- example: dotnet
533-
memory: "512Mi"
534523
args: ""
535524
expect: "Hello, World! From .NET on Hyperlight"
536525
- example: dotnet-nativeaot
537-
memory: "512Mi"
538526
args: ""
539527
expect: "Hello, World! From .NET NativeAOT on Hyperlight"
540528
- example: hostfs-posix-c
541-
memory: "16Mi"
542529
args: ""
543530
expect: "done\\."
544531
needs_mount: true
545532
- example: hostfs-posix-py
546-
memory: "512Mi"
547533
args: "-- /hostfs_demo.py"
548534
expect: "done\\."
549535
needs_mount: true
550536
- example: multifn-c
551-
memory: "4Mi"
552537
args: ""
553538
expect: "RUN: world"
554539
driver: multifn-test
555540
- example: python-agent
556-
memory: "1Gi"
557541
args: "-- /agent.py"
558542
expect: "done\\."
559543
needs_mount: true
560544
- example: python-agent-driver
561-
memory: "2Gi"
562545
args: ""
563546
expect: "hello from driver"
564547
driver: pydriver-run
565548
- example: powershell
566-
memory: "1Gi"
567549
args: "-- -NoProfile -File /scripts/hello.ps1"
568550
expect: "Hello, World! From PowerShell on Hyperlight"
569551
- example: networking-py
570-
memory: "512Mi"
571552
args: "--net -- /urllib_get.py"
572553
expect: "SUCCESS: urllib GET worked!"
573554
- example: networking-py
574-
memory: "512Mi"
575555
args: "--port 8080 -- /echo_server_test.py"
576556
expect: "SUCCESS: bind\\+listen on port 8080 allowed"
577557
steps:
@@ -614,10 +594,19 @@ jobs:
614594
$cpio = (Resolve-Path "image/initrd.cpio").Path
615595
$expect = '${{ matrix.expect }}'
616596
$driver = '${{ matrix.driver }}'
617-
$memory = '${{ matrix.memory }}'
618597
$runArgs = '${{ matrix.args }}'
619598
$needsMount = '${{ matrix.needs_mount }}'
620599
600+
# Read memory from the example's Justfile (single source of truth).
601+
$memory = ''
602+
$justfile = "examples/${{ matrix.example }}/Justfile"
603+
if (Test-Path $justfile) {
604+
$memLine = Get-Content $justfile | Where-Object { $_ -match '^\s*memory\s*:=' }
605+
if ($memLine -match '"([^"]+)"') {
606+
$memory = $Matches[1]
607+
}
608+
}
609+
621610
$mountArgs = @()
622611
if ($needsMount -eq 'true') {
623612
$mountDir = Join-Path $env:RUNNER_TEMP ('hostfs-' + '${{ matrix.example }}')
@@ -649,7 +638,11 @@ jobs:
649638
if ($runArgs -ne '') {
650639
$argList = $runArgs.Split(' ') | Where-Object { $_ -ne '' }
651640
}
652-
$out = & hyperlight-unikraft -q -m $memory `
641+
$memArgs = @()
642+
if ($memory -ne '') {
643+
$memArgs = @('-m', $memory)
644+
}
645+
$out = & hyperlight-unikraft -q @memArgs `
653646
$kernel --initrd $cpio @mountArgs @argList 2>&1
654647
$rc = $LASTEXITCODE
655648
}

examples/dotnet-nativeaot/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export DOCKER_BUILDKIT := "0"
1111

1212
kernel := ".unikraft/build/dotnet-nativeaot-hyperlight_hyperlight-x86_64"
1313
initrd := "hello-initrd.cpio"
14-
memory := "16Mi"
14+
memory := "8Mi"
1515
image := "dotnet-nativeaot-hyperlight"
1616
ghcr_kernel := "ghcr.io/hyperlight-dev/hyperlight-unikraft/dotnet-nativeaot-kernel:latest"
1717

examples/helloworld-c/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export DOCKER_BUILDKIT := "0"
1111

1212
kernel := ".unikraft/build/helloworld-hyperlight_hyperlight-x86_64"
1313
initrd := "hello-initrd.cpio"
14-
memory := "4Mi"
14+
memory := "2Mi"
1515
image := "helloworld-c-hyperlight"
1616
ghcr_kernel := "ghcr.io/hyperlight-dev/hyperlight-unikraft/helloworld-c-kernel:latest"
1717

examples/hostfs-posix-c/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export DOCKER_BUILDKIT := "0"
88

99
kernel := ".unikraft/build/hostfs-posix-c-hyperlight_hyperlight-x86_64"
1010
initrd := "hostfs-posix-c-initrd.cpio"
11-
memory := "16Mi"
11+
memory := "2Mi"
1212
image := "hostfs-posix-c-hyperlight"
1313
ghcr_kernel := "ghcr.io/hyperlight-dev/hyperlight-unikraft/hostfs-posix-c-kernel:latest"
1414
mount_dir := "./work"

examples/hostfs-posix-py/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export DOCKER_BUILDKIT := "0"
88

99
kernel := ".unikraft/build/hostfs-posix-py-hyperlight_hyperlight-x86_64"
1010
initrd := "hostfs-posix-py-initrd.cpio"
11-
memory := "96Mi"
11+
memory := "512Mi"
1212
image := "hostfs-posix-py-hyperlight"
1313
ghcr_kernel := "ghcr.io/hyperlight-dev/hyperlight-unikraft/hostfs-posix-py-kernel:latest"
1414
mount_dir := "./work"

examples/networking-py/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export DOCKER_BUILDKIT := "0"
1111

1212
kernel := ".unikraft/build/networking-py-hyperlight_hyperlight-x86_64"
1313
initrd := "initrd.cpio"
14-
memory := "512Mi"
14+
memory := "32Mi"
1515
image := "networking-py-hyperlight"
1616

1717
# Run HTTP GET test (raw sockets)

examples/python-tools/Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export DOCKER_BUILDKIT := "0"
1111

1212
kernel := ".unikraft/build/python-tools-hyperlight_hyperlight-x86_64"
1313
initrd := "initrd.cpio"
14-
memory := "96Mi"
14+
memory := "512Mi"
1515
image := "python-tools-hyperlight"
1616
ghcr_kernel := "ghcr.io/hyperlight-dev/hyperlight-unikraft/python-tools-kernel:latest"
1717

host/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ struct Args {
2727
#[arg(long)]
2828
initrd: Option<PathBuf>,
2929

30-
/// Memory allocation (e.g., 256Mi, 512Mi, 1Gi)
31-
#[arg(long, short = 'm', default_value = "512Mi")]
30+
/// Memory allocation (e.g., 32Mi, 256Mi, 1Gi)
31+
#[arg(long, short = 'm', default_value = "32Mi")]
3232
memory: String,
3333

3434
/// Stack size (e.g., 8Mi)

0 commit comments

Comments
 (0)