Files
devvm/internal/backend/docker
w3cjandClaude Opus 5.5 d55dae5386 fix(build): fit base's CPUs to the host, as its memory is
Base asked for base.yaml's 4 CPUs whatever the host had. It now gets
base.yaml's CPUs, or the host's count when the host has fewer, by the
same shared rule as its memory.

What happens above the host's count (from published docs, not checked
on a VM):
- Lima accepts cpus above the host's count: its template's default is
  min(4, host CPU cores), and its proposed check that refused more than
  runtime.NumCPU() (lima-vm/lima#2309) was closed unmerged. On vz, a
  VM given more CPUs than the Mac has can start so slowly that ssh never
  comes up (lima-vm/lima#1621, open).
- Apple's Virtualization framework only requires cpuCount <=
  VZVirtualMachineConfiguration.maximumAllowedCPUCount, whose docs don't
  tie it to the host's count.
- smolvm and libkrun document no limit for --cpus.
- Docker refuses --cpus above its engine's machine's count ("Range of
  CPUs is from 0.01 to N.00, as there are only N CPUs available").

Changes:
- internal/backend/fit.go: FitCPUs(want, hostCPUs int) int and
  FitMemory(wantGiB float64, hostBytes uint64) float64, pure and
  exported; fitMemory's rule moved there from Lima, with table tests.
- Lima: buildSize replaces buildMemory and reads base.yaml's cpus and
  memory; limactl create gets --cpus and --memory for base and the
  --from conversion VM (createArgs). A CPUs field (runtime.NumCPU) is
  the host-CPU seam beside Memory.
- smolvm: baseSize fits CPUs and memory with the shared rules, for
  base's build, tool builds and VMs given no size; a CPUs field is the
  seam. spec.Size.CPUs still wins.
- Docker: the engine's NCPU is read from docker info beside MemTotal
  (engineSize replaces engineMemory), and baseSize fits both.
- Image keys are unchanged: neither the fitted memory nor CPUs are in
  them.
- Tests: TestFitCPUs, TestFitMemory, Lima's TestBuildImageSmallHost and
  "no CPUs" case, smolvm's TestSmallHost, Docker's TestBaseSize; the
  build and from testscripts expect --cpus.
- Docs: using/ports-size.md and using/images.md say what a small
  machine gets; internals/images.md has a Base's size section on the
  mechanism; internals/smolvm.md and internals/docker.md match it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-30 17:55:30 -07:00
..