cgroups

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Tasks is a cgroup's "tasks" entry.
	Tasks = "tasks"
	// Procs is cgroup's "cgroup.procs" entry.
	Procs = "cgroup.procs"
	// CpuShares is the cpu controller's "cpu.shares" entry.
	CpuShares = "cpu.shares"
	// CpuPeriod is the cpu controller's "cpu.cfs_period_us" entry.
	CpuPeriod = "cpu.cfs_period_us"
	// CpuQuota is the cpu controller's "cpu.cfs_quota_us" entry.
	CpuQuota = "cpu.cfs_quota_us"
	// CpusetCpus is the cpuset controller's cpuset.cpus entry.
	CpusetCpus = "cpuset.cpus"
	// CpusetMems is the cpuset controller's cpuset.mems entry.
	CpusetMems = "cpuset.mems"
)

nolint

Variables

View Source
var (

	// KubeletRoot is the --cgroup-root option the kubelet is running with.
	KubeletRoot = ""
)

Functions

func GetCPUSetMemoryMigrate

func GetCPUSetMemoryMigrate(cgroupPath string) (bool, error)

GetCPUSetMemoryMigrate returns boolean indicating whether memory migration is enabled.

func GetGlobalNumaStats

func GetGlobalNumaStats() (map[int]GlobalNumaStats, error)

GetGlobalNumaStats returns the global (non-cgroup) NUMA statistics per node.

func GetMountDir

func GetMountDir() string

GetMountDir returns the common mount point for cgroup v1 controllers.

func GetV2Dir

func GetV2Dir() string

GetV2Dir() returns the cgroup v2 unified mount directory.

func SetMountDir

func SetMountDir(dir string)

SetMountDir sets the common mount point for the cgroup v1 controllers.

func SetV2Dir

func SetV2Dir(dir string)

SetV2Dir sets the unified cgroup v2 mount directory.

Types

type BlkioDeviceBytes

type BlkioDeviceBytes struct {
	Major      int
	Minor      int
	Operations map[string]int64
}

BlkioDeviceBytes contains a single operations line of blkio.throttle.io_service_bytes_recursive file

type BlkioThrottleBytes

type BlkioThrottleBytes struct {
	DeviceBytes []*BlkioDeviceBytes
	TotalBytes  int64
}

BlkioThrottleBytes has parsed contents of blkio.throttle.io_service_bytes_recursive file

func GetBlkioThrottleBytes

func GetBlkioThrottleBytes(cgroupPath string) (BlkioThrottleBytes, error)

GetBlkioThrottleBytes returns amount of bytes transferred to/from the disk.

type CPUAcctUsage

type CPUAcctUsage struct {
	CPU    int
	User   int64
	System int64
}

CPUAcctUsage has a parsed line of cpuacct.usage_all file

func GetCPUAcctStats

func GetCPUAcctStats(cgroupPath string) ([]CPUAcctUsage, error)

GetCPUAcctStats retrieves CPU account statistics for a given cgroup.

type CgroupID

type CgroupID struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CgroupID implements mapping kernel cgroup IDs to cgroupfs paths with transparent caching.

func NewCgroupID

func NewCgroupID(root string) *CgroupID

NewCgroupID creates a new CgroupID map/cache.

func (*CgroupID) Find

func (cgid *CgroupID) Find(id uint64) (string, error)

Find finds the path for the given cgroup id.

type Controller

type Controller int

Controller is our enumerated type for cgroup controllers.

const (
	// UnkownController represents a controller of unknown type.
	UnknownController Controller = iota
	// blkio cgroup controller.
	Blkio
	// cpu cgroup controller.
	Cpu
	// cpuacct cgroup controller.
	Cpuacct
	// cpuset cgroup controller.
	Cpuset
	// devices cgroup controller.
	Devices
	// freezer cgroup controller.
	Freezer
	// hugetlb cgroup controller.
	Hugetlb
	// memory cgroup controller.
	Memory
	// net_cls cgroup controller.
	NetCls
	// net_prio cgroup controller.
	NetPrio
	// per_event cgroup controller.
	PerfEvent
	// pids cgroup controller.
	Pids
)

nolint

func (Controller) Group

func (c Controller) Group(group string) Group

Group returns the given group for the controller.

func (Controller) Path

func (c Controller) Path() string

Path returns the absolute path of the given controller.

func (Controller) RelPath

func (c Controller) RelPath() string

RelPath returns the relative path of the given controller.

func (Controller) String

func (c Controller) String() string

String returns the name of the given controller.

type GlobalNumaStats

type GlobalNumaStats struct {
	NumaHit       int64
	NumaMiss      int64
	NumaForeign   int64
	InterleaveHit int64
	LocalNode     int64
	OtherNode     int64
}

GlobalNumaStats has the statistics from one global NUMA nodestats file.

type Group

type Group string

Group represents a control group.

func AsGroup

func AsGroup(absDir string) Group

AsGroup returns the group for the given absolute directory path.

func (Group) AddProcesses

func (g Group) AddProcesses(pids ...string) error

AddProcesses writes the given process pids to the group.

func (Group) AddTasks

func (g Group) AddTasks(pids ...string) error

AddTasks writes the given thread pids to the group.

func (Group) Controller

func (g Group) Controller() Controller

Controller returns the controller for the group.

func (Group) GetProcesses

func (g Group) GetProcesses() ([]string, error)

GetProcesses reads the pids of processes currently assigned to the group.

func (Group) GetTasks

func (g Group) GetTasks() ([]string, error)

GetTasks reads the pids of threads currently assigned to the group.

func (Group) Write

func (g Group) Write(entry, format string, args ...interface{}) error

Write writes the formatted data to the groups entry.

type HugetlbUsage

type HugetlbUsage struct {
	Size     string
	Bytes    int64
	MaxBytes int64
}

HugetlbUsage has parsed contents of huge pages usage in bytes.

func GetHugetlbUsage

func GetHugetlbUsage(cgroupPath string) ([]HugetlbUsage, error)

GetHugetlbUsage retrieves huge pages statistics for a given cgroup.

type MemoryUsage

type MemoryUsage struct {
	Bytes    int64
	MaxBytes int64
}

MemoryUsage has parsed contents of memory usage in bytes.

func GetMemoryUsage

func GetMemoryUsage(cgroupPath string) (MemoryUsage, error)

GetMemoryUsage retrieves cgroup memory usage.

type NumaLine

type NumaLine struct {
	Total int64
	Nodes map[string]int64
}

NumaLine represents one line in the NUMA statistics file.

type NumaStat

type NumaStat struct {
	Total       NumaLine
	File        NumaLine
	Anon        NumaLine
	Unevictable NumaLine

	HierarchicalTotal       NumaLine
	HierarchicalFile        NumaLine
	HierarchicalAnon        NumaLine
	HierarchicalUnevictable NumaLine
}

NumaStat has parsed contents of a NUMA statistics file.

func GetNumaStats

func GetNumaStats(cgroupPath string) (NumaStat, error)

GetNumaStats returns parsed cgroup NUMA statistics.

Jump to

Keyboard shortcuts

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