subsystems

package
v0.0.0-...-be3b871 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SubsystemIns = []SubSystemer{
	&CPUSubsystem{},

	&MemorySubSystem{},
}

SubsystemIns subsystem instances

Functions

func FindCgroupMountPoint

func FindCgroupMountPoint(subsystem string) string

FindCgroupMountPoint 通过/proc/self/mountinfo找出挂载了某个subsystem的hierarchy cgroup所在的目录 example: FindCgroupMountPoint("memory") mountinfo: 41 25 0:33 / /sys/fs/cgroup/memory rw,relatime - cgroup cgroup rw,memory

func GetCgroupPath

func GetCgroupPath(subsystem string, cgroupPath string, autoCreate bool) (string, error)

GetCgroupPath 得到cgroup在文件系统的中的绝对路径

Types

type CPUSetSubSystem

type CPUSetSubSystem struct {
}

CPUSetSubSystem .

func (*CPUSetSubSystem) Apply

func (cs *CPUSetSubSystem) Apply(cgroupPath string, pid int) error

Apply 将进程添加到某个cgroup中

func (*CPUSetSubSystem) Name

func (cs *CPUSetSubSystem) Name() string

Name 返回subsystem的名字,比如cpu memory

func (*CPUSetSubSystem) Remove

func (cs *CPUSetSubSystem) Remove(cgroupPath string) error

Remove 移除某个cgroup

func (*CPUSetSubSystem) Set

func (cs *CPUSetSubSystem) Set(cgroupPath string, res *ResourceConfig) error

Set 设置某个cgroup在这个Subsystem中的资源限制

type CPUSubsystem

type CPUSubsystem struct {
}

CPUSubsystem .

func (*CPUSubsystem) Apply

func (c *CPUSubsystem) Apply(cgroupPath string, pid int) error

Apply 将进程添加到某个cgroup中

func (*CPUSubsystem) Name

func (c *CPUSubsystem) Name() string

Name 返回subsystem的名字,比如cpu memory

func (*CPUSubsystem) Remove

func (c *CPUSubsystem) Remove(cgroupPath string) error

Remove 移除某个cgroup

func (*CPUSubsystem) Set

func (c *CPUSubsystem) Set(cgroupPath string, res *ResourceConfig) error

Set 设置某个cgroup在这个Subsystem中的资源限制

type MemorySubSystem

type MemorySubSystem struct {
}

MemorySubSystem 是 memory subsystem的实现

func (*MemorySubSystem) Apply

func (m *MemorySubSystem) Apply(cgroupPath string, pid int) error

将进程添加到某个cgroup中

func (*MemorySubSystem) Name

func (m *MemorySubSystem) Name() string

返回subsystem的名字,比如cpu memory

func (*MemorySubSystem) Remove

func (m *MemorySubSystem) Remove(cgroupPath string) error

移除某个cgroup

func (*MemorySubSystem) Set

func (m *MemorySubSystem) Set(cgroupPath string, res *ResourceConfig) error

设置某个cgroup在这个Subsystem中的资源限制

type ResourceConfig

type ResourceConfig struct {
	MemoryLimit string
	CPUShare    string
	CPUSet      string
}

ResourceConfig 用于传递资源配置的结构体,包含内存限制,cpu时间片权重,cpu核心数

type SubSystemer

type SubSystemer interface {
	// 返回subsystem的名字,比如cpu memory
	Name() string

	// 设置某个cgroup在这个Subsystem中的资源限制
	Set(path string, res *ResourceConfig) error

	// 将进程添加到某个cgroup中
	Apply(path string, pid int) error

	// 移除某个cgroup
	Remove(path string) error
}

SubSystemer 接口,每个Subsystem可以实现下面4个接口 这里将cgroup抽象成path,原因是cgroup在hierarchy的路径,便是虚拟 文件系统中的虚拟路径

Jump to

Keyboard shortcuts

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