const CgroupProcesses … const unifiedMountpoint … const hybridMountpoint … var isUnifiedOnce … var isUnified … var isHybridOnce … var isHybrid … // IsCgroup2UnifiedMode returns whether we are running in cgroup v2 unified mode. func IsCgroup2UnifiedMode() bool { … } // IsCgroup2HybridMode returns whether we are running in cgroup v2 hybrid mode. func IsCgroup2HybridMode() bool { … } type Mount … // GetCgroupMounts returns the mounts for the cgroup subsystems. // all indicates whether to return just the first instance or all the mounts. // This function should not be used from cgroupv2 code, as in this case // all the controllers are available under the constant unifiedMountpoint. func GetCgroupMounts(all bool) ([]Mount, error) { … } // GetAllSubsystems returns all the cgroup subsystems supported by the kernel func GetAllSubsystems() ([]string, error) { … } func readProcsFile(dir string) (out []int, _ error) { … } // ParseCgroupFile parses the given cgroup file, typically /proc/self/cgroup // or /proc/<pid>/cgroup, into a map of subsystems to cgroup paths, e.g. // // "cpu": "/user.slice/user-1000.slice" // "pids": "/user.slice/user-1000.slice" // // etc. // // Note that for cgroup v2 unified hierarchy, there are no per-controller // cgroup paths, so the resulting map will have a single element where the key // is empty string ("") and the value is the cgroup path the <pid> is in. func ParseCgroupFile(path string) (map[string]string, error) { … } // helper function for ParseCgroupFile to make testing easier func parseCgroupFromReader(r io.Reader) (map[string]string, error) { … } func PathExists(path string) bool { … } // rmdir tries to remove a directory, optionally retrying on EBUSY. func rmdir(path string, retry bool) error { … } // RemovePath aims to remove cgroup path. It does so recursively, // by removing any subdirectories (sub-cgroups) first. func RemovePath(path string) error { … } // RemovePaths iterates over the provided paths removing them. func RemovePaths(paths map[string]string) (err error) { … } var hugePageSizes … var initHPSOnce … func HugePageSizes() []string { … } func getHugePageSizeFromFilenames(fileNames []string) ([]string, error) { … } // GetPids returns all pids, that were added to cgroup at path. func GetPids(dir string) ([]int, error) { … } // WriteCgroupProc writes the specified pid into the cgroup's cgroup.procs file func WriteCgroupProc(dir string, pid int) error { … } // Since the OCI spec is designed for cgroup v1, in some cases // there is need to convert from the cgroup v1 configuration to cgroup v2 // the formula for cpuShares is y = (1 + ((x - 2) * 9999) / 262142) // convert from [2-262144] to [1-10000] // 262144 comes from Linux kernel definition "#define MAX_SHARES (1UL << 18)" func ConvertCPUSharesToCgroupV2Value(cpuShares uint64) uint64 { … } // ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec // for use by cgroup v2 drivers. A conversion is needed since Resources.MemorySwap // is defined as memory+swap combined, while in cgroup v2 swap is a separate value, // so we need to subtract memory from it where it makes sense. func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error) { … } // Since the OCI spec is designed for cgroup v1, in some cases // there is need to convert from the cgroup v1 configuration to cgroup v2 // the formula for BlkIOWeight to IOWeight is y = (1 + (x - 10) * 9999 / 990) // convert linearly from [10-1000] to [1-10000] func ConvertBlkIOToIOWeightValue(blkIoWeight uint16) uint64 { … }