cgroups

package
v0.0.0-...-50ffc52 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCgroupPath = "/sys/fs/cgroup"
)

Variables

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

Functions

func Check

func Check() error

func Fix

func Fix() error

func NestedGroupPath

func NestedGroupPath(suffix string) (string, error)

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

func PidGroupPath

func PidGroupPath(pid int) (string, error)

PidGroupPath 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 VerifyGroupPath

func VerifyGroupPath(g string) error

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

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

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

Types

type BFQ

type BFQ struct {
	Weight uint16
}

type CGMode

type CGMode int

CGMode is the cgroups mode of the host system

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

func Mode

func Mode() CGMode

Mode returns the cgroups mode running on the host

type CPU

type CPU struct {
	Weight *uint64
	Max    CPUMax
	Cpus   string
	Mems   string
}

func (*CPU) Values

func (r *CPU) Values() (o []Value)

type CPUMax

type CPUMax string

func NewCPUMax

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

type ControllerToggle

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

type Entry

type Entry struct {
	Type  IOType
	Major int64
	Minor int64
	Rate  uint64
}

func (Entry) String

func (e Entry) String() string

type Event

type Event struct {
	Low     uint64
	High    uint64
	Max     uint64
	OOM     uint64
	OOMKill uint64
}

type HugeTlb

type HugeTlb []HugeTlbEntry

func (*HugeTlb) Values

func (r *HugeTlb) Values() (o []Value)

type HugeTlbEntry

type HugeTlbEntry struct {
	HugePageSize string
	Limit        uint64
}

type IO

type IO struct {
	BFQ BFQ
	Max []Entry
}

func (*IO) Values

func (i *IO) Values() (o []Value)

type IOType

type IOType string
const (
	ReadBPS   IOType = "rbps"
	WriteBPS  IOType = "wbps"
	ReadIOPS  IOType = "riops"
	WriteIOPS IOType = "wiops"
)

type Manager

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

func LoadManager

func LoadManager(mountpoint string, group string) (*Manager, error)

func NewManager

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

func (*Manager) AddProc

func (c *Manager) AddProc(pid int) error

func (*Manager) AddThread

func (c *Manager) AddThread(tid uint64) error

func (*Manager) Controllers

func (c *Manager) Controllers() ([]string, error)

func (*Manager) Delete

func (c *Manager) Delete() error

func (*Manager) EventChan

func (c *Manager) EventChan() (<-chan Event, <-chan error)

func (*Manager) Freeze

func (c *Manager) Freeze() error

func (*Manager) MemoryEventFD

func (c *Manager) MemoryEventFD() (int, uint32, error)

MemoryEventFD returns inotify file descriptor and 'memory.events' inotify watch descriptor

func (*Manager) MoveTo

func (c *Manager) MoveTo(destination *Manager) error

func (*Manager) NewChild

func (c *Manager) NewChild(name string, resources *Resources) (*Manager, error)

func (*Manager) Procs

func (c *Manager) Procs(recursive bool) ([]int, error)

func (*Manager) RootControllers

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

func (*Manager) Thaw

func (c *Manager) Thaw() error

func (*Manager) ToggleControllers

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

func (*Manager) Update

func (c *Manager) Update(resources *Resources) error

type Memory

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

func (*Memory) Values

func (r *Memory) Values() (o []Value)

type Mount

type Mount struct {
	Device         string
	MountPoint     string
	FileSystemType string
	Flags          string
	Bsize          int64
	Blocks         uint64
	Total          uint64
	Used           uint64
	Avail          uint64
	PCT            uint8
}

Mount is a structure used to contain mount point data

type Pids

type Pids struct {
	Max int64
}

func (*Pids) Values

func (r *Pids) Values() (o []Value)

type Resources

type Resources struct {
	CPU     *CPU
	Memory  *Memory
	Pids    *Pids
	IO      *IO
	HugeTlb *HugeTlb
}

Resources for a cgroups v2 unified hierarchy

func (*Resources) EnabledControllers

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

EnabledControllers returns the list of all not nil resource controllers

func (*Resources) Values

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

Values returns the raw filenames and values that can be written to the unified hierarchy

type State

type State string

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

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

func (State) Values

func (s State) Values() []Value

type Value

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

Value of a cgroup setting

Jump to

Keyboard shortcuts

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