cgroup

package
v0.0.0-...-d691e2b Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package cgroup

Index

Constants

View Source
const (
	// Taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc
	MinShares     = 2
	SharesPerCPU  = 1024
	MilliCPUToCPU = 1000

	// 100000 is equivalent to 100ms
	QuotaPeriod    = 100000
	MinQuotaPeriod = 1000

	// default memory limits is PAGE_COUNTER_MAX, now support 64 bit arch
	// refs: https://github.com/torvalds/linux/blob/master/include/linux/page_counter.h
	MemoryNoLimits = 0x7FFFFFFFFFFFF000
	CPUNoLimits    = -1
)
View Source
const (
	DefaultCgroupPath = "/sys/fs/cgroup"

	CFSPeriodFile    = "cpu.cfs_period_us"
	CFSQuotaFile     = "cpu.cfs_quota_us"
	CPUShares        = "cpu.shares"
	MemoryLimitsFile = "memory.limit_in_bytes"
)

Variables

View Source
var (
	ErrNotValidFormat = errors.New("line is not a valid key value format")
)

Functions

func GetCPUPeriod

func GetCPUPeriod(path string) (CPUPeriod uint64, err error)

func GetCPUQuota

func GetCPUQuota(path string) (CPUQuota int64, err error)

func GetCPUShares

func GetCPUShares(path string) (shares uint64, err error)

func GetCgroupParamInt

func GetCgroupParamInt(cgroupPath, cgroupFile string) (int64, error)

Gets a single int64 value from the specified cgroup file.

func GetCgroupParamUint

func GetCgroupParamUint(cgroupPath, cgroupFile string) (uint64, error)

Gets a single uint64 value from the specified cgroup file.

func GetFreezerStats

func GetFreezerStats(path string) (api.FreezerState, error)

func GetMemoryLimit

func GetMemoryLimit(path string) (limit int64, err error)

func MilliCPUToQuota

func MilliCPUToQuota(milliCPU int64, period int64) (quota int64)

MilliCPUToQuota converts milliCPU to CFS quota and period values.

func MilliCPUToShares

func MilliCPUToShares(milliCPU int64) uint64

MilliCPUToShares converts the milliCPU to CFS shares.

func QuotaToMilliCPU

func QuotaToMilliCPU(quota int64, period int64) (milliCPU int64)

QuotaToMilliCPU converts CFS quota and period values to milliCPU.

Types

type CgroupConfig

type CgroupConfig struct {
	// Fully qualified name prior to any driver specific conversions.
	Name CgroupName
	// ResourceParameters contains various cgroups settings to apply.
	ResourceParameters *runtimeApi.ResourceConfig
}

CgroupConfig holds the cgroup configuration information. This is common object which is used to specify cgroup information to both systemd and raw cgroup fs implementation of the Cgroup Manager interface.

type CgroupManager

type CgroupManager interface {
	// Create creates and applies the cgroup configurations on the cgroup.
	// It just creates the leaf cgroups.
	// It expects the parent cgroup to already exist.
	Create(*CgroupConfig) error
	// Destroy the cgroup.
	Destroy(*CgroupConfig) error
	// Update cgroup configuration.
	Update(*CgroupConfig) error
	// Exists checks if the cgroup already exists
	Exists(name CgroupName) bool
	// Name returns the literal cgroupfs name on the host after any driver specific conversions.
	// We would expect systemd implementation to make appropriate name conversion.
	// For example, if we pass /foo/bar
	// then systemd should convert the name to something like
	// foo.slice/foo-bar.slice
	Name(name CgroupName) string
	// CgroupName converts the literal cgroupfs name on the host to an internal identifier.
	CgroupName(name string) CgroupName
	// Pids scans through all subsytems to find pids associated with specified cgroup.
	Pids(name CgroupName) []int
	// ReduceCPULimits reduces the CPU CFS values to the minimum amount of shares.
	ReduceCPULimits(cgroupName CgroupName) error
	// GetResourceStats returns statistics of the specified cgroup as read from the cgroup fs.
	GetResourceStats(name CgroupName) (*api.ResourceStats, error)
	// GetResourcesConfig
	GetResourcesConfig(r *ResourceParams) (config *runtimeApi.ResourceConfig, err error)
	// GetCgroupSubsysPath
	GetCgroupSubsysPath(subsys string) (path string, err error)
	// GetResourceConfig
	GetResourceConfig(name CgroupName) (resourceConfig *runtimeApi.ResourceConfig, err error)
}

CgroupManager allows for cgroup management. Supports Cgroup Creation ,Deletion and Updates.

func NewCgroupManager

func NewCgroupManager(cs *CgroupSubsystems, cgroupPath, cgroupDriver string) (m CgroupManager, err error)

NewCgroupManager is a factory method that returns a CgroupManager

type CgroupName

type CgroupName string

CgroupName is the abstract name of a cgroup prior to any driver specific conversion.

type CgroupSubsystems

type CgroupSubsystems struct {
	// Cgroup subsystem mounts.
	// e.g.: "/sys/fs/cgroup/cpu" -> ["cpu", "cpuacct"]
	Mounts []libcontainercgroups.Mount

	// Cgroup subsystem to their mount location.
	// e.g.: "cpu" -> "/sys/fs/cgroup/cpu"
	MountPoints map[string]string
}

