Skip to content

Commit

Permalink
cgroup2: do not parse /proc/cgroups
Browse files Browse the repository at this point in the history
/proc/cgroups is meaningless for v2 and should be ignored.

https://github.com/torvalds/linux/blob/v5.3/Documentation/admin-guide/cgroup-v2.rst#deprecated-v1-core-features

* Now GetAllSubsystems() parses /sys/fs/cgroup/cgroup.controller, not /proc/cgroups.
  The function result also contains "pseudo" controllers: {"devices", "freezer"}.
  As it is hard to detect availability of pseudo controllers, pseudo controllers
  are always assumed to be available.

* Now IOGroupV2.Name() returns "io", not "blkio"

Fix #2155 #2156

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 27, 2019
1 parent c4d8e16 commit 74a3fe5
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
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
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 74a3fe5

Please sign in to comment.