瀏覽代碼

Check sysinfo for Cpuset cpu.shares and blkio

Carried: #14015

If kernel is compiled with CONFIG_FAIR_GROUP_SCHED disabled cpu.shares
doesn't exist.
If kernel is compiled with CONFIG_CFQ_GROUP_IOSCHED disabled blkio.weight
doesn't exist.
If kernel is compiled with CONFIG_CPUSETS disabled cpuset won't be
supported.

We need to handle these conditions by checking sysinfo and verifying them.

Signed-off-by: Zefan Li <lizefan@huawei.com>
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Qiang Huang 10 年之前
父節點
當前提交
b7599d58cb
共有 3 個文件被更改,包括 69 次插入0 次删除
  1. 16 0
      daemon/daemon_unix.go
  2. 15 0
      pkg/sysinfo/sysinfo.go
  3. 38 0
      pkg/sysinfo/sysinfo_linux.go

+ 16 - 0
daemon/daemon_unix.go

@@ -166,6 +166,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.")
@@ -176,6 +181,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.")
 	}

+ 15 - 0
pkg/sysinfo/sysinfo.go

@@ -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
+}

+ 38 - 0
pkg/sysinfo/sysinfo_linux.go

@@ -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