diff options
author | gVisor bot <gvisor-bot@google.com> | 2019-12-17 23:21:18 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-17 23:21:18 +0000 |
commit | 7868f5a23b07ec1057e2ef34a7b526708f04bd28 (patch) | |
tree | 99865103d693fcd1ab85ce635b7b9753e9a128b1 /runsc/sandbox | |
parent | 10ff034b94702f317135ce51a52b3d19236f2594 (diff) | |
parent | 725e73eed081a5a063054511da63d0771f6705a1 (diff) |
Merge release-20191210.0-46-g725e73e (automated)
Diffstat (limited to 'runsc/sandbox')
-rw-r--r-- | runsc/sandbox/sandbox.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 805233184..ce1452b87 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -18,6 +18,7 @@ package sandbox import ( "context" "fmt" + "math" "os" "os/exec" "strconv" @@ -631,6 +632,26 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF if err != nil { 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 < minCPUs { + n = minCPUs + } + if n < cpuNum { + // Only lower the cpu number. + cpuNum = n + } + } + } cmd.Args = append(cmd.Args, "--cpu-num", strconv.Itoa(cpuNum)) mem, err := s.Cgroup.MemoryLimit() |