cgroups

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CgroupRoot default cgroup2
	CgroupRoot = "/sys/fs/cgroup"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CgroupManager

type CgroupManager struct {
	// Path of the cgroup relative to the cgroup root
	Path string
	// Resource configuration
	Resource *ResourceConfig
}

CgroupManager manages cgroup v2 resources

func NewCgroupManager

func NewCgroupManager(path string) *CgroupManager

NewCgroupManager creates a new CgroupManager instance

func (*CgroupManager) Apply

func (c *CgroupManager) Apply(pid int) error

Apply ensures that the cgroup directory exists, writes the process IDs to the cgroup.procs file under the cgroup path, and the processes can be subject to the resource limits set by that cgroup

func (*CgroupManager) Destroy

func (c *CgroupManager) Destroy() error

Destroy migrates all processes in the cgroup to the parent cgroup by reading cgroup.procs and writing the process IDs to the parent cgroup's cgroup.procs, then deletes the entire cgroup directory

func (*CgroupManager) Set

func (c *CgroupManager) Set(res *ResourceConfig) error

type ResourceConfig

type ResourceConfig struct {
	MemoryLimit string // in bytes
	CpuShare    string // in shares (relative weight)
	CpuSet      string // cpus the container can use, e.g., "0-1,3"
}

ResourceConfig holds resource limit configurations

Jump to

Keyboard shortcuts

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