diff options
author | Lingfu <shanks.cyp@gmail.com> | 2018-09-19 13:34:28 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-09-19 13:35:42 -0700 |
commit | f0a92b6b67382a1f8da5ef2622c59afdb1c40f13 (patch) | |
tree | 451879158e08d1ad8d08782353e8d95c752ac208 /runsc/boot/loader.go | |
parent | bd12e952479dead5adc84a611ee21ab76ce1b100 (diff) |
Add docker command line args support for --cpuset-cpus and --cpus
`docker run --cpuset-cpus=/--cpus=` will generate cpu resource info in config.json
(runtime spec file). When nginx worker_connections is configured as auto, the worker is
generated according to the number of CPUs. If the cgroup is already set on the host, but
it is not displayed correctly in the sandbox, performance may be degraded.
This patch can get cpus info from spec file and apply to sentry on bootup, so the
/proc/cpuinfo can show the correct cpu numbers. `lscpu` and other commands rely on
`/sys/devices/system/cpu/online` are also affected by this patch.
e.g.
--cpuset-cpus=2,3 -> cpu number:2
--cpuset-cpus=4-7 -> cpu number:4
--cpus=2.8 -> cpu number:3
--cpus=0.5 -> cpu number:1
Change-Id: Ideb22e125758d4322a12be7c51795f8018e3d316
PiperOrigin-RevId: 213685199
Diffstat (limited to 'runsc/boot/loader.go')
-rw-r--r-- | runsc/boot/loader.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index 623d04171..f906c9f95 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -20,7 +20,6 @@ import ( "math/rand" "os" "os/signal" - "runtime" "sync" "sync/atomic" "syscall" @@ -201,15 +200,20 @@ func New(spec *specs.Spec, conf *Config, controllerFD, deviceFD int, ioFDs []int caps, auth.NewRootUserNamespace()) + // Get CPU numbers from spec. + cpuNum, err := specutils.CalculateCPUNumber(spec) + if err != nil { + return nil, fmt.Errorf("cannot get cpus from spec: %v", err) + } + // Initiate the Kernel object, which is required by the Context passed // to createVFS in order to mount (among other things) procfs. if err = k.Init(kernel.InitKernelArgs{ - FeatureSet: cpuid.HostFeatureSet(), - Timekeeper: tk, - RootUserNamespace: creds.UserNamespace, - NetworkStack: networkStack, - // TODO: use number of logical processors from cgroups. - ApplicationCores: uint(runtime.NumCPU()), + FeatureSet: cpuid.HostFeatureSet(), + Timekeeper: tk, + RootUserNamespace: creds.UserNamespace, + NetworkStack: networkStack, + ApplicationCores: uint(cpuNum), Vdso: vdso, RootUTSNamespace: kernel.NewUTSNamespace(spec.Hostname, "", creds.UserNamespace), RootIPCNamespace: kernel.NewIPCNamespace(creds.UserNamespace), |