cgroup

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cgroup provides a unified interface for cgroup v1 and v2 operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToV2Resources

func ConvertToV2Resources(resources *oci.LinuxResources) *cgroups2.Resources

ConvertToV2Resources converts oci.LinuxResources to cgroups2.Resources.

func ConvertV2StatsToV1

func ConvertV2StatsToV1(v2Stats *cgroups2stats.Metrics) *cgroups1stats.Metrics

ConvertV2StatsToV1 converts cgroup v2 metrics to v1 metrics format for compatibility.

func IsCgroupV2

func IsCgroupV2() bool

IsCgroupV2 checks if cgroup v2 (unified or hybrid) is available on the system.

func LoadAndStat

func LoadAndStat(cgroupPath string) (*cgroups1stats.Metrics, error)

LoadAndStat loads an existing cgroup by path and returns its stats. This is useful for containers whose cgroups are managed by the runtime (e.g., runc) rather than created by us directly.

func ParseMemoryEvents

func ParseMemoryEvents(content string) map[string]uint64

ParseMemoryEvents parses cgroup v2 memory.events file. Format: "low 0\nhigh 5\nmax 0\noom 0\noom_kill 0\noom_group_kill 0\n"

Types

type Manager

type Manager interface {
	Create(pid int) error
	Delete() error
	// Stats returns cgroup metrics in v1 format for wire protocol compatibility.
	// On cgroup v2 systems, native v2 stats are converted via ConvertV2StatsToV1.
	// TODO: Add StatsV2() method returning native *cgroups2stats.Metrics when
	// host-side consumers (HCS schema, GCS protocol, containerd shim) are updated
	// to handle the v2 wire format.
	Stats() (*cgroups1stats.Metrics, error)
	Update(resources *oci.LinuxResources) error
	AddTask(pid int) error
	Add(process cgroups1.Process, names ...cgroups1.Name) error
	RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)
	OOMEventFD() (uintptr, error)
	// GetV1Cgroup returns the underlying v1 cgroup if available, nil for v2.
	GetV1Cgroup() cgroups1.Cgroup
	// GetV2Manager returns the underlying v2 manager if available, nil for v1.
	GetV2Manager() *cgroups2.Manager
}

Manager provides a unified interface for cgroup v1 and v2 operations.

func LoadManager

func LoadManager(cgroupPath string) (Manager, error)

LoadManager loads an existing cgroup (created by the runtime) and returns a Manager. Unlike NewManager, this does not create the cgroup — it wraps one that already exists.

func NewManager

func NewManager(path string, resources *oci.LinuxResources) (Manager, error)

NewManager creates the appropriate cgroup manager based on the detected system version.

type V1Mgr

type V1Mgr struct {
	// contains filtered or unexported fields
}

V1Mgr wraps cgroup v1 operations.

func (*V1Mgr) Add

func (v *V1Mgr) Add(process cgroups1.Process, names ...cgroups1.Name) error

func (*V1Mgr) AddTask

func (v *V1Mgr) AddTask(pid int) error

func (*V1Mgr) Create

func (v *V1Mgr) Create(pid int) error

func (*V1Mgr) Delete

func (v *V1Mgr) Delete() error

func (*V1Mgr) GetV1Cgroup

func (v *V1Mgr) GetV1Cgroup() cgroups1.Cgroup

func (*V1Mgr) GetV2Manager

func (v *V1Mgr) GetV2Manager() *cgroups2.Manager

func (*V1Mgr) OOMEventFD

func (v *V1Mgr) OOMEventFD() (uintptr, error)

func (*V1Mgr) RegisterMemoryEvent

func (v *V1Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)

func (*V1Mgr) Stats

func (v *V1Mgr) Stats() (*cgroups1stats.Metrics, error)

func (*V1Mgr) Update

func (v *V1Mgr) Update(resources *oci.LinuxResources) error

type V2Mgr

type V2Mgr struct {
	// contains filtered or unexported fields
}

V2Mgr wraps cgroup v2 operations.

func (*V2Mgr) Add

func (v *V2Mgr) Add(process cgroups1.Process, _ ...cgroups1.Name) error

func (*V2Mgr) AddTask

func (v *V2Mgr) AddTask(pid int) error

func (*V2Mgr) Create

func (v *V2Mgr) Create(pid int) error

func (*V2Mgr) Delete

func (v *V2Mgr) Delete() error

func (*V2Mgr) GetV1Cgroup

func (v *V2Mgr) GetV1Cgroup() cgroups1.Cgroup

func (*V2Mgr) GetV2Manager

func (v *V2Mgr) GetV2Manager() *cgroups2.Manager

func (*V2Mgr) OOMEventFD

func (v *V2Mgr) OOMEventFD() (uintptr, error)

func (*V2Mgr) RegisterMemoryEvent

func (v *V2Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)

func (*V2Mgr) Stats

func (v *V2Mgr) Stats() (*cgroups1stats.Metrics, error)

func (*V2Mgr) Update

func (v *V2Mgr) Update(resources *oci.LinuxResources) error

Jump to

Keyboard shortcuts

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