mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Leave minimum CPU number as a constant
Remove introduced CPUNumMin config and hard-code it as 2.
This commit is contained in:
@@ -256,12 +256,6 @@ type Config struct {
|
||||
//
|
||||
// E.g. 0.2 CPU quota will result in 1, and 1.9 in 2.
|
||||
CPUNumFromQuota bool
|
||||
|
||||
// CPUNumMin is minimum value of CPU number setting when CPUNumFromQuota
|
||||
// strategy is active.
|
||||
//
|
||||
// E.g. when CPUNumMin is 2, 0.2 CPU quota will result in 2 instead of 1.
|
||||
CPUNumMin int
|
||||
}
|
||||
|
||||
// ToFlags returns a slice of flags that correspond to the given Config.
|
||||
@@ -295,9 +289,7 @@ func (c *Config) ToFlags() []string {
|
||||
"--overlayfs-stale-read=" + strconv.FormatBool(c.OverlayfsStaleRead),
|
||||
}
|
||||
if c.CPUNumFromQuota {
|
||||
f = append(f, "--cpu-num-from-quota",
|
||||
"--cpu-num-min="+strconv.Itoa(c.CPUNumMin),
|
||||
)
|
||||
f = append(f, "--cpu-num-from-quota")
|
||||
}
|
||||
// Only include these if set since it is never to be used by users.
|
||||
if c.TestOnlyAllowRunAsCurrentUserWithoutChroot {
|
||||
|
||||
+1
-3
@@ -82,8 +82,7 @@ var (
|
||||
numNetworkChannels = flag.Int("num-network-channels", 1, "number of underlying channels(FDs) to use for network link endpoints.")
|
||||
rootless = flag.Bool("rootless", false, "it allows the sandbox to be started with a user that is not root. Sandbox and Gofer processes may run with same privileges as current user.")
|
||||
referenceLeakMode = flag.String("ref-leak-mode", "disabled", "sets reference leak check mode: disabled (default), log-names, log-traces.")
|
||||
cpuNumFromQuota = flag.Bool("cpu-num-from-quota", false, "set cpu number to cpu quota (least integer greater or equal to quota value)")
|
||||
cpuNumMin = flag.Int("cpu-num-min", 2, "minimum number of cpu to use with --cpu-num-from-quota")
|
||||
cpuNumFromQuota = flag.Bool("cpu-num-from-quota", false, "set cpu number to cpu quota (least integer greater or equal to quota value, but not less than 2)")
|
||||
|
||||
// Test flags, not to be used outside tests, ever.
|
||||
testOnlyAllowRunAsCurrentUserWithoutChroot = flag.Bool("TESTONLY-unsafe-nonroot", false, "TEST ONLY; do not ever use! This skips many security measures that isolate the host from the sandbox.")
|
||||
@@ -228,7 +227,6 @@ func main() {
|
||||
ReferenceLeakMode: refsLeakMode,
|
||||
OverlayfsStaleRead: *overlayfsStaleRead,
|
||||
CPUNumFromQuota: *cpuNumFromQuota,
|
||||
CPUNumMin: *cpuNumMin,
|
||||
|
||||
TestOnlyAllowRunAsCurrentUserWithoutChroot: *testOnlyAllowRunAsCurrentUserWithoutChroot,
|
||||
TestOnlyTestNameEnv: *testOnlyTestNameEnv,
|
||||
|
||||
@@ -633,13 +633,18 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF
|
||||
return fmt.Errorf("getting cpu count from cgroups: %v", err)
|
||||
}
|
||||
if conf.CPUNumFromQuota {
|
||||
// Dropping below 2 CPUs can trigger application to disable
|
||||
// locks that can lead do hard to debug errors, so just
|
||||
// leaving two cores as reasonable default.
|
||||
const minCPUs = 2
|
||||
|
||||
quota, err := s.Cgroup.CPUQuota()
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting cpu qouta from cgroups: %v", err)
|
||||
}
|
||||
if n := int(math.Ceil(quota)); n > 0 {
|
||||
if n < conf.CPUNumMin {
|
||||
n = conf.CPUNumMin
|
||||
if n < minCPUs {
|
||||
n = minCPUs
|
||||
}
|
||||
if n < cpuNum {
|
||||
// Only lower the cpu number.
|
||||
|
||||
Reference in New Issue
Block a user