Repository navigation
fix(hypervisors): correct memory unit conversion and validation - #826
Nachiket-Roy wants to merge 1 commit into
Conversation
👷 Deploy Preview for urunc processing.
|
✅ Deploy Preview for urunc canceled.
|
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days. |
|
Hello @Nachiket-Roy , can you bring this up-to-date with main? |
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>
92fab26 to
6731e28
Compare
👷 Deploy request for urunc pending review.Visit the deploys page to approve it
|
cmainas
left a comment
There was a problem hiding this comment.
Hello @Nachiket-Roy ,
the changes in this PR break cloud-hypervisor and Qemu which now do not boot. Please test your changes before opening a PR or pushing any changes in a PR.
Some generic comments for this PR:
- Since Firecracker and Solo5 use MiB by default, we can use this unit for all monitors.
- One monitor hyperlight-unikraft is missing.
- The handling of less than 1MiB memory should be uniform across all implementations. Qemu and CLoud-hypervisor have different behavior than Solo5 and Firecracker.
- We should end up with a single function to handle memory with all rules applied in that function and only there. All other functions should get removed/replaced.
| } | ||
|
|
||
| // Memory configuration | ||
| memSize := args.MemSizeB |
There was a problem hiding this comment.
Memory for cloud-hypervisor should be a multiple of a page size. As a result, passing 1G as memory limit the cli option will become size=1000000000, which will fail the booting in cloud-hypervisor. See https://github.com/cloud-hypervisor/cloud-hypervisor/blob/v54.1/vmm/src/memory_manager.rs#L686
| func (h *HVT) BuildExecCmd(args types.ExecArgs, ukernel types.Unikernel) ([]string, error) { | ||
| hvtMem := BytesToStringMB(args.MemSizeB) | ||
| hvtMem := BytesToMiBString(args.MemSizeB) | ||
| if args.MemSizeB > 0 && args.MemSizeB < 1024*1024 { |
There was a problem hiding this comment.
This check should be inside BytesToMiBString.
| hvtMem := BytesToMiBString(args.MemSizeB) | ||
| if args.MemSizeB > 0 && args.MemSizeB < 1024*1024 { | ||
| hvtMem = "1" | ||
| vmmLog.Warnf("Requested memory (%d bytes) is below Solo5's minimum unit (1 MiB); clamping to 1 MiB", args.MemSizeB) |
There was a problem hiding this comment.
Use a different word than "clamping"
| exArgs := []string{ | ||
| q.binaryPath, | ||
| "-m", qemuMem + "M", | ||
| "-m", qemuMem + "B", |
There was a problem hiding this comment.
Qemu rounds up the memory to a multiple of 8KiB See https://github.com/qemu/qemu/blob/v11.1.3/hw/core/machine.c#L600 but it does not do the same for memory-backend-file and therefore these might end up different. Please use MiB everywhere.
| name: "custom memory sub-1-MiB clamps to 1 MiB", | ||
| args: types.ExecArgs{UnikernelPath: testKernelPath, MemSizeB: 512 * 1024}, | ||
| unikernel: &fakeUnikernel{}, | ||
| mustContain: []string{"--mem=1"}, |
There was a problem hiding this comment.
This should be change to an exact match because the current check will also get cases like --mem=10
| return ch.binaryPath | ||
| } | ||
|
|
||
| // BuildExecCmd builds and validates the Cloud Hypervisor command arguments without executing. |
| input uint64 | ||
| expected string | ||
| }{ | ||
| {"zero (Case A)", 0, "268435456"}, // 256 MB * 1024 * 1024 |
| func bytesToMB(bytes uint64) uint64 { | ||
| const bytesInMB = 1000 * 1000 | ||
| return bytes / bytesInMB | ||
| func BytesToBString(argMem uint64) string { |
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
0were treated as unspecified and silently replaced withDefaultMemory(256MB).This PR updates each backend to use the most accurate representation it supports:
-m <bytes>B).--memory size=<bytes>).1 MiBto the minimum representable value.1 MiBto satisfy its CLI validation.An unspecified (
0) memory request continues to fall back toDefaultMemory, while valid non-zero requests are preserved as accurately as each monitor allows.Related issues
How was this tested?
go test -v ./pkg/....LLM usage
Claude (Anthropic) Sonnet 5 was used to discuss implementation trade-offs. All implementation details and behavior were independently verified through source inspection, documentation, and runtime testing.
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).