diff --git a/pkg/sentry/platform/kvm/machine_amd64.go b/pkg/sentry/platform/kvm/machine_amd64.go index c99009f0d..fa3152cd3 100644 --- a/pkg/sentry/platform/kvm/machine_amd64.go +++ b/pkg/sentry/platform/kvm/machine_amd64.go @@ -21,6 +21,7 @@ import ( "fmt" "math/big" "reflect" + "runtime" "runtime/debug" "golang.org/x/sys/unix" @@ -478,6 +479,16 @@ func (m *machine) getMaxVCPU() { } else { m.maxVCPUs = int(maxVCPUs) } + + // The goal here is to avoid vCPU contentions for reasonable workloads. + // But "reasonable" isn't defined well in this case. Let's say that CPU + // overcommit with factor 2 is still acceptable. We allocate a set of + // vCPU for each goruntime processor (P) and two sets of vCPUs to run + // user code. + rCPUs := runtime.GOMAXPROCS(0) + if 3*rCPUs < m.maxVCPUs { + m.maxVCPUs = 3 * rCPUs + } } func archPhysicalRegions(physicalRegions []physicalRegion) []physicalRegion {