cgroupv1/systemd.Set: don't enable kernel memory acct

This is a regression from commit 1d4ccc8e0. We only need to enable
kernel memory accounting once, from the (*legacyManager*).Apply(),
and there is no need to do it in (*legacyManager*).Set().

While at it, rename the method to better reflect what it's doing.

This saves 1 call to mountinfo parser.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-05-29 17:43:11 -07:00
parent 774a9e7641
commit 3fe6e04510
1 changed files with 9 additions and 8 deletions

View File

@ -119,13 +119,6 @@ func genV1ResourcesProperties(c *configs.Cgroup) ([]systemdDbus.Property, error)
newProp("TasksMax", uint64(c.Resources.PidsLimit)))
}
// We have to set kernel memory here, as we can't change it once
// processes have been attached to the cgroup.
if c.Resources.KernelMemory != 0 {
if err := setKernelMemory(c); err != nil {
return nil, err
}
}
return properties, nil
}
@ -197,6 +190,14 @@ func (m *legacyManager) Apply(pid int) error {
properties = append(properties, resourcesProperties...)
properties = append(properties, c.SystemdProps...)
// We have to set kernel memory here, as we can't change it once
// processes have been attached to the cgroup.
if c.Resources.KernelMemory != 0 {
if err := enableKmem(c); err != nil {
return err
}
}
dbusConnection, err := getDbusConnection(false)
if err != nil {
return err
@ -443,7 +444,7 @@ func (m *legacyManager) Set(container *configs.Config) error {
return nil
}
func setKernelMemory(c *configs.Cgroup) error {
func enableKmem(c *configs.Cgroup) error {
path, err := getSubsystemPath(c, "memory")
if err != nil && !cgroups.IsNotFound(err) {
return err