CgroupSubsystems holds information about the mounted cgroup subsytem

func GetCgroupSubsystems

func GetCgroupSubsystems() (*CgroupSubsystems, error)

GetCgroupSubsystems returns information about the mounted cgroup subsystems

type Empty

type Empty struct{}

type ErrUnsupportedCgroup

type ErrUnsupportedCgroup struct {
	CgroupName string
}

func (ErrUnsupportedCgroup) Error

func (err ErrUnsupportedCgroup) Error() string

type Int

type Int map[int]Empty

sets.Int is a set of ints, implemented via map[int]struct{} for minimal memory consumption.

func IntKeySet

func IntKeySet(theMap interface{}) Int

IntKeySet creates a Int from a keys of a map[int](? extends interface{}). If the value passed in is not actually a map, this will panic.

func NewInt

func NewInt(items ...int) Int

New creates a Int from a list of values.

func (Int) Delete

func (s Int) Delete(items ...int)

Delete removes all items from the set.

func (Int) Difference

func (s Int) Difference(s2 Int) Int

Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}

func (Int) Equal

func (s1 Int) Equal(s2 Int) bool

Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)

func (Int) Has

func (s Int) Has(item int) bool

Has returns true if and only if item is contained in the set.

func (Int) HasAll

func (s Int) HasAll(items ...int) bool

HasAll returns true if and only if all items are contained in the set.

func (Int) HasAny

func (s Int) HasAny(items ...int) bool

HasAny returns true if any items are contained in the set.

func (Int) Insert

func (s Int) Insert(items ...int)

Insert adds items to the set.

func (Int) Intersection

func (s1 Int) Intersection(s2 Int) Int

Intersection returns a new set which includes the item in BOTH s1 and s2 For example: s1 = {a1, a2} s2 = {a2, a3} s1.Intersection(s2) = {a2}

func (Int) IsSuperset

func (s1 Int) IsSuperset(s2 Int) bool

IsSuperset returns true if and only if s1 is a superset of s2.

func (Int) Len

func (s Int) Len() int

Len returns the size of the set.

func (Int) List

func (s Int) List() []int

List returns the contents as a sorted int slice.

func (Int) PopAny

func (s Int) PopAny() (int, bool)

Returns a single element from the set.

func (Int) Union

func (s1 Int) Union(s2 Int) Int

Union returns a new set which includes items in either s1 or s2. For example: s1 = {a1, a2} s2 = {a3, a4} s1.Union(s2) = {a1, a2, a3, a4} s2.Union(s1) = {a1, a2, a3, a4}

func (Int) UnsortedList

func (s Int) UnsortedList() []int

UnsortedList returns the slice with contents in random order.

type ResourceParams

type ResourceParams struct {
	MemLimits   string
	CPURequests float64
	CPULimits   float64
}

type String

type String map[string]Empty

sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.

func NewString

func NewString(items ...string) String

New creates a String from a list of values.

func StringKeySet

func StringKeySet(theMap interface{}) String

StringKeySet creates a String from a keys of a map[string](? extends interface{}). If the value passed in is not actually a map, this will panic.

func (String) Delete

func (s String) Delete(items ...string)

Delete removes all items from the set.

func (String) Difference

func (s String) Difference(s2 String) String

Difference returns a set of objects that are not in s2 For example: s1 = {a1, a2, a3} s2 = {a1, a2, a4, a5} s1.Difference(s2) = {a3} s2.Difference(s1) = {a4, a5}

func (String) Equal

func (s1 String) Equal(s2 String) bool

Equal returns true if and only if s1 is equal (as a set) to s2. Two sets are equal if their membership is identical. (In practice, this means same elements, order doesn't matter)

func (String) Has

func (s String) Has(item string) bool

Has returns true if and only if item is contained in the set.

func (String) HasAll

func (s String) HasAll(items ...string) bool

HasAll returns true if and only if all items are contained in the set.

func (String) HasAny

func (s String) HasAny(items ...string) bool

HasAny returns true if any items are contained in the set.

func (String) Insert

func (s String) Insert(items ...string)

Insert adds items to the set.

func (String) Intersection

func (s1 String) Intersection(s2 String) String

Intersection returns a new set which includes the item in BOTH s1 and s2 For example: s1 = {a1, a2} s2 = {a2, a3} s1.Intersection(s2) = {a2}

func (String) IsSuperset

func (s1 String) IsSuperset(s2 String) bool

IsSuperset returns true if and only if s1 is a superset of s2.

func (String) Len

func (s String) Len() int

Len returns the size of the set.

func (String) List

func (s String) List() []string

ListAll returns the contents as a sorted string slice.

func (String) PopAny

func (s String) PopAny() (string, bool)

Returns a single element from the set.

func (String) Union

func (s1 String) Union(s2 String) String

Union returns a new set which includes items in either s1 or s2. For example: s1 = {a1, a2} s2 = {a3, a4} s1.Union(s2) = {a1, a2, a3, a4} s2.Union(s1) = {a1, a2, a3, a4}

func (String) UnsortedList

func (s String) UnsortedList() []string

UnsortedList returns the slice with contents in random order.

Jump to

Keyboard shortcuts

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