package cgroup
import "gvisor.dev/gvisor/runsc/cgroup"
Package cgroup provides an interface to read and write configuration to cgroup.
Index ¶
- Variables
- func IsOnlyV2() bool
- func LikelySystemdPath(path string) bool
- func RangeToBits(str string) ([]byte, error)
- func TransformSystemdPath(path, cid string, rootless bool) (string, error)
- type Cgroup
- func CreateMockSystemdCgroup() Cgroup
- func NewFromPath(cgroupsPath string, useSystemd bool) (Cgroup, error)
- func NewFromPid(pid int, useSystemd bool) (Cgroup, error)
- type CgroupJSON
Variables ¶
var ( ErrInvalidFormat = errors.New("cgroup: parsing file with invalid format failed") ErrInvalidGroupPath = errors.New("cgroup: invalid group path") )
var ( // ErrBadResourceSpec indicates that a cgroupSystemd function was // passed a specs.LinuxResources object that is impossible or illegal // to process. ErrBadResourceSpec = errors.New("misconfigured resource spec") // ErrInvalidSlice indicates that the slice name passed via cgroup.Path is // invalid. ErrInvalidSlice = errors.New("invalid slice name") )
Functions ¶
func IsOnlyV2 ¶
func IsOnlyV2() bool
IsOnlyV2 checks whether cgroups V2 is enabled and V1 is not.
func LikelySystemdPath ¶
LikelySystemdPath returns true if the path looks like a systemd path. This is by no means an exhaustive check, it's just a useful proxy for logging a warning.
func RangeToBits ¶
RangeToBits converts a text representation of a CPU mask (as written to or read from cgroups' cpuset.* files, e.g. "1,3-5") to a slice of bytes with the corresponding bits set (as consumed by systemd over dbus as AllowedCPUs/AllowedMemoryNodes unit property value). Copied from runc.
func TransformSystemdPath ¶
TransformSystemdPath transforms systemd path to be in the form `slice:prefix:name`. It returns an error if path could not be parsed as a valid systemd path.
Types ¶
type Cgroup ¶
type Cgroup interface { Install(res *specs.LinuxResources) error Uninstall() error Join() (func(), error) CPUQuota() (float64, error) CPUUsage() (uint64, error) NumCPU() (int, error) MemoryLimit() (uint64, error) MakePath(controllerName string) string }
Cgroup represents a cgroup configuration.
func CreateMockSystemdCgroup ¶
func CreateMockSystemdCgroup() Cgroup
CreateMockSystemdCgroup returns a mock Cgroup configured for systemd. This is useful for testing.
func NewFromPath ¶
NewFromPath creates a new Cgroup instance from the specified relative path. Cgroup paths are loaded based on the current process. If useSystemd is true, the Cgroup will be created and managed with systemd. This requires systemd (>=v244) to be running on the host and the cgroup path to be in the form `slice:prefix:name`.
func NewFromPid ¶
NewFromPid loads cgroup for the given process. If useSystemd is true, the Cgroup will be created and managed with systemd. This requires systemd (>=v244) to be running on the host and the cgroup path to be in the form `slice:prefix:name`.
type CgroupJSON ¶
type CgroupJSON struct { Cgroup Cgroup }
CgroupJSON is a wrapper for Cgroup that can be encoded to JSON.
func (*CgroupJSON) MarshalJSON ¶
func (c *CgroupJSON) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.MarshalJSON
func (*CgroupJSON) UnmarshalJSON ¶
func (c *CgroupJSON) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON
Source Files ¶
cgroup.go cgroup_v2.go systemd.go
- Version
- v0.0.0-20250605235530-a6711d1e1dc6 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Imports
- 24 packages
- Last checked
- 5 hours ago –
Tools for package owners.