Skip to content

Commit 8a740d5

Browse files
committed
libcontainer: cgroups: don't Set in Apply
Apply and Set are two separate operations, and it doesn't make sense to group the two together (especially considering that the bootstrap process is added to the cgroup as well). The only exception to this is the memory cgroup, which requires the configuration to be set before processes can join. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 37789f5 commit 8a740d5

File tree

13 files changed

+38
-193
lines changed

13 files changed

+38
-193
lines changed

libcontainer/cgroups/fs/apply_raw.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ func (m *Manager) GetStats() (*cgroups.Stats, error) {
181181

182182
func (m *Manager) Set(container *configs.Config) error {
183183
for name, path := range m.Paths {
184+
// We can't set this here, because after being applied, memcg doesn't
185+
// allow a non-empty cgroup from having its limits changed.
186+
if name == "memory" {
187+
continue
188+
}
184189
sys, err := subsystems.Get(name)
185190
if err == errSubsystemDoesNotExist || !cgroups.PathExists(path) {
186191
continue

libcontainer/cgroups/fs/blkio.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ func (s *BlkioGroup) Name() string {
2222
}
2323

2424
func (s *BlkioGroup) Apply(d *cgroupData) error {
25-
dir, err := d.join("blkio")
25+
_, err := d.join("blkio")
2626
if err != nil && !cgroups.IsNotFound(err) {
2727
return err
2828
}
29-
30-
if err := s.Set(dir, d.config); err != nil {
31-
return err
32-
}
33-
3429
return nil
3530
}
3631

libcontainer/cgroups/fs/cpu.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ func (s *CpuGroup) Name() string {
2222
func (s *CpuGroup) Apply(d *cgroupData) error {
2323
// We always want to join the cpu group, to allow fair cpu scheduling
2424
// on a container basis
25-
dir, err := d.join("cpu")
25+
_, err := d.join("cpu")
2626
if err != nil && !cgroups.IsNotFound(err) {
2727
return err
2828
}
29-
30-
if err := s.Set(dir, d.config); err != nil {
31-
return err
32-
}
33-
3429
return nil
3530
}
3631

libcontainer/cgroups/fs/cpuset.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ func (s *CpusetGroup) ApplyDir(dir string, cgroup *configs.Cgroup, pid int) erro
6363
if err := s.ensureParent(dir, root); err != nil {
6464
return err
6565
}
66-
// the default values inherit from parent cgroup are already set in
67-
// s.ensureParent, cover these if we have our own
68-
if err := s.Set(dir, cgroup); err != nil {
69-
return err
70-
}
7166
// because we are not using d.join we need to place the pid into the procs file
7267
// unlike the other subsystems
7368
if err := writeFile(dir, "cgroup.procs", strconv.Itoa(pid)); err != nil {

libcontainer/cgroups/fs/devices.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@ func (s *DevicesGroup) Name() string {
1515
}
1616

1717
func (s *DevicesGroup) Apply(d *cgroupData) error {
18-
dir, err := d.join("devices")
18+
_, err := d.join("devices")
1919
if err != nil {
2020
// We will return error even it's `not found` error, devices
2121
// cgroup is hard requirement for container's security.
2222
return err
2323
}
24-
25-
if err := s.Set(dir, d.config); err != nil {
26-
return err
27-
}
28-
2924
return nil
3025
}
3126

libcontainer/cgroups/fs/freezer.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ func (s *FreezerGroup) Name() string {
1919
}
2020

2121
func (s *FreezerGroup) Apply(d *cgroupData) error {
22-
dir, err := d.join("freezer")
22+
_, err := d.join("freezer")
2323
if err != nil && !cgroups.IsNotFound(err) {
2424
return err
2525
}
26-
27-
if err := s.Set(dir, d.config); err != nil {
28-
return err
29-
}
30-
3126
return nil
3227
}
3328

libcontainer/cgroups/fs/hugetlb.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ func (s *HugetlbGroup) Name() string {
1919
}
2020

2121
func (s *HugetlbGroup) Apply(d *cgroupData) error {
22-
dir, err := d.join("hugetlb")
22+
_, err := d.join("hugetlb")
2323
if err != nil && !cgroups.IsNotFound(err) {
2424
return err
2525
}
26-
27-
if err := s.Set(dir, d.config); err != nil {
28-
return err
29-
}
30-
3126
return nil
3227
}
3328

libcontainer/cgroups/fs/memory.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
3232
return err
3333
}
3434
}
35-
3635
if err := s.Set(path, d.config); err != nil {
3736
return err
3837
}

libcontainer/cgroups/fs/net_cls.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ func (s *NetClsGroup) Name() string {
1515
}
1616

1717
func (s *NetClsGroup) Apply(d *cgroupData) error {
18-
dir, err := d.join("net_cls")
18+
_, err := d.join("net_cls")
1919
if err != nil && !cgroups.IsNotFound(err) {
2020
return err
2121
}
22-
23-
if err := s.Set(dir, d.config); err != nil {
24-
return err
25-
}
26-
2722
return nil
2823
}
2924

libcontainer/cgroups/fs/net_prio.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ func (s *NetPrioGroup) Name() string {
1515
}
1616

1717
func (s *NetPrioGroup) Apply(d *cgroupData) error {
18-
dir, err := d.join("net_prio")
18+
_, err := d.join("net_prio")
1919
if err != nil && !cgroups.IsNotFound(err) {
2020
return err
2121
}
22-
23-
if err := s.Set(dir, d.config); err != nil {
24-
return err
25-
}
26-
2722
return nil
2823
}
2924

0 commit comments

Comments
 (0)