mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15320 from hqhq/hq_add_cgroup_check
Check sysinfo for Cpuset cpu.shares and blkio
This commit is contained in:
commit
9ce0a20c01
3 changed files with 69 additions and 0 deletions
|
@ -183,6 +183,11 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
|
|||
return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
|
||||
}
|
||||
}
|
||||
if hostConfig.CPUShares > 0 && !daemon.SystemConfig().CPUShares {
|
||||
warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.")
|
||||
logrus.Warnf("Your kernel does not support CPU shares. Shares discarded.")
|
||||
hostConfig.CPUShares = 0
|
||||
}
|
||||
if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CPUCfsPeriod {
|
||||
warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
|
||||
logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
|
||||
|
@ -193,6 +198,17 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
|
|||
logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
|
||||
hostConfig.CPUQuota = 0
|
||||
}
|
||||
if (hostConfig.CpusetCpus != "" || hostConfig.CpusetMems != "") && !daemon.SystemConfig().Cpuset {
|
||||
warnings = append(warnings, "Your kernel does not support cpuset. Cpuset discarded.")
|
||||
logrus.Warnf("Your kernel does not support cpuset. Cpuset discarded.")
|
||||
hostConfig.CpusetCpus = ""
|
||||
hostConfig.CpusetMems = ""
|
||||
}
|
||||
if hostConfig.BlkioWeight > 0 && !daemon.SystemConfig().BlkioWeight {
|
||||
warnings = append(warnings, "Your kernel does not support Block I/O weight. Weight discarded.")
|
||||
logrus.Warnf("Your kernel does not support Block I/O weight. Weight discarded.")
|
||||
hostConfig.BlkioWeight = 0
|
||||
}
|
||||
if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
|
||||
return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ type SysInfo struct {
|
|||
|
||||
*cgroupMemInfo
|
||||
*cgroupCPUInfo
|
||||
*cgroupBlkioInfo
|
||||
*cgroupCpusetInfo
|
||||
|
||||
// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
|
||||
IPv4ForwardingDisabled bool
|
||||
|
@ -37,9 +39,22 @@ type cgroupMemInfo struct {
|
|||
}
|
||||
|
||||
type cgroupCPUInfo struct {
|
||||
// Whether CPU shares is supported or not
|
||||
CPUShares bool
|
||||
|
||||
// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
|
||||
CPUCfsPeriod bool
|
||||
|
||||
// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
|
||||
CPUCfsQuota bool
|
||||
}
|
||||
|
||||
type cgroupBlkioInfo struct {
|
||||
// Whether Block IO weight is supported or not
|
||||
BlkioWeight bool
|
||||
}
|
||||
|
||||
type cgroupCpusetInfo struct {
|
||||
// Whether Cpuset is supported or not
|
||||
Cpuset bool
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ func New(quiet bool) *SysInfo {
|
|||
sysInfo := &SysInfo{}
|
||||
sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
|
||||
sysInfo.cgroupCPUInfo = checkCgroupCPU(quiet)
|
||||
sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(quiet)
|
||||
sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(quiet)
|
||||
|
||||
_, err := cgroups.FindCgroupMountpoint("devices")
|
||||
sysInfo.CgroupDevicesEnabled = err == nil
|
||||
|
@ -68,6 +70,11 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
|
|||
return info
|
||||
}
|
||||
|
||||
info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
|
||||
if !quiet && !info.CPUShares {
|
||||
logrus.Warn("Your kernel does not support cgroup cpu shares")
|
||||
}
|
||||
|
||||
info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
|
||||
if !quiet && !info.CPUCfsPeriod {
|
||||
logrus.Warn("Your kernel does not support cgroup cfs period")
|
||||
|
@ -80,6 +87,37 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
|
|||
return info
|
||||
}
|
||||
|
||||
func checkCgroupBlkioInfo(quiet bool) *cgroupBlkioInfo {
|
||||
info := &cgroupBlkioInfo{}
|
||||
mountPoint, err := cgroups.FindCgroupMountpoint("blkio")
|
||||
if err != nil {
|
||||
if !quiet {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
info.BlkioWeight = cgroupEnabled(mountPoint, "blkio.weight")
|
||||
if !quiet && !info.BlkioWeight {
|
||||
logrus.Warn("Your kernel does not support cgroup blkio weight")
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func checkCgroupCpusetInfo(quiet bool) *cgroupCpusetInfo {
|
||||
info := &cgroupCpusetInfo{}
|
||||
_, err := cgroups.FindCgroupMountpoint("cpuset")
|
||||
if err != nil {
|
||||
if !quiet {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
info.Cpuset = true
|
||||
return info
|
||||
}
|
||||
|
||||
func cgroupEnabled(mountPoint, name string) bool {
|
||||
_, err := os.Stat(path.Join(mountPoint, name))
|
||||
return err == nil
|
||||
|
|
Loading…
Reference in a new issue