vm: derive host CPU capacity from online cores, not process affinity - #190
Merged
Conversation
runtime.NumCPU reports the calling process's affinity mask, so a core-pinned control plane rejected multi-vCPU creates/clones/restores and collapsed CH's hotplug ceiling to max=1. HostCPUCount reads /sys/devices/system/cpu/online (NumCPU fallback where unavailable); process-concurrency pools intentionally keep NumCPU.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #189.
runtime.NumCPU()returns the size of the calling process's CPU affinity mask, not the machine's core count. A control plane pinned to a reserved core (systemd-run -p AllowedCPUs=383 cocoon vm clone ...— the shape acgroup_cpusfence deployment invites) therefore:requested 2 vCPUs exceeds host cores (1)--cpus max=1for every VM it launchedHostCPUCount()reads/sys/devices/system/cpu/online(affinity-independent, parsed with the existingcgroup.ParseCPUList) and falls back toruntime.NumCPU()where the file is unavailable (darwin). Both guest-facing sites —ValidateHostCPUandbuildVMConfig— now use it. The process-concurrency sites (pool_sizedefault, sqlite reader pool,PoolSizeOrDefault) intentionally keepruntime.NumCPU: affinity is the correct sizing for the process's own workers.The fence width is deliberately not a ceiling: vCPU overcommit against the fence is legitimate (many VMs already sum past it), so the validation keeps its original meaning — reject configs that exceed the machine.
Hot-path cost: one small sysfs read per create/clone/restore/launch, dwarfed by the fork/exec and snapshot I/O around it; no caching, so CPU hotplug is always seen fresh.
Verification on a 384-core linux/amd64 host:
The pinned row is exactly the #189 failure shape: the old code compared against 1, the new code sees the machine.
Gates:
make lint(both GOOS) 0 issues,asl ./...(both GOOS) clean,go test ./...34 packages ok.