cgroup

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 12 Imported by: 6

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

Constants

This section is empty.

Variables

View Source
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

func CreateSubCgroupPath(group, prefix string) (string, error)

CreateSubCgroupPath creates path for sub-cgroup with given group and prefix

func EnsureDirExists

func EnsureDirExists(path string) error

EnsureDirExists creates directories if the path not exists

func GetAllSubCgroup

func GetAllSubCgroup() (map[string]bool, error)

GetAllSubCgroup reads /proc/cgroups and get all available sub-cgroup as set

func GetCgroupInfo added in v0.5.8

func GetCgroupInfo() (map[string]Info, error)

GetCgroupInfo read /proc/cgroups and return the result

Types

type Builder

type Builder struct {
	Prefix string

	CPU     bool
	CPUSet  bool
	CPUAcct bool
	Memory  bool
	Pids    bool
}

Builder builds cgroup directories available: cpuacct, memory, pids

func NewBuilder

func NewBuilder(prefix string) *Builder

NewBuilder return a dumb builder without any sub-cgroup

func (*Builder) Build

func (b *Builder) Build() (cg *Cgroup, err error)

Build creates new cgrouup directories

func (*Builder) FilterByEnv

func (b *Builder) FilterByEnv() (*Builder, error)

FilterByEnv reads /proc/cgroups and filter out non-exists ones

func (*Builder) String

func (b *Builder) String() string

String prints the build properties

func (*Builder) WithCPU added in v0.5.8

func (b *Builder) WithCPU() *Builder

WithCPU includes cpu cgroup

func (*Builder) WithCPUAcct

func (b *Builder) WithCPUAcct() *Builder

WithCPUAcct includes cpuacct cgroup

func (*Builder) WithCPUSet added in v0.5.3

func (b *Builder) WithCPUSet() *Builder

WithCPUSet includes cpuset cgroup

func (*Builder) WithMemory

func (b *Builder) WithMemory() *Builder

WithMemory includes memory cgroup

func (*Builder) WithPids

func (b *Builder) WithPids() *Builder

WithPids includes pids 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) AddProc added in v0.2.0

func (c *Cgroup) AddProc(pid int) error

AddProc writes cgroup.procs to all sub-cgroup

func (*Cgroup) CpuacctUsage added in v0.2.0

func (c *Cgroup) CpuacctUsage() (uint64, error)

CpuacctUsage read cpuacct.usage in ns

func (*Cgroup) Destroy added in v0.2.0

func (c *Cgroup) Destroy() error

Destroy removes dir for sub-cgroup, errors are ignored if remove one failed

func (*Cgroup) FindMemoryStatProperty added in v0.2.0

func (c *Cgroup) FindMemoryStatProperty(prop string) (uint64, error)

FindMemoryStatProperty find certain property from memory.stat

func (*Cgroup) MemoryMaxUsageInBytes added in v0.2.0

func (c *Cgroup) MemoryMaxUsageInBytes() (uint64, error)

MemoryMaxUsageInBytes read memory.max_usage_in_bytes

func (*Cgroup) MemoryMemswMaxUsageInBytes added in v0.5.8

func (c *Cgroup) MemoryMemswMaxUsageInBytes() (uint64, error)

MemoryMemswMaxUsageInBytes read memory.memsw.max_usage_in_bytes

func (*Cgroup) SetCPUCfsPeriod added in v0.5.8

func (c *Cgroup) SetCPUCfsPeriod(p uint64) error

SetCPUCfsPeriod set cpu.cfs_period_us in us

func (*Cgroup) SetCPUCfsQuota added in v0.5.8

func (c *Cgroup) SetCPUCfsQuota(p uint64) error

SetCPUCfsQuota set cpu.cfs_quota_us in us

func (*Cgroup) SetCpuacctUsage added in v0.2.0

func (c *Cgroup) SetCpuacctUsage(i uint64) error

SetCpuacctUsage write cpuacct.usage in ns

func (*Cgroup) SetCpusetCpus added in v0.5.3

func (c *Cgroup) SetCpusetCpus(b []byte) error

SetCpusetCpus set cpuset.cpus

func (*Cgroup) SetCpusetMems added in v0.5.3

func (c *Cgroup) SetCpusetMems(b []byte) error

SetCpusetMems set cpuset.mems

func (*Cgroup) SetMemoryLimitInBytes added in v0.2.0

func (c *Cgroup) SetMemoryLimitInBytes(i uint64) error

SetMemoryLimitInBytes write memory.limit_in_bytes

func (*Cgroup) SetMemoryMaxUsageInBytes added in v0.2.0

func (c *Cgroup) SetMemoryMaxUsageInBytes(i uint64) error

SetMemoryMaxUsageInBytes write cpuacct.usage in ns

func (*Cgroup) SetMemoryMemswLimitInBytes added in v0.5.8

func (c *Cgroup) SetMemoryMemswLimitInBytes(i uint64) error

SetMemoryMemswLimitInBytes write memory.memsw.limit_in_bytes

func (*Cgroup) SetPidsMax added in v0.2.0

func (c *Cgroup) SetPidsMax(i uint64) error

SetPidsMax write pids.max

type Info added in v0.5.8

type Info struct {
	Hierarchy  int
	NumCgroups int
	Enabled    bool
}

Info reads the cgroup mount info from /proc/cgroups

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

func NewSubCgroup(p string) *SubCgroup

NewSubCgroup creates a cgroup accessor with given path (path needs to be created in advance)

func (*SubCgroup) ReadFile added in v0.2.0

func (c *SubCgroup) ReadFile(name string) ([]byte, error)

ReadFile reads cgroup file and handles potential EINTR error while read to the slow device (cgroup)

func (*SubCgroup) ReadUint added in v0.2.0

func (c *SubCgroup) ReadUint(filename string) (uint64, error)

ReadUint read uint64 from given file

func (*SubCgroup) WriteFile added in v0.2.0

func (c *SubCgroup) WriteFile(name string, content []byte) error

WriteFile writes cgroup file and handles potential EINTR error while writes to the slow device (cgroup)

func (*SubCgroup) WriteUint added in v0.2.0

func (c *SubCgroup) WriteUint(filename string, i uint64) error

WriteUint writes uint64 into given file

Jump to

Keyboard shortcuts

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