Merge pull request #1939 from cyphar/nokmem-error
cgroups: nokmem: error out on explicitly-set kmemcg limits
This commit is contained in:
commit
25f3f893c8
|
@ -3,6 +3,7 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -17,7 +18,12 @@ import (
|
||||||
const cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
|
const cgroupKernelMemoryLimit = "memory.kmem.limit_in_bytes"
|
||||||
|
|
||||||
func EnableKernelMemoryAccounting(path string) error {
|
func EnableKernelMemoryAccounting(path string) error {
|
||||||
// Check if kernel memory is enabled
|
// Ensure that kernel memory is available in this kernel build. If it
|
||||||
|
// isn't, we just ignore it because EnableKernelMemoryAccounting is
|
||||||
|
// automatically called for all memory limits.
|
||||||
|
if !cgroups.PathExists(filepath.Join(path, cgroupKernelMemoryLimit)) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// We have to limit the kernel memory here as it won't be accounted at all
|
// We have to limit the kernel memory here as it won't be accounted at all
|
||||||
// until a limit is set on the cgroup and limit cannot be set once the
|
// until a limit is set on the cgroup and limit cannot be set once the
|
||||||
// cgroup has children, or if there are already tasks in the cgroup.
|
// cgroup has children, or if there are already tasks in the cgroup.
|
||||||
|
@ -34,8 +40,9 @@ func setKernelMemory(path string, kernelMemoryLimit int64) error {
|
||||||
return fmt.Errorf("no such directory for %s", cgroupKernelMemoryLimit)
|
return fmt.Errorf("no such directory for %s", cgroupKernelMemoryLimit)
|
||||||
}
|
}
|
||||||
if !cgroups.PathExists(filepath.Join(path, cgroupKernelMemoryLimit)) {
|
if !cgroups.PathExists(filepath.Join(path, cgroupKernelMemoryLimit)) {
|
||||||
// kernel memory is not enabled on the system so we should do nothing
|
// We have specifically been asked to set a kmem limit. If the kernel
|
||||||
return nil
|
// doesn't support it we *must* error out.
|
||||||
|
return errors.New("kernel memory accounting not supported by this kernel")
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(filepath.Join(path, cgroupKernelMemoryLimit), []byte(strconv.FormatInt(kernelMemoryLimit, 10)), 0700); err != nil {
|
if err := ioutil.WriteFile(filepath.Join(path, cgroupKernelMemoryLimit), []byte(strconv.FormatInt(kernelMemoryLimit, 10)), 0700); err != nil {
|
||||||
// Check if the error number returned by the syscall is "EBUSY"
|
// Check if the error number returned by the syscall is "EBUSY"
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
|
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
func EnableKernelMemoryAccounting(path string) error {
|
func EnableKernelMemoryAccounting(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setKernelMemory(path string, kernelMemoryLimit int64) error {
|
func setKernelMemory(path string, kernelMemoryLimit int64) error {
|
||||||
return nil
|
return errors.New("kernel memory accounting disabled in this runc build")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue