cgroups

package
v0.58.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 24 Imported by: 30

Documentation

Index

Constants

View Source
const (

	// CPU is the cpu controller
	CPU = "cpu"
	// CPUAcct is the cpuacct controller
	CPUAcct = "cpuacct"
	// CPUset is the cpuset controller
	CPUset = "cpuset"
	// Memory is the memory controller
	Memory = "memory"
	// Pids is the pids controller
	Pids = "pids"
	// Blkio is the blkio controller
	Blkio = "blkio"
)

Variables

View Source
var (
	// ErrCgroupDeleted means the cgroup was deleted
	ErrCgroupDeleted = errors.New("cgroup deleted")
	// ErrCgroupV1Rootless means the cgroup v1 were attempted to be used in rootless environment
	ErrCgroupV1Rootless = errors.New("no support for CGroups V1 in rootless environments")
	ErrStatCgroup       = errors.New("no cgroup available for gathering user statistics")
)
View Source
var TestMode bool

Functions

func AvailableControllers added in v0.57.0

func AvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error)

AvailableControllers get string:bool map of all the available controllers

func BlkioFiles added in v0.57.0

func BlkioFiles(cgroupPath string) (wtFile, wtDevFile string)

BlkioFiles gets the proper files for blkio weights

func GetCgroupProcess added in v0.58.0

func GetCgroupProcess(pid int) (string, error)

GetCgroupProcess returns the cgroup for the specified process process.

func GetOwnCgroup added in v0.58.0

func GetOwnCgroup() (string, error)

GetOwnCgroup returns the cgroup for the current process.

func GetOwnCgroupDisallowRoot added in v0.58.0

func GetOwnCgroupDisallowRoot() (string, error)

func IsCgroup2UnifiedMode

func IsCgroup2UnifiedMode() (bool, error)

IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode.

func MaybeMoveToSubCgroup added in v0.58.0

func MaybeMoveToSubCgroup() error

MaybeMoveToSubCgroup moves the current process in a sub cgroup when it is running in the root cgroup on a system that uses cgroupv2.

func MoveUnderCgroup added in v0.58.0

func MoveUnderCgroup(cgroup, subtree string, processes []uint32) error

MoveUnderCgroup moves a group of processes to a new cgroup. If cgroup is the empty string, then the current calling process cgroup is used. If processes is empty, then the processes from the current cgroup are moved.

func MoveUnderCgroupSubtree added in v0.58.0

func MoveUnderCgroupSubtree(subtree string) error

MoveUnderCgroupSubtree moves the PID under a cgroup subtree.

func OpenFile added in v0.49.0

func OpenFile(dir, file string, flags int) (*os.File, error)

OpenFile opens a cgroup file with the given flags

func ReadFile added in v0.49.0

func ReadFile(dir, file string) (string, error)

ReadFile reads from a cgroup file, opening it with the read only flag

func SetBlkioThrottle added in v0.49.0

func SetBlkioThrottle(res *configs.Resources, cgroupPath string) error

SetBlkioThrottle sets the throttle limits for the cgroup

func SystemCPUUsage added in v0.57.0

func SystemCPUUsage() (uint64, error)

SystemCPUUsage returns the system usage for all the cgroups

func UserConnection added in v0.57.0

func UserConnection(uid int) (*systemdDbus.Conn, error)

UserConnection returns an user connection to D-BUS

func UserOwnsCurrentSystemdCgroup

func UserOwnsCurrentSystemdCgroup() (bool, error)

UserOwnsCurrentSystemdCgroup checks whether the current EUID owns the current cgroup.

func WriteFile added in v0.49.0

func WriteFile(dir, file, data string) error

WriteFile writes to a cgroup file

Types

type BlkioDev added in v0.49.0

type BlkioDev struct {
	Device string
	Bytes  uint64
}

type CgroupControl

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

CgroupControl controls a cgroup hierarchy

func Load

func Load(path string) (*CgroupControl, error)

Load loads an existing cgroup control

func New

func New(path string, resources *configs.Resources) (*CgroupControl, error)

New creates a new cgroup control

func NewSystemd

func NewSystemd(path string, resources *configs.Resources) (*CgroupControl, error)

NewSystemd creates a new cgroup control

func (*CgroupControl) AddPid

func (c *CgroupControl) AddPid(pid int) error

AddPid moves the specified pid to the cgroup

func (*CgroupControl) CreateSystemdUnit

func (c *CgroupControl) CreateSystemdUnit(path string) error

CreateSystemdUnit creates the systemd cgroup

func (*CgroupControl) CreateSystemdUserUnit

func (c *CgroupControl) CreateSystemdUserUnit(path string, uid int) error

CreateSystemdUserUnit creates the systemd cgroup for the specified user

func (*CgroupControl) Delete

func (c *CgroupControl) Delete() error

Delete cleans a cgroup

func (*CgroupControl) DeleteByPath

func (c *CgroupControl) DeleteByPath(path string) error

DeleteByPath deletes the specified cgroup path

func (*CgroupControl) DeleteByPathConn

func (c *CgroupControl) DeleteByPathConn(path string, conn *systemdDbus.Conn) error

DeleteByPathConn deletes the specified cgroup path using the specified dbus connection if needed.

func (*CgroupControl) Stat

func (c *CgroupControl) Stat() (*cgroups.Stats, error)

Stat returns usage statistics for the cgroup

func (*CgroupControl) Update

func (c *CgroupControl) Update(resources *configs.Resources) error

Update updates the cgroups

Jump to

Keyboard shortcuts

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