Skip to content

Commit 4c013a1

Browse files
author
Mrunal Patel
authored
Merge pull request #1194 from hqhq/fix_cpu_exclusive
Fix cpuset issue with cpuset.cpu_exclusive
2 parents f156f73 + aee4686 commit 4c013a1

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

libcontainer/cgroups/fs/cpuset.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,26 @@ func (s *CpusetGroup) ApplyDir(dir string, cgroup *configs.Cgroup, pid int) erro
6161
if err != nil {
6262
return err
6363
}
64-
if err := s.ensureParent(dir, root); err != nil {
64+
// 'ensureParent' start with parent because we don't want to
65+
// explicitly inherit from parent, it could conflict with
66+
// 'cpuset.cpu_exclusive'.
67+
if err := s.ensureParent(filepath.Dir(dir), root); err != nil {
6568
return err
6669
}
70+
if err := os.MkdirAll(dir, 0755); err != nil {
71+
return err
72+
}
73+
// We didn't inherit cpuset configs from parent, but we have
74+
// to ensure cpuset configs are set before moving task into the
75+
// cgroup.
76+
// The logic is, if user specified cpuset configs, use these
77+
// specified configs, otherwise, inherit from parent. This makes
78+
// cpuset configs work correctly with 'cpuset.cpu_exclusive', and
79+
// keep backward compatbility.
80+
if err := s.ensureCpusAndMems(dir, cgroup); err != nil {
81+
return err
82+
}
83+
6784
// because we are not using d.join we need to place the pid into the procs file
6885
// unlike the other subsystems
6986
if err := cgroups.WriteCgroupProc(dir, pid); err != nil {
@@ -136,3 +153,10 @@ func (s *CpusetGroup) copyIfNeeded(current, parent string) error {
136153
func (s *CpusetGroup) isEmpty(b []byte) bool {
137154
return len(bytes.Trim(b, "\n")) == 0
138155
}
156+
157+
func (s *CpusetGroup) ensureCpusAndMems(path string, cgroup *configs.Cgroup) error {
158+
if err := s.Set(path, cgroup); err != nil {
159+
return err
160+
}
161+
return s.copyIfNeeded(path, filepath.Dir(path))
162+
}

0 commit comments

Comments
 (0)