Skip to content

Commit 349e5ab

Browse files
authored
Merge pull request #4283 from kolyshkin/revert-cpu-aff
Revert "Set temporary single CPU affinity before cgroup cpuset transition"
2 parents 67a1477 + 1c505ff commit 349e5ab

File tree

15 files changed

+16
-961
lines changed

15 files changed

+16
-961
lines changed

docs/isolated-cpu-affinity-transition.md

Lines changed: 0 additions & 125 deletions
This file was deleted.

features.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ var featuresCommand = cli.Command{
6868
"bundle",
6969
"org.systemd.property.", // prefix form
7070
"org.criu.config",
71-
"org.opencontainers.runc.exec.isolated-cpu-affinity-transition",
7271
},
7372
}
7473

libcontainer/cgroups/cgroups.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,4 @@ type Manager interface {
7272

7373
// OOMKillCount reports OOM kill count for the cgroup.
7474
OOMKillCount() (uint64, error)
75-
76-
// GetEffectiveCPUs returns the effective CPUs of the cgroup, an empty
77-
// value means that the cgroups cpuset subsystem/controller is not enabled.
78-
GetEffectiveCPUs() string
7975
}

libcontainer/cgroups/fs/fs.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"os"
7-
"path/filepath"
8-
"strings"
97
"sync"
108

119
"golang.org/x/sys/unix"
@@ -265,28 +263,3 @@ func (m *Manager) OOMKillCount() (uint64, error) {
265263

266264
return c, err
267265
}
268-
269-
func (m *Manager) GetEffectiveCPUs() string {
270-
return GetEffectiveCPUs(m.Path("cpuset"), m.cgroups)
271-
}
272-
273-
func GetEffectiveCPUs(cpusetPath string, cgroups *configs.Cgroup) string {
274-
// Fast path.
275-
if cgroups.CpusetCpus != "" {
276-
return cgroups.CpusetCpus
277-
} else if !strings.HasPrefix(cpusetPath, defaultCgroupRoot) {
278-
return ""
279-
}
280-
281-
// Iterates until it goes to the cgroup root path.
282-
// It's required for containers in which cpuset controller
283-
// is not enabled, in this case a parent cgroup is used.
284-
for path := cpusetPath; path != defaultCgroupRoot; path = filepath.Dir(path) {
285-
cpus, err := fscommon.GetCgroupParamString(path, "cpuset.effective_cpus")
286-
if err == nil {
287-
return cpus
288-
}
289-
}
290-
291-
return ""
292-
}

libcontainer/cgroups/fs2/fs2.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"errors"
55
"fmt"
66
"os"
7-
"path/filepath"
87
"strings"
98

109
"github.com/opencontainers/runc/libcontainer/cgroups"
1110
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
1211
"github.com/opencontainers/runc/libcontainer/configs"
13-
"github.com/opencontainers/runc/libcontainer/utils"
1412
)
1513

1614
type parseError = fscommon.ParseError
@@ -34,9 +32,6 @@ func NewManager(config *configs.Cgroup, dirPath string) (*Manager, error) {
3432
if err != nil {
3533
return nil, err
3634
}
37-
} else {
38-
// Clean path for safety.
39-
dirPath = utils.CleanPath(dirPath)
4035
}
4136

4237
m := &Manager{
@@ -321,26 +316,3 @@ func CheckMemoryUsage(dirPath string, r *configs.Resources) error {
321316

322317
return nil
323318
}
324-
325-
func (m *Manager) GetEffectiveCPUs() string {
326-
// Fast path.
327-
if m.config.CpusetCpus != "" {
328-
return m.config.CpusetCpus
329-
} else if !strings.HasPrefix(m.dirPath, UnifiedMountpoint) {
330-
return ""
331-
}
332-
333-
// Iterates until it goes outside of the cgroup root path.
334-
// It's required for containers in which cpuset controller
335-
// is not enabled, in this case a parent cgroup is used.
336-
outsidePath := filepath.Dir(UnifiedMountpoint)
337-
338-
for path := m.dirPath; path != outsidePath; path = filepath.Dir(path) {
339-
cpus, err := fscommon.GetCgroupParamString(path, "cpuset.cpus.effective")
340-
if err == nil {
341-
return cpus
342-
}
343-
}
344-
345-
return ""
346-
}

libcontainer/cgroups/systemd/v1.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,3 @@ func (m *LegacyManager) Exists() bool {
411411
func (m *LegacyManager) OOMKillCount() (uint64, error) {
412412
return fs.OOMKillCount(m.Path("memory"))
413413
}
414-
415-
func (m *LegacyManager) GetEffectiveCPUs() string {
416-
return fs.GetEffectiveCPUs(m.Path("cpuset"), m.cgroups)
417-
}

libcontainer/cgroups/systemd/v2.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,3 @@ func (m *UnifiedManager) Exists() bool {
514514
func (m *UnifiedManager) OOMKillCount() (uint64, error) {
515515
return m.fsMgr.OOMKillCount()
516516
}
517-
518-
func (m *UnifiedManager) GetEffectiveCPUs() string {
519-
return m.fsMgr.GetEffectiveCPUs()
520-
}

libcontainer/cgroups/utils.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ func GetAllSubsystems() ([]string, error) {
136136
return subsystems, nil
137137
}
138138

139-
func readProcsFile(dir string) ([]int, error) {
140-
f, err := OpenFile(dir, CgroupProcesses, os.O_RDONLY)
139+
func readProcsFile(dir string) (out []int, _ error) {
140+
file := CgroupProcesses
141+
retry := true
142+
143+
again:
144+
f, err := OpenFile(dir, file, os.O_RDONLY)
141145
if err != nil {
142146
return nil, err
143147
}
144148
defer f.Close()
145149

146-
var (
147-
s = bufio.NewScanner(f)
148-
out = []int{}
149-
)
150-
150+
s := bufio.NewScanner(f)
151151
for s.Scan() {
152152
if t := s.Text(); t != "" {
153153
pid, err := strconv.Atoi(t)
@@ -157,6 +157,13 @@ func readProcsFile(dir string) ([]int, error) {
157157
out = append(out, pid)
158158
}
159159
}
160+
if errors.Is(s.Err(), unix.ENOTSUP) && retry {
161+
// For a threaded cgroup, read returns ENOTSUP, and we should
162+
// read from cgroup.threads instead.
163+
file = "cgroup.threads"
164+
retry = false
165+
goto again
166+
}
160167
return out, s.Err()
161168
}
162169

libcontainer/container_linux_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
6969
return configs.Thawed, nil
7070
}
7171

72-
func (m *mockCgroupManager) GetEffectiveCPUs() string {
73-
return ""
74-
}
75-
7672
type mockProcess struct {
7773
_pid int
7874
started uint64

0 commit comments

Comments
 (0)