Documentation
¶
Overview ¶
Package cgroup provices builder to create multiple different cgroup-v1 sub groups under systemd defined mount path (i.e.,sys/fs/cgroup).
Current available:
cpu cpuset cpuacct memory pids
Current not available: devices, freezer, net_cls, blkio, perf_event, net_prio, huge_tlb, rdma
Additional ideas:
cpu share(not used): cpu.share reclaim pages from old process: memory.force_empty (tasks kill are managed out of cgroup as freeze takes some time) freeze: freezer.state
Index ¶
- Variables
- func CreateSubCgroupPath(group, prefix string) (string, error)
- func EnsureDirExists(path string) error
- func GetAllSubCgroup() (map[string]bool, error)
- func GetCgroupInfo() (map[string]Info, error)
- type Builder
- func (b *Builder) Build() (cg *Cgroup, err error)
- func (b *Builder) FilterByEnv() (*Builder, error)
- func (b *Builder) String() string
- func (b *Builder) WithCPU() *Builder
- func (b *Builder) WithCPUAcct() *Builder
- func (b *Builder) WithCPUSet() *Builder
- func (b *Builder) WithMemory() *Builder
- func (b *Builder) WithPids() *Builder
- type Cgroup
- func (c *Cgroup) AddProc(pid int) error
- func (c *Cgroup) CpuacctUsage() (uint64, error)
- func (c *Cgroup) Destroy() error
- func (c *Cgroup) FindMemoryStatProperty(prop string) (uint64, error)
- func (c *Cgroup) MemoryMaxUsageInBytes() (uint64, error)
- func (c *Cgroup) MemoryMemswMaxUsageInBytes() (uint64, error)
- func (c *Cgroup) SetCPUCfsPeriod(p uint64) error
- func (c *Cgroup) SetCPUCfsQuota(p uint64) error
- func (c *Cgroup) SetCpuacctUsage(i uint64) error
- func (c *Cgroup) SetCpusetCpus(b []byte) error
- func (c *Cgroup) SetCpusetMems(b []byte) error
- func (c *Cgroup) SetMemoryLimitInBytes(i uint64) error
- func (c *Cgroup) SetMemoryMaxUsageInBytes(i uint64) error
- func (c *Cgroup) SetMemoryMemswLimitInBytes(i uint64) error
- func (c *Cgroup) SetPidsMax(i uint64) error
- type Info
- type SubCgroup
Constants ¶
This section is empty.
Variables ¶
var ErrNotInitialized = errors.New("cgroup was not initialized")
ErrNotInitialized returned when trying to read from not initialized cgroup
Functions ¶
func CreateSubCgroupPath ¶ added in v0.2.0
CreateSubCgroupPath creates path for sub-cgroup with given group and prefix
func EnsureDirExists ¶
EnsureDirExists creates directories if the path not exists
func GetAllSubCgroup ¶
GetAllSubCgroup reads /proc/cgroups and get all available sub-cgroup as set
func GetCgroupInfo ¶ added in v0.5.8
GetCgroupInfo read /proc/cgroups and return the result
Types ¶
type Builder ¶
Builder builds cgroup directories available: cpuacct, memory, pids
func NewBuilder ¶
NewBuilder return a dumb builder without any sub-cgroup
func (*Builder) FilterByEnv ¶
FilterByEnv reads /proc/cgroups and filter out non-exists ones
func (*Builder) WithCPUAcct ¶
WithCPUAcct includes cpuacct cgroup
func (*Builder) WithCPUSet ¶ added in v0.5.3
WithCPUSet includes cpuset cgroup
func (*Builder) WithMemory ¶
WithMemory includes memory cgroup
type Cgroup ¶ added in v0.2.0
type Cgroup struct {
// contains filtered or unexported fields
}
Cgroup is the combination of sub-cgroups
func (*Cgroup) CpuacctUsage ¶ added in v0.2.0
CpuacctUsage read cpuacct.usage in ns
func (*Cgroup) Destroy ¶ added in v0.2.0
Destroy removes dir for sub-cgroup, errors are ignored if remove one failed
func (*Cgroup) FindMemoryStatProperty ¶ added in v0.2.0
FindMemoryStatProperty find certain property from memory.stat
func (*Cgroup) MemoryMaxUsageInBytes ¶ added in v0.2.0
MemoryMaxUsageInBytes read memory.max_usage_in_bytes
func (*Cgroup) MemoryMemswMaxUsageInBytes ¶ added in v0.5.8
MemoryMemswMaxUsageInBytes read memory.memsw.max_usage_in_bytes
func (*Cgroup) SetCPUCfsPeriod ¶ added in v0.5.8
SetCPUCfsPeriod set cpu.cfs_period_us in us
func (*Cgroup) SetCPUCfsQuota ¶ added in v0.5.8
SetCPUCfsQuota set cpu.cfs_quota_us in us
func (*Cgroup) SetCpuacctUsage ¶ added in v0.2.0
SetCpuacctUsage write cpuacct.usage in ns
func (*Cgroup) SetCpusetCpus ¶ added in v0.5.3
SetCpusetCpus set cpuset.cpus
func (*Cgroup) SetCpusetMems ¶ added in v0.5.3
SetCpusetMems set cpuset.mems
func (*Cgroup) SetMemoryLimitInBytes ¶ added in v0.2.0
SetMemoryLimitInBytes write memory.limit_in_bytes
func (*Cgroup) SetMemoryMaxUsageInBytes ¶ added in v0.2.0
SetMemoryMaxUsageInBytes write cpuacct.usage in ns
func (*Cgroup) SetMemoryMemswLimitInBytes ¶ added in v0.5.8
SetMemoryMemswLimitInBytes write memory.memsw.limit_in_bytes
func (*Cgroup) SetPidsMax ¶ added in v0.2.0
SetPidsMax write pids.max
type SubCgroup ¶ added in v0.2.0
type SubCgroup struct {
// contains filtered or unexported fields
}
SubCgroup is the accessor for single cgroup resource with given path
func NewSubCgroup ¶ added in v0.2.0
NewSubCgroup creates a cgroup accessor with given path (path needs to be created in advance)
func (*SubCgroup) ReadFile ¶ added in v0.2.0
ReadFile reads cgroup file and handles potential EINTR error while read to the slow device (cgroup)