mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-30 10:36:27 +08:00
In some cases, container init fails to start because it is killed by the kernel OOM killer. The errors returned by runc in such cases are semi-random and rather cryptic. Below are a few examples. On cgroup v1 + systemd cgroup driver: > process_linux.go:348: copying bootstrap data to pipe caused: write init-p: broken pipe > process_linux.go:352: getting the final child's pid from pipe caused: EOF On cgroup v2: > process_linux.go:495: container init caused: read init-p: connection reset by peer > process_linux.go:484: writing syncT 'resume' caused: write init-p: broken pipe This commits adds the OOM method to cgroup managers, which tells whether the container was OOM-killed. In case that has happened, the original error is discarded (unless --debug is set), and the new OOM error is reported instead: > ERRO[0000] container_linux.go:367: starting container process caused: container init was OOM-killed (memory limit too low?) Also, fix the rootless test cases that are failing because they expect an error in the first line, and we have an additional warning now: > unable to get oom kill count" error="no directory specified for memory.oom_control Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
// +build linux
|
|
|
|
package cgroups
|
|
|
|
import (
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
type Manager interface {
|
|
// Applies cgroup configuration to the process with the specified pid
|
|
Apply(pid int) error
|
|
|
|
// Returns the PIDs inside the cgroup set
|
|
GetPids() ([]int, error)
|
|
|
|
// Returns the PIDs inside the cgroup set & all sub-cgroups
|
|
GetAllPids() ([]int, error)
|
|
|
|
// Returns statistics for the cgroup set
|
|
GetStats() (*Stats, error)
|
|
|
|
// Toggles the freezer cgroup according with specified state
|
|
Freeze(state configs.FreezerState) error
|
|
|
|
// Destroys the cgroup set
|
|
Destroy() error
|
|
|
|
// Path returns a cgroup path to the specified controller/subsystem.
|
|
// For cgroupv2, the argument is unused and can be empty.
|
|
Path(string) string
|
|
|
|
// Sets the cgroup as configured.
|
|
Set(container *configs.Config) error
|
|
|
|
// GetPaths returns cgroup path(s) to save in a state file in order to restore later.
|
|
//
|
|
// For cgroup v1, a key is cgroup subsystem name, and the value is the path
|
|
// to the cgroup for this subsystem.
|
|
//
|
|
// For cgroup v2 unified hierarchy, a key is "", and the value is the unified path.
|
|
GetPaths() map[string]string
|
|
|
|
// GetCgroups returns the cgroup data as configured.
|
|
GetCgroups() (*configs.Cgroup, error)
|
|
|
|
// GetFreezerState retrieves the current FreezerState of the cgroup.
|
|
GetFreezerState() (configs.FreezerState, error)
|
|
|
|
// Whether the cgroup path exists or not
|
|
Exists() bool
|
|
|
|
// OOMKillCount reports OOM kill count for the cgroup.
|
|
OOMKillCount() (uint64, error)
|
|
}
|