Skip to content

fix(hypervisors): correct memory unit conversion and validation#826

Open
Nachiket-Roy wants to merge 1 commit into
urunc-dev:mainfrom
Nachiket-Roy:fix/memory-conversion-and-validation
Open

fix(hypervisors): correct memory unit conversion and validation#826
Nachiket-Roy wants to merge 1 commit into
urunc-dev:mainfrom
Nachiket-Roy:fix/memory-conversion-and-validation

Conversation

@Nachiket-Roy

@Nachiket-Roy Nachiket-Roy commented Jul 15, 2026

Copy link
Copy Markdown

Description

This PR fixes the memory handling issues reported in #818 and #819 by replacing the previous global conversion with monitor-specific handling.

Previously, OCI memory limits were converted using decimal MB for all monitors, which could cause the guest to receive more memory than requested. Additionally, requests that rounded to 0 were treated as unspecified and silently replaced with DefaultMemory (256MB).

This PR updates each backend to use the most accurate representation it supports:

  • QEMU: pass exact byte values (-m <bytes>B).
  • Cloud Hypervisor: pass exact byte values (--memory size=<bytes>).
  • Firecracker: convert to MiB and clamp values below 1 MiB to the minimum representable value.
  • Solo5: convert to MiB and clamp values below 1 MiB to satisfy its CLI validation.

An unspecified (0) memory request continues to fall back to DefaultMemory, while valid non-zero requests are preserved as accurately as each monitor allows.

Related issues

How was this tested?

  • Verified each monitor's supported memory units from its implementation and documentation.
  • Boot-tested QEMU, Cloud Hypervisor, Firecracker, and Solo5 with real guest images.
  • Confirmed QEMU and Cloud Hypervisor preserve exact byte values end-to-end.
  • Added unit tests for the new conversion helpers and updated QEMU tests.
  • Ran go test -v ./pkg/....

LLM usage

Claude (Anthropic) was used to discuss implementation trade-offs. All implementation details and behavior were independently verified through source inspection, documentation, and runtime testing.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

Update various VMM backends (QEMU, Firecracker, HVT, SPT, and Cloud
Hypervisor) to correctly convert and validate memory sizes to their
expected units (bytes/MiB) instead of MB.

- QEMU and Cloud Hypervisor now use raw bytes.
- Firecracker, HVT, and SPT now use MiB.
- Low memory values (<1 MiB) for Solo5 (HVT/SPT) and Firecracker
  are clamped to 1 MiB instead of falling back to default 256 MiB.
- Replace utility BytesToStringMB with BytesToBString and
  BytesToMiBString, and update tests accordingly.

Fixes: urunc-dev#818
Fixes: urunc-dev#819

Signed-off-by: Nachiket Roy <nachiket.roy.2@gmail.com>
@netlify

netlify Bot commented Jul 15, 2026

Copy link
Copy Markdown

👷 Deploy Preview for urunc processing.

Name Link
🔨 Latest commit 92fab26
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a5798d7f2549900089a4474

@netlify

netlify Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 92fab26
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a5798d7f2549900089a4474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant