Implementing support for --cpu-rt-period and --cpu-rt-runtime so that

containers may specify these cgroup values at runtime. This will allow
processes to change their priority to real-time within the container
when CONFIG_RT_GROUP_SCHED is enabled in the kernel. See #22380.

Also added sanity checks for the new --cpu-rt-runtime and --cpu-rt-period
flags to ensure that that the kernel supports these features and that
runtime is not greater than period.

Daemon will support a --cpu-rt-runtime flag to initialize the parent
cgroup on startup, this prevents the administrator from alotting runtime
to docker after each restart.

There are additional checks that could be added but maybe too far? Check
parent cgroups to ensure values are <= parent, inspecting rtprio ulimit
and issuing a warning.

Signed-off-by: Erik St. Martin <alakriti@gmail.com>
This commit is contained in:
Erik St. Martin 2016-06-07 15:05:43 -04:00
parent 4c4545c92f
commit 4f320d7c2a
1 changed files with 27 additions and 21 deletions

View File

@ -15,17 +15,19 @@ import (
) )
type updateOptions struct { type updateOptions struct {
blkioWeight uint16 blkioWeight uint16
cpuPeriod int64 cpuPeriod int64
cpuQuota int64 cpuQuota int64
cpusetCpus string cpuRealtimePeriod int64
cpusetMems string cpuRealtimeRuntime int64
cpuShares int64 cpusetCpus string
memoryString string cpusetMems string
memoryReservation string cpuShares int64
memorySwap string memoryString string
kernelMemory string memoryReservation string
restartPolicy string memorySwap string
kernelMemory string
restartPolicy string
nFlag int nFlag int
@ -51,6 +53,8 @@ func NewUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.Uint16Var(&opts.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000") flags.Uint16Var(&opts.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000")
flags.Int64Var(&opts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period") flags.Int64Var(&opts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
flags.Int64Var(&opts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota") flags.Int64Var(&opts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
flags.Int64Var(&opts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds")
flags.Int64Var(&opts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds")
flags.StringVar(&opts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") flags.StringVar(&opts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
flags.StringVar(&opts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") flags.StringVar(&opts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
flags.Int64VarP(&opts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") flags.Int64VarP(&opts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
@ -115,16 +119,18 @@ func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error {
} }
resources := containertypes.Resources{ resources := containertypes.Resources{
BlkioWeight: opts.blkioWeight, BlkioWeight: opts.blkioWeight,
CpusetCpus: opts.cpusetCpus, CpusetCpus: opts.cpusetCpus,
CpusetMems: opts.cpusetMems, CpusetMems: opts.cpusetMems,
CPUShares: opts.cpuShares, CPUShares: opts.cpuShares,
Memory: memory, Memory: memory,
MemoryReservation: memoryReservation, MemoryReservation: memoryReservation,
MemorySwap: memorySwap, MemorySwap: memorySwap,
KernelMemory: kernelMemory, KernelMemory: kernelMemory,
CPUPeriod: opts.cpuPeriod, CPUPeriod: opts.cpuPeriod,
CPUQuota: opts.cpuQuota, CPUQuota: opts.cpuQuota,
CPURealtimePeriod: opts.cpuRealtimePeriod,
CPURealtimeRuntime: opts.cpuRealtimeRuntime,
} }
updateConfig := containertypes.UpdateConfig{ updateConfig := containertypes.UpdateConfig{