Skip to content

Commit

Permalink
don't enable threaded mode by default
Browse files Browse the repository at this point in the history
Because in threaded mode, we can't enable the memory controller -- it isn't thread-aware.

Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed May 10, 2020
1 parent 6621af8 commit 1e97975
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions libcontainer/cgroups/fs2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ func neededControllers(cgroup *configs.Cgroup) ([]string, error) {
return list, nil
}

// containsDomainController returns whether the current config contains domain controller or not.
// Refer to: http://man7.org/linux/man-pages/man7/cgroups.7.html
// As at Linux 4.19, the following controllers are threaded: cpu, perf_event, and pids.
func containsDomainController(cgroup *configs.Cgroup) bool {
if isMemorySet(cgroup) {
return true
}
if isIoSet(cgroup) {
return true
}
if isCpuSet(cgroup) {
return true
}
if isHugeTlbSet(cgroup) {
return true
}
return false
}

// CreateCgroupPath creates cgroupv2 path, enabling all the
// needed controllers in the process.
func CreateCgroupPath(path string, c *configs.Cgroup) (Err error) {
Expand Down Expand Up @@ -95,10 +114,18 @@ func CreateCgroupPath(path string, c *configs.Cgroup) (Err error) {
}
}()
}
// Write cgroup.type explicitly.
// Otherwise ENOTSUP may happen.
cgType := filepath.Join(current, "cgroup.type")
_ = ioutil.WriteFile(cgType, []byte("threaded"), 0644)
// There are 4 types: 'domain', 'threaded', 'domain threaded', and 'domain invalid'.
// If got 'domain invalid', we should check whether the current config contains domain controller or not.
// When does not contain domain controller, we can write "threaded" without retuning erro.
cgTypeFile := filepath.Join(current, "cgroup.type")
cgType, _ := ioutil.ReadFile(cgTypeFile)
if strings.TrimSpace(string(cgType)) == "domain invalid" {
if containsDomainController(c) {
return fmt.Errorf("Can't enter cgroup path %s, the cgroup type is 'domain invalid.", current)
} else {
_ = ioutil.WriteFile(cgTypeFile, []byte("threaded"), 0644)
}
}
}
// enable needed controllers
if i < len(elements)-1 {
Expand Down

0 comments on commit 1e97975

Please sign in to comment.