cgutil

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCgroupV1Parent    = "/nomad"
	SharedCpusetCgroupName   = "shared"
	ReservedCpusetCgroupName = "reserved"
)
View Source
const (
	// CreationPID is a special PID in libcontainer used to denote a cgroup
	// should be created, but with no process added.
	//
	// https://github.com/opencontainers/runc/blob/v1.0.3/libcontainer/cgroups/utils.go#L372
	CreationPID = -1

	// DefaultCgroupParentV2 is the name of Nomad's default parent cgroup, under which
	// all other cgroups are managed. This can be changed with client configuration
	// in case for e.g. Nomad tasks should be further constrained by an externally
	// configured systemd cgroup.
	DefaultCgroupParentV2 = "nomad.slice"
)
View Source
const (
	// CgroupRoot is hard-coded in the cgroups specification.
	// It only applies to linux but helpers have references to it in driver(s).
	CgroupRoot = "/sys/fs/cgroup"
)

Variables

View Source
var UseV2 = safelyDetectUnifiedMode()

UseV2 indicates whether only cgroups.v2 is enabled. If cgroups.v2 is not enabled or is running in hybrid mode with cgroups.v1, Nomad will make use of cgroups.v1

This is a read-only value.

Functions

func CgroupScope added in v1.3.0

func CgroupScope(allocID, task string) string

CgroupScope returns the name of the scope for Nomad's managed cgroups for the given allocID and task.

e.g. "<allocID>.<task>.scope"

Only useful for v2.

func ConfigureBasicCgroups added in v1.3.0

func ConfigureBasicCgroups(config *lcc.Config) error

ConfigureBasicCgroups will initialize a cgroup and modify config to contain a reference to its path.

v1: creates a random "freezer" cgroup which can later be used for cleanup of processes. v2: does nothing.

func CopyCpuset added in v1.3.0

func CopyCpuset(source, destination string) error

CopyCpuset copies the cpuset.cpus value from source into destination.

func FindCgroupMountpointDir

func FindCgroupMountpointDir() (string, error)

FindCgroupMountpointDir is used to find the cgroup mount point on a Linux system.

Note that in cgroups.v1, this returns one of many subsystems that are mounted. e.g. a return value of "/sys/fs/cgroup/systemd" really implies the root is "/sys/fs/cgroup", which is interesting on hybrid systems where the 'unified' subsystem is mounted as if it were a subsystem, but the actual root is different. (i.e. /sys/fs/cgroup/unified).

As far as Nomad is concerned, UseV2 is the source of truth for which hierarchy to use, and that will only be a true value if cgroups.v2 is mounted on /sys/fs/cgroup (i.e. system is not in v1 or hybrid mode).

➜ mount -l | grep cgroup tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755,inode64) cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) (etc.)

func GetCPUsFromCgroup

func GetCPUsFromCgroup(group string) ([]uint16, error)

GetCPUsFromCgroup gets the effective cpuset value for the given cgroup.

func GetCgroupParent added in v1.3.0

func GetCgroupParent(parent string) string

GetCgroupParent returns the mount point under the root cgroup in which Nomad will create cgroups. If parent is not set, an appropriate name for the version of cgroups will be used.

func GetCgroupPathHelperV1 added in v1.3.0

func GetCgroupPathHelperV1(subsystem, cgroup string) (string, error)

func MaybeDisableMemorySwappiness added in v1.4.11

func MaybeDisableMemorySwappiness() *uint64

MaybeDisableMemorySwappiness will disable memory swappiness, if that controller is available. Always the case for cgroups v2, but is not always the case on very old kernels with cgroups v1.

func SplitPath added in v1.3.0

func SplitPath(p string) (string, string)

SplitPath determines the parent and cgroup from p. p must contain at least 2 elements (parent + cgroup).

Handles the cgroup root if present.

Types

type CgroupPathGetter

type CgroupPathGetter func(context.Context) (path string, err error)

CgroupPathGetter is a function which returns the cgroup path and any error which occurred during cgroup initialization.

It should block until the cgroup has been created or an error is reported.

type CpusetManager

type CpusetManager interface {
	// Init should be called before the client starts running allocations. This
	// is where the cpuset manager should start doing background operations.
	Init()

	// AddAlloc adds an allocation to the manager
	AddAlloc(alloc *structs.Allocation)

	// RemoveAlloc removes an alloc by ID from the manager
	RemoveAlloc(allocID string)

	// CgroupPathFor returns a callback for getting the cgroup path and any error that may have occurred during
	// cgroup initialization. The callback will block if the cgroup has not been created
	CgroupPathFor(allocID, taskName string) CgroupPathGetter
}

CpusetManager is used to setup cpuset cgroups for each task.

func CreateCPUSetManager added in v1.3.0

func CreateCPUSetManager(parent string, reservable []uint16, logger hclog.Logger) CpusetManager

CreateCPUSetManager creates a V1 or V2 CpusetManager depending on system configuration.

func NewCpusetManagerV1 added in v1.3.0

func NewCpusetManagerV1(cgroupParent string, _ []uint16, logger hclog.Logger) CpusetManager

NewCpusetManagerV1 creates a CpusetManager compatible with cgroups.v1

func NewCpusetManagerV2 added in v1.3.0

func NewCpusetManagerV2(parent string, reservable []uint16, logger hclog.Logger) CpusetManager

type GroupKiller added in v1.3.0

type GroupKiller interface {
	KillGroup(cgroup *configs.Cgroup) error
}

GroupKiller is used for SIGKILL-ing the process tree[s] of a cgroup by leveraging the freezer cgroup subsystem.

func NewGroupKiller added in v1.3.0

func NewGroupKiller(logger hclog.Logger, pid int) GroupKiller

NewGroupKiller creates a GroupKiller with executor PID pid.

type NoopCpusetManager

type NoopCpusetManager struct{}

func (NoopCpusetManager) AddAlloc added in v1.3.0

func (n NoopCpusetManager) AddAlloc(alloc *structs.Allocation)

func (NoopCpusetManager) CgroupPathFor added in v1.3.0

func (n NoopCpusetManager) CgroupPathFor(allocID, task string) CgroupPathGetter

func (NoopCpusetManager) Init added in v1.3.0

func (n NoopCpusetManager) Init()

func (NoopCpusetManager) RemoveAlloc added in v1.3.0

func (n NoopCpusetManager) RemoveAlloc(allocID string)

type TaskCgroupInfo

type TaskCgroupInfo struct {
	CgroupPath         string
	RelativeCgroupPath string
	Cpuset             cpuset.CPUSet
	Error              error
}

Jump to

Keyboard shortcuts

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