Skip to content

Commit 4029019

Browse files
committed
memory: remove wrong memory.kmem.limit_in_bytes check
This check is useless as: "We have to limit the kernel memory here as it won't be accounted at all until a limit is set on the cgroup" - if kmem accounting is enabled on boot (no nokmem) kernel memory would be accounted without setting the limit. "limit cannot be set once the cgroup has children, or if there are already tasks in the cgroup." - It can, the only restriction it should be > usage, but setting this limit < future usage is a bad thing itself. So there is no difference if we set this limit on an active cgroup. More over memory.kmem.limit_in_bytes is deprecated in mainstream linux kernel as it was considered unreliable, see more information in: commit 0158115f702b ("memcg, kmem: deprecate kmem.limit_in_bytes") Link: torvalds/linux@0158115f702b Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
1 parent 318312a commit 4029019

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

memory.go

-28
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"path/filepath"
2525
"strconv"
2626
"strings"
27-
"syscall"
2827

2928
v1 "github.com/containerd/cgroups/stats/v1"
3029
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -207,21 +206,6 @@ func (m *memoryController) Create(path string, resources *specs.LinuxResources)
207206
if resources.Memory == nil {
208207
return nil
209208
}
210-
if resources.Memory.Kernel != nil {
211-
// Check if kernel memory is enabled
212-
// We have to limit the kernel memory here as it won't be accounted at all
213-
// until a limit is set on the cgroup and limit cannot be set once the
214-
// cgroup has children, or if there are already tasks in the cgroup.
215-
for _, i := range []int64{1, -1} {
216-
if err := retryingWriteFile(
217-
filepath.Join(m.Path(path), "memory.kmem.limit_in_bytes"),
218-
[]byte(strconv.FormatInt(i, 10)),
219-
defaultFilePerm,
220-
); err != nil {
221-
return checkEBUSY(err)
222-
}
223-
}
224-
}
225209
return m.set(path, getMemorySettings(resources))
226210
}
227211

@@ -433,18 +417,6 @@ func getMemorySettings(resources *specs.LinuxResources) []memorySettings {
433417
}
434418
}
435419

436-
func checkEBUSY(err error) error {
437-
if pathErr, ok := err.(*os.PathError); ok {
438-
if errNo, ok := pathErr.Err.(syscall.Errno); ok {
439-
if errNo == unix.EBUSY {
440-
return fmt.Errorf(
441-
"failed to set memory.kmem.limit_in_bytes, because either tasks have already joined this cgroup or it has children")
442-
}
443-
}
444-
}
445-
return err
446-
}
447-
448420
func getOomControlValue(mem *specs.LinuxMemory) *int64 {
449421
if mem.DisableOOMKiller != nil && *mem.DisableOOMKiller {
450422
i := int64(1)

0 commit comments

Comments
 (0)