Documentation ¶
Index ¶
- Constants
- Variables
- func CgroupScope(allocID, task string) string
- func ConfigureBasicCgroups(config *lcc.Config) error
- func CopyCpuset(source, destination string) error
- func FindCgroupMountpointDir() (string, error)
- func GetCPUsFromCgroup(group string) ([]uint16, error)
- func GetCgroupParent(parent string) string
- func GetCgroupPathHelperV1(subsystem, cgroup string) (string, error)
- func MaybeDisableMemorySwappiness() *uint64
- func SplitPath(p string) (string, string)
- type CgroupPathGetter
- type CpusetManager
- type GroupKiller
- type NoopCpusetManager
- type TaskCgroupInfo
Constants ¶
const ( DefaultCgroupV1Parent = "/nomad" ReservedCpusetCgroupName = "reserved" )
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" )
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 ¶
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
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
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
CopyCpuset copies the cpuset.cpus value from source into destination.
func FindCgroupMountpointDir ¶
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 ¶
GetCPUsFromCgroup gets the effective cpuset value for the given cgroup.
func GetCgroupParent ¶ added in v1.3.0
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 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.
Types ¶
type CgroupPathGetter ¶
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
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)