kvm: limit number of vCPU-s

We see a regression of the startup benchmark. The main reason is that the
maximum number of vCPUs in the kernel has been increased from 256 to 1024. In
most cases, we don't need so many vCPU-s.

PiperOrigin-RevId: 462455491
This commit is contained in:
Andrei Vagin
2022-07-21 13:20:03 -07:00
committed by gVisor bot
parent 1f2b30d70c
commit 796050f1da
+11
View File
@@ -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 {