cgroups

package
v0.0.0-...-8b8575e Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Tasks is a cgroup's "tasks" entry.
	Tasks = "tasks"
	// Procs is cgroup's "cgroup.procs" entry.
	Procs = "cgroup.procs"
	// CpuShares is the cpu controller's "cpu.shares" entry.
	CpuShares = "cpu.shares"
	// CpuPeriod is the cpu controller's "cpu.cfs_period_us" entry.
	CpuPeriod = "cpu.cfs_period_us"
	// CpuQuota is the cpu controller's "cpu.cfs_quota_us" entry.
	CpuQuota = "cpu.cfs_quota_us"
	// CpusetCpus is the cpuset controller's cpuset.cpus entry.
	CpusetCpus = "cpuset.cpus"
	// CpusetMems is the cpuset controller's cpuset.mems entry.
	CpusetMems = "cpuset.mems"
)

nolint

Variables

View Source
var (

	// KubeletRoot is the --cgroup-root option the kubelet is running with.
	KubeletRoot = ""
)

Functions

func GetMountDir

func GetMountDir() string

GetMountDir returns the common mount point for cgroup v1 controllers.

func GetV2Dir

func GetV2Dir() string

GetV2Dir() returns the cgroup v2 unified mount directory.

func NewFsiMock

func NewFsiMock(files map[string]mockFile) fsiIface

func NewFsiOS

func NewFsiOS() fsiIface

func ResetBlkioParameters

func ResetBlkioParameters(cntnrDir string, blockIO OciBlockIOParameters) error

ResetBlkioParameters adds new, changes existing and removes missing blockIO parameters in cgroupsDir

func SetBlkioParameters

func SetBlkioParameters(group string, blockIO OciBlockIOParameters) error

SetBlkioParameters writes OCI BlockIO parameters to files in cgroups blkio contoller directory.

func SetMountDir

func SetMountDir(dir string)

SetMountDir sets the common mount point for the cgroup v1 controllers.

func SetV2Dir

func SetV2Dir(dir string)

SetV2Dir sets the unified cgroup v2 mount directory.

Types

type CgroupID

type CgroupID struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CgroupID implements mapping kernel cgroup IDs to cgroupfs paths with transparent caching.

func NewCgroupID

func NewCgroupID(root string) *CgroupID

NewCgroupID creates a new CgroupID map/cache.

func (*CgroupID) Find

func (cgid *CgroupID) Find(id uint64) (string, error)

Find finds the path for the given cgroup id.

type Controller

type Controller int

Controller is our enumerated type for cgroup controllers.

const (
	// UnkownController represents a controller of unknown type.
	UnknownController Controller = iota
	// blkio cgroup controller.
	Blkio
	// cpu cgroup controller.
	Cpu
	// cpuacct cgroup controller.
	Cpuacct
	// cpuset cgroup controller.
	Cpuset
	// devices cgroup controller.
	Devices
	// freezer cgroup controller.
	Freezer
	// hugetlb cgroup controller.
	Hugetlb
	// memory cgroup controller.
	Memory
	// net_cls cgroup controller.
	NetCls
	// net_prio cgroup controller.
	NetPrio
	// per_event cgroup controller.
	PerfEvent
	// pids cgroup controller.
	Pids
)

nolint

func (Controller) Group

func (c Controller) Group(group string) Group

Group returns the given group for the controller.

func (Controller) Path

func (c Controller) Path() string

Path returns the absolute path of the given controller.

func (Controller) RelPath

func (c Controller) RelPath() string

RelPath returns the relative path of the given controller.

func (Controller) String

func (c Controller) String() string

String returns the name of the given controller.

type Group

type Group string

Group represents a control group.

func AsGroup

func AsGroup(absDir string) Group

AsGroup returns the group for the given absolute directory path.

func (Group) AddProcesses

func (g Group) AddProcesses(pids ...string) error

AddProcesses writes the given process pids to the group.

