Documentation ¶
Index ¶
- Constants
- Variables
- func AttachCurrentProc(cgroup string) error
- func BootstrapChild(groupPath string, resources Resources) error
- func BootstrapParent(groupPath string, controllers ...Controller) error
- func CheckCgroupV2Enabled() error
- func MapResourceToFiles(resources Resources) (map[string]interface{}, error)
- func ValidateGroupPath(in string) error
- type CPU
- type Controller
- type IO
- type IOMax
- type IOMaxEntry
- type IOType
- type Memory
- type Resources
Constants ¶
const (
// PseudoFsPrefix represents cgroup pseudo-filesystem prefix.
PseudoFsPrefix = "/sys/fs/cgroup/"
)
Variables ¶
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 ¶
AttachCurrentProc attaches current process PID to a given cgroup.
func BootstrapChild ¶
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 ¶
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 ¶
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 IOMaxEntry ¶
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" )