cgroups

package
v0.1.0-proto2f Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(cgPath string, pid int) error

Add moves a PID into the cgroup

func AgentCgroup

func AgentCgroup(id string) string

AgentCgroup names the per-agent cgroup for id.

Exported and used by all five call sites - create, cleanup in both agent types, and the two metrics collectors - because those were five independent fmt.Sprintf("gapid-%s") literals. Five spellings of one name is a cleanup that misses, or a stats read that finds nothing and reports zero; composing them here makes agreement structural rather than a thing to remember.

func Cleanup

func Cleanup(name string) error

Cleanup removes the cgroup

func Create

func Create(name string, spec ResourceSpec) (string, error)

Create creates a new cgroup and sets limits

func Setup

func Setup() error

Setup prepares the root cgroup for delegation. It moves the current process (the daemon) into '<daemon>-infra/supervisor'. Then it enables controllers (+cpu +memory) in '<daemon>-infra'.

Types

type LimitError

type LimitError struct {
	Field  string // "cpu" or "memory"
	Value  string // the limit string as supplied
	Reason string // why it cannot be represented
}

LimitError reports a resource limit string that cannot be turned into a ResourceSpec field. Errors are data: the caller gets the field, the offending value and the reason as fields, and never has to match on a formatted message to tell which limit was bad.

func (*LimitError) Error

func (e *LimitError) Error() string

type ResourceSpec

type ResourceSpec struct {
	CPU    float64 // 0.5 = 50%
	Memory int64   // Bytes
}

ResourceSpec defines limits

func ParseResourceSpec

func ParseResourceSpec(cpu, mem string) (ResourceSpec, error)

ParseResourceSpec converts operator-supplied cpu and memory limit strings into a ResourceSpec.

It is the SINGLE source of truth for what a limit string means. core/schema validates manifests by calling this function rather than reimplementing the formats, so "the manifest was accepted" and "the limit can be applied" are one statement instead of two implementations that drift apart. That is structural, not a convention to remember: core/cgroups imports only internal/safeio, so core/schema can depend on it with no cycle.

An empty string means "no limit for this resource": the field stays zero and no error is returned, because a manifest that names no limit is not an error. Every other unrepresentable input returns a *LimitError. What this function must never do - and what GAPI-DIV-049 was - is return a zero field with a nil error for a non-empty limit: Create writes a limit only when the field is positive, so a discarded parse error produced an agent with no containment and no log line to say so.

type Stats

type Stats struct {
	CPUUsage    float64 // Percentage (0-100)
	MemoryUsage int64   // Bytes
}

Stats holds resource usage statistics

func GetStats

func GetStats(name string) (Stats, error)

GetStats reads current resource usage from a cgroup

Jump to

Keyboard shortcuts

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