Documentation
¶
Overview ¶
Package cgroup provides a unified interface for cgroup v1 and v2 operations.
Index ¶
- func ConvertToV2Resources(resources *oci.LinuxResources) *cgroups2.Resources
- func ConvertV2StatsToV1(v2Stats *cgroups2stats.Metrics) *cgroups1stats.Metrics
- func IsCgroupV2() bool
- func LoadAndStat(cgroupPath string) (*cgroups1stats.Metrics, error)
- func ParseMemoryEvents(content string) map[string]uint64
- type Manager
- type V1Mgr
- func (v *V1Mgr) Add(process cgroups1.Process, names ...cgroups1.Name) error
- func (v *V1Mgr) AddTask(pid int) error
- func (v *V1Mgr) Create(pid int) error
- func (v *V1Mgr) Delete() error
- func (v *V1Mgr) GetV1Cgroup() cgroups1.Cgroup
- func (v *V1Mgr) GetV2Manager() *cgroups2.Manager
- func (v *V1Mgr) OOMEventFD() (uintptr, error)
- func (v *V1Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)
- func (v *V1Mgr) Stats() (*cgroups1stats.Metrics, error)
- func (v *V1Mgr) Update(resources *oci.LinuxResources) error
- type V2Mgr
- func (v *V2Mgr) Add(process cgroups1.Process, _ ...cgroups1.Name) error
- func (v *V2Mgr) AddTask(pid int) error
- func (v *V2Mgr) Create(pid int) error
- func (v *V2Mgr) Delete() error
- func (v *V2Mgr) GetV1Cgroup() cgroups1.Cgroup
- func (v *V2Mgr) GetV2Manager() *cgroups2.Manager
- func (v *V2Mgr) OOMEventFD() (uintptr, error)
- func (v *V2Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)
- func (v *V2Mgr) Stats() (*cgroups1stats.Metrics, error)
- func (v *V2Mgr) Update(resources *oci.LinuxResources) error
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 ¶
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 ¶
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) GetV1Cgroup ¶
func (*V1Mgr) GetV2Manager ¶
func (*V1Mgr) OOMEventFD ¶
func (*V1Mgr) RegisterMemoryEvent ¶
func (v *V1Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)
type V2Mgr ¶
type V2Mgr struct {
// contains filtered or unexported fields
}
V2Mgr wraps cgroup v2 operations.
func (*V2Mgr) GetV1Cgroup ¶
func (*V2Mgr) GetV2Manager ¶
func (*V2Mgr) OOMEventFD ¶
func (*V2Mgr) RegisterMemoryEvent ¶
func (v *V2Mgr) RegisterMemoryEvent(event cgroups1.MemoryEvent) (uintptr, error)