Documentation ¶
Overview ¶
Package cgroup
Index ¶
- Constants
- Variables
- func GetCPUPeriod(path string) (CPUPeriod uint64, err error)
- func GetCPUQuota(path string) (CPUQuota int64, err error)
- func GetCPUShares(path string) (shares uint64, err error)
- func GetCgroupParamInt(cgroupPath, cgroupFile string) (int64, error)
- func GetCgroupParamUint(cgroupPath, cgroupFile string) (uint64, error)
- func GetFreezerStats(path string) (api.FreezerState, error)
- func GetMemoryLimit(path string) (limit int64, err error)
- func MilliCPUToQuota(milliCPU int64, period int64) (quota int64)
- func MilliCPUToShares(milliCPU int64) uint64
- func QuotaToMilliCPU(quota int64, period int64) (milliCPU int64)
- type CgroupConfig
- type CgroupManager
- type CgroupName
- type CgroupSubsystems
- type Empty
- type ErrUnsupportedCgroup
- type Int
- func (s Int) Delete(items ...int)
- func (s Int) Difference(s2 Int) Int
- func (s1 Int) Equal(s2 Int) bool
- func (s Int) Has(item int) bool
- func (s Int) HasAll(items ...int) bool
- func (s Int) HasAny(items ...int) bool
- func (s Int) Insert(items ...int)
- func (s1 Int) Intersection(s2 Int) Int
- func (s1 Int) IsSuperset(s2 Int) bool
- func (s Int) Len() int
- func (s Int) List() []int
- func (s Int) PopAny() (int, bool)
- func (s1 Int) Union(s2 Int) Int
- func (s Int) UnsortedList() []int
- type ResourceParams
- type String
- func (s String) Delete(items ...string)
- func (s String) Difference(s2 String) String
- func (s1 String) Equal(s2 String) bool
- func (s String) Has(item string) bool
- func (s String) HasAll(items ...string) bool
- func (s String) HasAny(items ...string) bool
- func (s String) Insert(items ...string)
- func (s1 String) Intersection(s2 String) String
- func (s1 String) IsSuperset(s2 String) bool
- func (s String) Len() int
- func (s String) List() []string
- func (s String) PopAny() (string, bool)
- func (s1 String) Union(s2 String) String
- func (s String) UnsortedList() []string
Constants ¶
const ( // Taken from lmctfy https://github.com/google/lmctfy/blob/master/lmctfy/controllers/cpu_controller.cc 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 )
const ( DefaultCgroupPath = "/sys/fs/cgroup" CFSPeriodFile = "cpu.cfs_period_us" CFSQuotaFile = "cpu.cfs_quota_us" MemoryLimitsFile = "memory.limit_in_bytes" )
Variables ¶
var (
ErrNotValidFormat = errors.New("line is not a valid key value format")
)
Functions ¶
func GetCPUPeriod ¶
func GetCPUQuota ¶
func GetCPUShares ¶
func GetCgroupParamInt ¶
Gets a single int64 value from the specified cgroup file.
func GetCgroupParamUint ¶
Gets a single uint64 value from the specified cgroup file.
func GetFreezerStats ¶
func GetFreezerStats(path string) (api.FreezerState, error)
func GetMemoryLimit ¶
func MilliCPUToQuota ¶
MilliCPUToQuota converts milliCPU to CFS quota and period values.
func MilliCPUToShares ¶
MilliCPUToShares converts the milliCPU to CFS shares.
func QuotaToMilliCPU ¶
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 ErrUnsupportedCgroup ¶
type ErrUnsupportedCgroup struct {
CgroupName string
}
func (ErrUnsupportedCgroup) Error ¶
func (err ErrUnsupportedCgroup) Error() string
type Int ¶
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 (Int) Difference ¶
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 ¶
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) Intersection ¶
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 ¶
IsSuperset returns true if and only if s1 is a superset of s2.
func (Int) Union ¶
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 ¶
UnsortedList returns the slice with contents in random order.
type ResourceParams ¶
type String ¶
sets.String is a set of strings, implemented via map[string]struct{} for minimal memory consumption.
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) Difference ¶
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 ¶
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) Intersection ¶
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 ¶
IsSuperset returns true if and only if s1 is a superset of s2.
func (String) Union ¶
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 ¶
UnsortedList returns the slice with contents in random order.