Browse code

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 authored on 2015/08/05 23:35:18
Showing 3 changed files
... ...
@@ -166,6 +166,11 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
166 166
 			return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
167 167
 		}
168 168
 	}
169
+	if hostConfig.CPUShares > 0 && !daemon.SystemConfig().CPUShares {
170
+		warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.")
171
+		logrus.Warnf("Your kernel does not support CPU shares. Shares discarded.")
172
+		hostConfig.CPUShares = 0
173
+	}
169 174
 	if hostConfig.CPUPeriod > 0 && !daemon.SystemConfig().CPUCfsPeriod {
170 175
 		warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
171 176
 		logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
... ...
@@ -176,6 +181,17 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
176 176
 		logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
177 177
 		hostConfig.CPUQuota = 0
178 178
 	}
179
+	if (hostConfig.CpusetCpus != "" || hostConfig.CpusetMems != "") && !daemon.SystemConfig().Cpuset {
180
+		warnings = append(warnings, "Your kernel does not support cpuset. Cpuset discarded.")
181
+		logrus.Warnf("Your kernel does not support cpuset. Cpuset discarded.")
182
+		hostConfig.CpusetCpus = ""
183
+		hostConfig.CpusetMems = ""
184
+	}
185
+	if hostConfig.BlkioWeight > 0 && !daemon.SystemConfig().BlkioWeight {
186
+		warnings = append(warnings, "Your kernel does not support Block I/O weight. Weight discarded.")
187
+		logrus.Warnf("Your kernel does not support Block I/O weight. Weight discarded.")
188
+		hostConfig.BlkioWeight = 0
189
+	}
179 190
 	if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
180 191
 		return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
181 192
 	}
... ...
@@ -8,6 +8,8 @@ type SysInfo struct {
8 8
 
9 9
 	*cgroupMemInfo
10 10
 	*cgroupCPUInfo
11
+	*cgroupBlkioInfo
12
+	*cgroupCpusetInfo
11 13
 
12 14
 	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
13 15
 	IPv4ForwardingDisabled bool
... ...
@@ -37,9 +39,22 @@ type cgroupMemInfo struct {
37 37
 }
38 38
 
39 39
 type cgroupCPUInfo struct {
40
+	// Whether CPU shares is supported or not
41
+	CPUShares bool
42
+
40 43
 	// Whether CPU CFS(Completely Fair Scheduler) period is supported or not
41 44
 	CPUCfsPeriod bool
42 45
 
43 46
 	// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not
44 47
 	CPUCfsQuota bool
45 48
 }
49
+
50
+type cgroupBlkioInfo struct {
51
+	// Whether Block IO weight is supported or not
52
+	BlkioWeight bool
53
+}
54
+
55
+type cgroupCpusetInfo struct {
56
+	// Whether Cpuset is supported or not
57
+	Cpuset bool
58
+}
... ...
@@ -15,6 +15,8 @@ func New(quiet bool) *SysInfo {
15 15
 	sysInfo := &SysInfo{}
16 16
 	sysInfo.cgroupMemInfo = checkCgroupMem(quiet)
17 17
 	sysInfo.cgroupCPUInfo = checkCgroupCPU(quiet)
18
+	sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(quiet)
19
+	sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(quiet)
18 20
 
19 21
 	_, err := cgroups.FindCgroupMountpoint("devices")
20 22
 	sysInfo.CgroupDevicesEnabled = err == nil
... ...
@@ -68,6 +70,11 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
68 68
 		return info
69 69
 	}
70 70
 
71
+	info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
72
+	if !quiet && !info.CPUShares {
73
+		logrus.Warn("Your kernel does not support cgroup cpu shares")
74
+	}
75
+
71 76
 	info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
72 77
 	if !quiet && !info.CPUCfsPeriod {
73 78
 		logrus.Warn("Your kernel does not support cgroup cfs period")
... ...
@@ -80,6 +87,37 @@ func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
80 80
 	return info
81 81
 }
82 82
 
83
+func checkCgroupBlkioInfo(quiet bool) *cgroupBlkioInfo {
84
+	info := &cgroupBlkioInfo{}
85
+	mountPoint, err := cgroups.FindCgroupMountpoint("blkio")
86
+	if err != nil {
87
+		if !quiet {
88
+			logrus.Warn(err)
89
+		}
90
+		return info
91
+	}
92
+
93
+	info.BlkioWeight = cgroupEnabled(mountPoint, "blkio.weight")
94
+	if !quiet && !info.BlkioWeight {
95
+		logrus.Warn("Your kernel does not support cgroup blkio weight")
96
+	}
97
+	return info
98
+}
99
+
100
+func checkCgroupCpusetInfo(quiet bool) *cgroupCpusetInfo {
101
+	info := &cgroupCpusetInfo{}
102
+	_, err := cgroups.FindCgroupMountpoint("cpuset")
103
+	if err != nil {
104
+		if !quiet {
105
+			logrus.Warn(err)
106
+		}
107
+		return info
108
+	}
109
+
110
+	info.Cpuset = true
111
+	return info
112
+}
113
+
83 114
 func cgroupEnabled(mountPoint, name string) bool {
84 115
 	_, err := os.Stat(path.Join(mountPoint, name))
85 116
 	return err == nil