cgroup

package
v0.0.0-...-da0d16f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidGroupPath = errors.New("cgroups: invalid group path")
	ErrInvalidFormat    = errors.New("cgroups: parsing file with invalid format failed")
)

Functions

func DeviceFilter

func DeviceFilter(devices []specs.LinuxDeviceCgroup) (asm.Instructions, string, error)

func EnableNesting

func EnableNesting() error

EnableV2Nesting migrates all process in the container to nested /init path and enables all available controllers in the root cgroup

func LoadAttachCgroupDeviceFilter

func LoadAttachCgroupDeviceFilter(insts asm.Instructions, license string, dirFD int) (func() error, error)

LoadAttachCgroupDeviceFilter installs eBPF device filter program to /sys/fs/cgroup/<foo> directory.

Requires the system to be running in cgroup2 unified-mode with kernel >= 4.15 .

https://github.com/torvalds/linux/commit/ebc614f687369f9df99828572b1d85a7c2de3d92

func VerifyGroupPath

func VerifyGroupPath(p string) error

VerifyGroupPath verifies the format of group path string p. The format is same as the third field in /proc/PID/cgroup. e.g. "/user.slice/user-1001.slice/session-1.scope"

p must be a "clean" absolute path starts with "/", and must not contain "/sys/fs/cgroup" prefix.

VerifyGroupPath doesn't verify whether p actually exists on the system.

Types

type CGMode

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

func Mode

func Mode() CGMode

Mode returns the cgroup mode running the host.

type CPU

type CPU struct {
	Weight *uint64 // Weight is a pointer to a uint64, indicating the CPU weight for relative priority in resource allocation.
	Max    CPUMax  // Max represents the maximum CPU quota in the cgroup.
	Cpus   string  // Cpus represents the list of available CPU cores in the CPU group.
	Mems   string  // Mems represents the list of available memory nodes in the CPU group.
}

CPU represents the CPU-related attributes in a cgroup.

func (*CPU) Values

func (c *CPU) Values() (v []Value)

type CPUMax

type CPUMax string

CPUMax represents the maximum CPU quota in a cgroup. It is a string type alias used to define the maximum CPU quota, which can be either a numeric value (representing microseconds) or "max" (indicating no limit).

func NewCPUMax

func NewCPUMax(quota *int64, period *uint64) CPUMax

type ControllerToggle

type ControllerToggle int
const (
	Enable ControllerToggle = iota + 1
	Disable
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(mountpoint string, group string, resources *Resources) (*Manager, error)

NewManager new a cgroup, and set resources controllers

func (*Manager) RootControllers

func (m *Manager) RootControllers() ([]string, error)

RootControllers read /sys/fs/cgroup/cgroup.controllers content [cpuset cpu io memory pids rdma hugetlb]

func (*Manager) ToggleControllers

func (m *Manager) ToggleControllers(controllers []string, t ControllerToggle) error

type Memory

type Memory struct {
	Swap *int64
	Min  *int64
	Max  *int64
	Low  *int64
	High *int64
}

func (*Memory) Values

func (m *Memory) Values() (v []Value)

type Resources

type Resources struct {
	CPU     *CPU
	Memory  *Memory
	Devices []specs.LinuxDeviceCgroup // When len(Devices) is zero, devices are not controlled
}

Resources for a cgruop unified hierarchy

func (*Resources) EnabledControllers

func (r *Resources) EnabledControllers() (c []string)

EnabledControllers get resources enabled controllers

func (*Resources) Values

func (r *Resources) Values() (v []Value)

type Value

type Value struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL