Skip to content

Commit

Permalink
Merge pull request opencontainers#2160 from AkihiroSuda/cgroup2-no-pr…
Browse files Browse the repository at this point in the history
…oc-cgroups

cgroup2: do not parse /proc/cgroups
  • Loading branch information
Mrunal Patel authored Oct 29, 2019
2 parents c4d8e16 + 74a3fe5 commit f04fb99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions libcontainer/cgroups/fs/io_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ type IOGroupV2 struct {
}

func (s *IOGroupV2) Name() string {
// for compatibility with v1 blkio controller
return "blkio"
return "io"
}

func (s *IOGroupV2) Apply(d *cgroupData) error {
_, err := d.join("blkio")
_, err := d.join("io")
if err != nil && !cgroups.IsNotFound(err) {
return err
}
Expand Down Expand Up @@ -62,7 +61,7 @@ func (s *IOGroupV2) Set(path string, cgroup *configs.Cgroup) error {
}

func (s *IOGroupV2) Remove(d *cgroupData) error {
return removePath(d.path("blkio"))
return removePath(d.path("io"))
}

func readCgroup2MapFile(path string, name string) (map[string][]string, error) {
Expand Down
15 changes: 15 additions & 0 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ func GetCgroupMounts(all bool) ([]Mount, error) {

// GetAllSubsystems returns all the cgroup subsystems supported by the kernel
func GetAllSubsystems() ([]string, error) {
// /proc/cgroups is meaningless for v2
// https://github.com/torvalds/linux/blob/v5.3/Documentation/admin-guide/cgroup-v2.rst#deprecated-v1-core-features
if IsCgroup2UnifiedMode() {
// "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers.
// - devices: implemented in kernel 4.15
// - freezer: implemented in kernel 5.2
// We assume these are always available, as it is hard to detect availability.
pseudo := []string{"devices", "freezer"}
data, err := ioutil.ReadFile("/sys/fs/cgroup/cgroup.controllers")
if err != nil {
return nil, err
}
subsystems := append(pseudo, strings.Fields(string(data))...)
return subsystems, nil
}
f, err := os.Open("/proc/cgroups")
if err != nil {
return nil, err
Expand Down

0 comments on commit f04fb99

Please sign in to comment.