cgroups: Index | Files | Directories

package cgroups

import ""


Package Files

blkio.go cgroup.go control.go cpu.go cpuacct.go cpuset.go devices.go errors.go freezer.go hierarchy.go hugetlb.go memory.go named.go net_cls.go net_prio.go opts.go paths.go perf_event.go pids.go rdma.go state.go subsystem.go systemd.go ticks.go utils.go v1.go


var (
    ErrInvalidPid               = errors.New("cgroups: pid must be greater than 0")
    ErrMountPointNotExist       = errors.New("cgroups: cgroup mountpoint does not exist")
    ErrInvalidFormat            = errors.New("cgroups: parsing file with invalid format failed")
    ErrFreezerNotSupported      = errors.New("cgroups: freezer cgroup not supported on this system")
    ErrMemoryNotSupported       = errors.New("cgroups: memory cgroup not supported on this system")
    ErrCgroupDeleted            = errors.New("cgroups: cgroup deleted")
    ErrNoCgroupMountDestination = errors.New("cgroups: cannot find cgroup mount destination")
var (
    // ErrIgnoreSubsystem allows the specific subsystem to be skipped
    ErrIgnoreSubsystem = errors.New("skip subsystem")
    // ErrDevicesRequired is returned when the devices subsystem is required but
    // does not exist or is not active
    ErrDevicesRequired = errors.New("devices subsystem is required")
var ErrControllerNotActive = errors.New("controller is not supported")

ErrControllerNotActive is returned when a controller is not supported or enabled

func AllowAny Uses

func AllowAny(s Subsystem, p Path, err error) error

AllowAny allows any subsystem errors to be skipped

func IgnoreModules Uses

func IgnoreModules(names ...string) func(*memoryController)

IgnoreModules configure the memory controller to not read memory metrics for some module names (e.g. passing "memsw" would avoid all the memory.memsw.* entries)

func IgnoreNotExist Uses

func IgnoreNotExist(err error) error

IgnoreNotExist ignores any errors that are for not existing files

func NewBlkio Uses

func NewBlkio(root string, options ...func(controller *blkioController)) *blkioController

NewBlkio returns a Blkio controller given the root folder of cgroups. It may optionally accept other configuration options, such as ProcRoot(path)

func NewCpu Uses

func NewCpu(root string) *cpuController

func NewCpuacct Uses

func NewCpuacct(root string) *cpuacctController

func NewCputset Uses

func NewCputset(root string) *cpusetController

func NewDevices Uses

func NewDevices(root string) *devicesController

func NewFreezer Uses

func NewFreezer(root string) *freezerController

func NewHugetlb Uses

func NewHugetlb(root string) (*hugetlbController, error)

func NewMemory Uses

func NewMemory(root string, options ...func(*memoryController)) *memoryController

NewMemory returns a Memory controller given the root folder of cgroups. It may optionally accept other configuration options, such as IgnoreModules(...)

func NewNamed Uses

func NewNamed(root string, name Name) *namedController

func NewNetCls Uses

func NewNetCls(root string) *netclsController

func NewNetPrio Uses

func NewNetPrio(root string) *netprioController

func NewPids Uses

func NewPids(root string) *pidsController

func NewRdma Uses

func NewRdma(root string) *rdmaController

func OptionalSwap Uses

func OptionalSwap() func(*memoryController)

OptionalSwap allows the memory controller to not fail if cgroups is not accounting Swap memory (there are no memory.memsw.* entries)

func ProcRoot Uses

func ProcRoot(path string) func(controller *blkioController)

ProcRoot overrides the default location of the "/proc" filesystem

func RequireDevices Uses

func RequireDevices(s Subsystem, p Path, err error) error

RequireDevices requires the device subsystem but no others

func RootPath Uses

func RootPath(subsysem Name) (string, error)

type CGMode Uses

type CGMode int

CGMode is the cgroups mode of the host system

const (
    // Unavailable cgroup mountpoint
    Unavailable CGMode = iota
    // Legacy cgroups v1
    // Hybrid with cgroups v1 and v2 controllers mounted
    // Unified with only cgroups v2 mounted

func Mode Uses

func Mode() CGMode

Mode returns the cgroups mode running on the host

type Cgroup Uses

type Cgroup interface {
    // New creates a new cgroup under the calling cgroup
    New(string, *specs.LinuxResources) (Cgroup, error)
    // Add adds a process to the cgroup (cgroup.procs)
    Add(Process) error
    // AddTask adds a process to the cgroup (tasks)
    AddTask(Process) error
    // Delete removes the cgroup as a whole
    Delete() error
    // MoveTo moves all the processes under the calling cgroup to the provided one
    // subsystems are moved one at a time
    MoveTo(Cgroup) error
    // Stat returns the stats for all subsystems in the cgroup
    Stat(...ErrorHandler) (*v1.Metrics, error)
    // Update updates all the subsystems with the provided resource changes
    Update(resources *specs.LinuxResources) error
    // Processes returns all the processes in a select subsystem for the cgroup
    Processes(Name, bool) ([]Process, error)
    // Tasks returns all the tasks in a select subsystem for the cgroup
    Tasks(Name, bool) ([]Task, error)
    // Freeze freezes or pauses all processes inside the cgroup
    Freeze() error
    // Thaw thaw or resumes all processes inside the cgroup
    Thaw() error
    // OOMEventFD returns the memory subsystem's event fd for OOM events
    OOMEventFD() (uintptr, error)
    // State returns the cgroups current state
    State() State
    // Subsystems returns all the subsystems in the cgroup
    Subsystems() []Subsystem

Cgroup handles interactions with the individual groups to perform actions on them as them main interface to this cgroup package

func Load Uses

func Load(hierarchy Hierarchy, path Path, opts ...InitOpts) (Cgroup, error)

Load will load an existing cgroup and allow it to be controlled All static path should not include `/sys/fs/cgroup/` prefix, it should start with your own cgroups name

func New Uses

func New(hierarchy Hierarchy, path Path, resources *specs.LinuxResources, opts ...InitOpts) (Cgroup, error)

New returns a new control via the cgroup cgroups interface

type ErrorHandler Uses

type ErrorHandler func(err error) error

ErrorHandler is a function that handles and acts on errors

type Hierarchy Uses

type Hierarchy func() ([]Subsystem, error)

Hierarchy enableds both unified and split hierarchy for cgroups

func SingleSubsystem Uses

func SingleSubsystem(baseHierarchy Hierarchy, subsystem Name) Hierarchy

SingleSubsystem returns a single cgroup subsystem within the base Hierarchy

type InitCheck Uses

type InitCheck func(Subsystem, Path, error) error

InitCheck allows subsystems errors to be checked when initialized or loaded

type InitConfig Uses

type InitConfig struct {
    // InitCheck can be used to check initialization errors from the subsystem
    InitCheck InitCheck

InitConfig provides configuration options for the creation or loading of a cgroup and its subsystems

type InitOpts Uses

type InitOpts func(*InitConfig) error

InitOpts allows configuration for the creation or loading of a cgroup

type Name Uses

type Name string

Name is a typed name for a cgroup subsystem

const (
    Devices   Name = "devices"
    Hugetlb   Name = "hugetlb"
    Freezer   Name = "freezer"
    Pids      Name = "pids"
    NetCLS    Name = "net_cls"
    NetPrio   Name = "net_prio"
    PerfEvent Name = "perf_event"
    Cpuset    Name = "cpuset"
    Cpu       Name = "cpu"
    Cpuacct   Name = "cpuacct"
    Memory    Name = "memory"
    Blkio     Name = "blkio"
    Rdma      Name = "rdma"
const (
    SystemdDbus Name = "systemd"

func Subsystems Uses

func Subsystems() []Name

Subsystems returns a complete list of the default cgroups available on most linux systems

type Path Uses

type Path func(subsystem Name) (string, error)

func NestedPath Uses

func NestedPath(suffix string) Path

NestedPath will nest the cgroups based on the calling processes cgroup placing its child processes inside its own path

func PidPath Uses

func PidPath(pid int) Path

PidPath will return the correct cgroup paths for an existing process running inside a cgroup This is commonly used for the Load function to restore an existing container

func Slice Uses

func Slice(slice, name string) Path

func StaticPath Uses

func StaticPath(path string) Path

StaticPath returns a static path to use for all cgroups

type PerfEventController Uses

type PerfEventController struct {
    // contains filtered or unexported fields

func NewPerfEvent Uses

func NewPerfEvent(root string) *PerfEventController

func (*PerfEventController) Name Uses

func (p *PerfEventController) Name() Name

func (*PerfEventController) Path Uses

func (p *PerfEventController) Path(path string) string

type Process Uses

type Process struct {
    // Subsystem is the name of the subsystem that the process is in
    Subsystem Name
    // Pid is the process id of the process
    Pid int
    // Path is the full path of the subsystem and location that the process is in
    Path string

type State Uses

type State string

State is a type that represents the state of the current cgroup

const (
    Unknown  State = ""
    Thawed   State = "thawed"
    Frozen   State = "frozen"
    Freezing State = "freezing"
    Deleted  State = "deleted"

type Subsystem Uses

type Subsystem interface {
    Name() Name

func Systemd Uses

func Systemd() ([]Subsystem, error)

func V1 Uses

func V1() ([]Subsystem, error)

V1 returns all the groups in the default cgroups mountpoint in a single hierarchy

type SystemdController Uses

type SystemdController struct {
    // contains filtered or unexported fields

func NewSystemd Uses

func NewSystemd(root string) (*SystemdController, error)

func (*SystemdController) Create Uses

func (s *SystemdController) Create(path string, resources *specs.LinuxResources) error

func (*SystemdController) Delete Uses

func (s *SystemdController) Delete(path string) error

func (*SystemdController) Name Uses

func (s *SystemdController) Name() Name

type Task Uses

type Task struct {
    // Subsystem is the name of the subsystem that the task is in
    Subsystem Name
    // Pid is the process id of the task
    Pid int
    // Path is the full path of the subsystem and location that the task is in
    Path string


v2Devicefilter containes eBPF device filter program

Package cgroups imports 21 packages (graph) and is imported by 261 packages. Updated 2019-12-06. Refresh now. Tools for package owners.