cgroup

package
v0.0.0-...-87fd372 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PseudoFsPrefix represents cgroup pseudo-filesystem prefix.
	PseudoFsPrefix = "/sys/fs/cgroup/"
)

Variables

View Source
var (
	// ErrCgroupV2NotSupported indicates that the cgroup in version 2 is not enabled on a given OS.
	ErrCgroupV2NotSupported = errors.New("cgroup v2 is not enabled on OS under /sys/fs/cgroup/, enable it before running daemon")
)

Functions

func AttachCurrentProc

func AttachCurrentProc(cgroup string) error

AttachCurrentProc attaches current process PID to a given cgroup.

func BootstrapChild

func BootstrapChild(groupPath string, resources Resources) error

BootstrapChild bootstraps a parent child group with given resources' restrictions.

func BootstrapParent

func BootstrapParent(groupPath string, controllers ...Controller) error

BootstrapParent bootstraps a parent group where a proper controllers are enabled for children. TODO(simplification): it works only 1 level deep - /sys/fs/cgroup/{PARENT}/

func CheckCgroupV2Enabled

func CheckCgroupV2Enabled() error

CheckCgroupV2Enabled returns nil if cgroup v2 is enabled.

func MapResourceToFiles

func MapResourceToFiles(resources Resources) (map[string]interface{}, error)

MapResourceToFiles returns resources' settings indexed by a proper filename.

NOTE: Experimental approach - this function is "generic" but at the same time requires 3rd party lib (which uses reflection). This can be easily changed, and we can attach a dedicated method to each resource entity, similar to: https://github.com/containerd/cgroups/blob/2e502f6b9e43588a1108ebdd04c51ad2b04050f0/v2/cpu.go#L57

But I wanted to try this approach as it adds an easy way to associate a given field with a proper file which IMO give more friendly API:

Min int64 `filename:"memory.min,omitempty"`

func ValidateGroupPath

func ValidateGroupPath(in string) error

ValidateGroupPath verifies the cgroup path format.

Types

type CPU

type CPU struct {
	Max  string `filename:"cpu.max,omitempty"`
	Cpus string `filename:"cpuset.cpus,omitempty"`
	Mems string `filename:"cpuset.mems,omitempty"`
}

CPU represents settings for CPU controller.

type Controller

type Controller string

Controller represents cgroup v2 supported controllers.

const (
	MemoryController Controller = "memory"
	CPUController    Controller = "cpu"
	CPUSetController Controller = "cpuset"
	IOController     Controller = "io"
)

type IO

type IO struct {
	Max IOMax `filename:"io.max,omitempty"`
}

IO represents settings for IO controller.

type IOMax

type IOMax []IOMaxEntry

IOMax represents IOMax collection.

func (IOMax) Items

func (io IOMax) Items() []string

Items returns list of IO limits. It doesn't remove duplicated entries (same IOType).

type IOMaxEntry

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

IOMaxEntry represents settings for IO limits.

func (IOMaxEntry) String

func (e IOMaxEntry) String() string

String returns a data in io.max supported format.

type IOType

type IOType string
const (
	// ReadBPS represents read bytes per second.
	ReadBPS IOType = "rbps"
	// WriteBPS represents write bytes per second.
	WriteBPS IOType = "wbps"
	// ReadIOPS represents read IO operations per second.
	ReadIOPS IOType = "riops"
	// WriteIOPS represents write IO operations per second.
	WriteIOPS IOType = "wiops"
)

type Memory

type Memory struct {
	// Takes a memory size in bytes
	Min int64 `filename:"memory.min,omitempty"`
	Max int64 `filename:"memory.max,omitempty"`
}

Memory represents settings for Memory controller.

type Resources

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

Resources represents supported resource configuration.

Jump to

Keyboard shortcuts

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