Documentation ¶
Index ¶
- Constants
- func Subsys(name string, executor executor.Executor, timeout time.Duration) (bool, error)
- func SubsysMounts(executor executor.Executor, timeout time.Duration) (map[string]string, error)
- func SubsysPath(name string, executor executor.Executor, timeout time.Duration) (string, error)
- type ByPathLength
- type CPUSet
- type Cgroup
- type Filesystem
- type Metadata
Constants ¶
const ( // CPUSetController is the canonical name of the cgroups cpuset controller. CPUSetController = "cpuset" // CPUController is the canonical name of the cgroups cpu controller. CPUController = "cpu" // MemoryController is the canonical name of the cgroups memory controller. MemoryController = "memory" // DefaultCommandTimeout is the default amount of time to wait for // dispatched commands to finish executing. DefaultCommandTimeout = 10 * time.Second )
const ( // CPUSetMems is the name of the memory node attribute for a cpuset. CPUSetMems = "cpuset.mems" // CPUSetCpus is the name of the cpus attribute for a cpuset. CPUSetCpus = "cpuset.cpus" // CPUSetCPUExclusive is the name of the exclusive cpu attribute // for a cpuset. CPUSetCPUExclusive = "cpuset.cpu_exclusive" // CPUSetMemExclusive is the name of the exclusive memory node attribute // for a cpuset. CPUSetMemExclusive = "cpuset.mem_exclusive" )
Variables ¶
This section is empty.
Functions ¶
func SubsysMounts ¶
SubsysMounts returns a map of cgroup subsystem controller names to mount points in the file system.
Types ¶
type ByPathLength ¶
type ByPathLength []Cgroup
ByPathLength implements sort.Interface for []Cgroup. We define a partial order on Cgroups based on path length. For a slice of Cgroups in an ancestry chain this yields a topological sort beginning with the root of the Cgroup hierarchy.
func (ByPathLength) Len ¶
func (b ByPathLength) Len() int
Len returns the length of the Cgroup slice. This method satisfies part of sort.Interface.
func (ByPathLength) Less ¶
func (b ByPathLength) Less(i, j int) bool
Less returns true if the Cgroup at index i has a shorter path than the Cgroup at index j.. This method satisfies part of sort.Interface.
func (ByPathLength) Swap ¶
func (b ByPathLength) Swap(i int, j int)
Swap swaps two elements in the Cgroup slice. This method satisfies part of sort.Interface.
type CPUSet ¶
type CPUSet interface { isolation.Isolation // Cgroup returns the underlying cgroup for this CPUSet. Cgroup() Cgroup // Cpus returns the set of cpus allocated to this CPUSet. Cpus() isolation.IntSet // Cpus returns the set of memory nodes allocated to this CPUSet. Mems() isolation.IntSet // CPUExclusive returns true if this CPUSet's cpus are allocated // exclusively.. CPUExclusive() bool // MemExclusive returns true if this CPUSet's memory nodes are allocated // exclusively.. MemExclusive() bool }
CPUSet represents a cgroup in the cpuset hierarchy.
func NewCPUSet ¶
func NewCPUSet(path string, cpus, mems isolation.IntSet, cpuExclusive, memExclusive bool) (CPUSet, error)
NewCPUSet creates a new CPUSet with the default (local) executor and default timeout.
func NewCPUSetWithExecutor ¶
func NewCPUSetWithExecutor(path string, cpus isolation.IntSet, mems isolation.IntSet, cpuExclusive bool, memExclusive bool, executor executor.Executor, timeout time.Duration) (CPUSet, error)
NewCPUSetWithExecutor creates a new CPUSet with the supplied executor and timeout.
type Cgroup ¶
type Cgroup interface { isolation.Isolation Metadata Filesystem }
Cgroup represents a Linux control group. See https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt
Usage of this interface requires the libcgroup tools to be installed on the system. This library interacts with cgroups by shelling out to utility programs like `cgcreate`, `cgexec`, `cgget` and friends.
func NewCgroup ¶
NewCgroup returns a new Cgroup with the supplied controllers and path. Returns an error if no controllers are specified or the path is empty.
func NewCgroupWithExecutor ¶
func NewCgroupWithExecutor(controllers []string, path string, executor executor.Executor, cmdTimeout time.Duration) (Cgroup, error)
NewCgroupWithExecutor returns a new Cgroup with the supplied controllers, path and executor. Returns an error if no controllers are specified or the path is empty.
type Filesystem ¶
type Filesystem interface { // AbsPath returns the absolute path to this cgroup within the // VFS mount for the specified controller. // Returns the empty string if the controller is not a member of // this cgroup's controllers. // e.g. `d, err := cgroup.AbsPath("cpuset")` AbsPath(controller string) string // Exists returns `true` iff this cgroup is present in all of its // controller hierarchies. Exists() (bool, error) // Destroy removes this cgroup. // If recursive is specified, also destroy this cgroup's children. // Returns an error if this cgroup has children but recurvisve was not // specified. // Returns an error if this cgroup cannot be destroyed. Destroy(recursive bool) error // Tasks returns the pids for this cgroup and the supplied controller. // Returns an error if the controller is not a member of // this cgroup's controllers. // // NB: Linux pid range is [0, 2^22]; see /proc/sys/kernel/pid_max. Tasks(controller string) (isolation.IntSet, error) // Get returns the value of an attribute for this Cgroup. Get(name string) (string, error) // Set overwrites the value of an attribute for this Cgroup. Set(name string, value string) error // SetAndCheck overwrites the value of an attribute for this Cgroup and // returns an error if a subsequent read of the same attribute does // not exactly match the written value. SetAndCheck(name string, value string) error }
Filesystem represents Linux control group's backing virtual file system. These methods shell out to external libcgroup-tools programs.
type Metadata ¶
type Metadata interface { // Controllers returns this cgroup's controllers. Controllers() []string // Path returns this cgroup's path in the hierarchy. Path() string // IsRoot returns true if this cgroup is the root of the hierarchy. IsRoot() bool // Parent returns the direct ancestor of this cgroup, or nil if this // is the root. Parent() Cgroup // Ancestors returns all ancestors of this cgroup, in depth order // beginning with the root of the hierarchy. The result does not // contain this cgroup. Ancestors() []Cgroup // Spec returns an identifier compatible with libcgroup-tools. // Returns a string like 'cpu,cpuset:/my/cool/group'. Spec() string }
Metadata represents a Linux control group's metadata. These methods do not shell out to external libcgroup-tools programs.