func (Group) AddTasks

func (g Group) AddTasks(pids ...string) error

AddTasks writes the given thread pids to the group.

func (Group) Controller

func (g Group) Controller() Controller

Controller returns the controller for the group.

func (Group) GetProcesses

func (g Group) GetProcesses() ([]string, error)

GetProcesses reads the pids of processes currently assigned to the group.

func (Group) GetTasks

func (g Group) GetTasks() ([]string, error)

GetTasks reads the pids of threads currently assigned to the group.

func (Group) Read

func (g Group) Read(entry string) (string, error)

Read the groups entry and return contents in a string

func (Group) Write

func (g Group) Write(entry, format string, args ...interface{}) error

Write writes the formatted data to the groups entry.

type OciBlockIOParameters

type OciBlockIOParameters struct {
	Weight                  int64
	WeightDevice            OciDeviceWeights
	ThrottleReadBpsDevice   OciDeviceRates
	ThrottleWriteBpsDevice  OciDeviceRates
	ThrottleReadIOPSDevice  OciDeviceRates
	ThrottleWriteIOPSDevice OciDeviceRates
}

OciBlockIOParameters contains OCI standard configuration of cgroups blkio parameters.

Effects of Weight and Rate values in SetBlkioParameters(): Value | Effect -------+-------------------------------------------------------------------

  -1  |  Do not write to cgroups, value is missing
   0  |  Write to cgroups, will remove the setting as specified in cgroups blkio interface
other |  Write to cgroups, sets the value

func GetBlkioParameters

func GetBlkioParameters(group string) (OciBlockIOParameters, error)

GetBlkioParameters returns OCI BlockIO parameters from files in cgroups blkio controller directory.

func NewOciBlockIOParameters

func NewOciBlockIOParameters() OciBlockIOParameters

NewOciBlockIOParameters creates new OciBlockIOParameters instance.

type OciDeviceParameters

type OciDeviceParameters interface {
	Append(maj, min, val int64)
	Update(maj, min, val int64)
}

OciDeviceParameters interface provides functions common to OciDeviceWeights and OciDeviceRates

type OciDeviceRate

type OciDeviceRate struct {
	Major int64
	Minor int64
	Rate  int64
}

OciDeviceRate contains values for - blkio.throttle.read_bps_device - blkio.throttle.write_bps_device - blkio.throttle.read_iops_device - blkio.throttle.write_iops_device

func NewOciDeviceRate

func NewOciDeviceRate() OciDeviceRate

NewOciDeviceRate creates new OciDeviceRate instance.

type OciDeviceRates

type OciDeviceRates []OciDeviceRate

OciDeviceRates contains throttling rates for devices

func (*OciDeviceRates) Append

func (r *OciDeviceRates) Append(maj, min, val int64)

Append appends (major, minor, value) to OciDeviceRates slice.

func (*OciDeviceRates) Update

func (r *OciDeviceRates) Update(maj, min, val int64)

Update updates device rate in OciDeviceRates slice, or appends it if not found.

type OciDeviceWeight

type OciDeviceWeight struct {
	Major  int64
	Minor  int64
	Weight int64
}

OciDeviceWeight contains values for - blkio.[io-scheduler].weight

func NewOciDeviceWeight

func NewOciDeviceWeight() OciDeviceWeight

NewOciDeviceWeight creates new OciDeviceWeight instance.

type OciDeviceWeights

type OciDeviceWeights []OciDeviceWeight

OciDeviceWeights contains weights for devices

func (*OciDeviceWeights) Append

func (w *OciDeviceWeights) Append(maj, min, val int64)

Append appends (major, minor, value) to OciDeviceWeights slice.

func (*OciDeviceWeights) Update

func (w *OciDeviceWeights) Update(maj, min, val int64)

Update updates device weight in OciDeviceWeights slice, or appends it if not found.

Jump to

Keyboard shortcuts

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