cgroup

package
v0.0.0-...-ff2c174 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cgroup provides an interface to read and write configuration to cgroup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOnlyV2

func IsOnlyV2() bool

IsOnlyV2 checks whether cgroups V2 is enabled and V1 is not.

Types

type Cgroup

type Cgroup struct {
	Name    string            `json:"name"`
	Parents map[string]string `json:"parents"`
	Own     map[string]bool   `json:"own"`
}

Cgroup represents a group inside all controllers. For example:

Name='/foo/bar' maps to /sys/fs/cgroup/<controller>/foo/bar on
all controllers.

If Name is relative, it uses the parent cgroup path to determine the location. For example:

Name='foo/bar' and Parent[ctrl]="/user.slice", then it will map to
/sys/fs/cgroup/<ctrl>/user.slice/foo/bar

func NewFromPid

func NewFromPid(pid int) (*Cgroup, error)

NewFromPid loads cgroup for the given process.

func NewFromSpec

func NewFromSpec(spec *specs.Spec) (*Cgroup, error)

NewFromSpec creates a new Cgroup instance if the spec includes a cgroup path. Returns nil otherwise. Cgroup paths are loaded based on the current process.

func (*Cgroup) CPUQuota

func (c *Cgroup) CPUQuota() (float64, error)

CPUQuota returns the CFS CPU quota.

func (*Cgroup) CPUUsage

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

CPUUsage returns the total CPU usage of the cgroup.

func (*Cgroup) Install

func (c *Cgroup) Install(res *specs.LinuxResources) error

Install creates and configures cgroups according to 'res'. If cgroup path already exists, it means that the caller has already provided a pre-configured cgroups, and 'res' is ignored.

func (*Cgroup) Join

func (c *Cgroup) Join() (func(), error)

Join adds the current process to the all controllers. Returns function that restores cgroup to the original state.

func (*Cgroup) MakePath

func (c *Cgroup) MakePath(controllerName string) string

MakePath builds a path to the given controller.

func (*Cgroup) MemoryLimit

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

MemoryLimit returns the memory limit.

func (*Cgroup) NumCPU

func (c *Cgroup) NumCPU() (int, error)

NumCPU returns the number of CPUs configured in 'cpuset/cpuset.cpus'.

func (*Cgroup) Uninstall

func (c *Cgroup) Uninstall() error

Uninstall removes the settings done in Install(). If cgroup path already existed when Install() was called, Uninstall is a noop.

Jump to

Keyboard shortcuts

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