resourceexecutor

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CgroupMaxSymbolStr only appears in cgroups-v2 files, we consider the value as MaxInt64
	CgroupMaxSymbolStr string = "max"
	// CgroupMaxValueStr math.MaxInt64; writing `memory.high` with this do the same as set as "max"
	CgroupMaxValueStr string = "9223372036854775807"
)
View Source
const (
	ReasonUpdateCgroups      = "UpdateCgroups"
	ReasonUpdateSystemConfig = "UpdateSystemConfig"
	ReasonUpdateResctrl      = "UpdateResctrl" // update resctrl tasks, schemata

	EvictPodByNodeMemoryUsage   = "EvictPodByNodeMemoryUsage"
	EvictPodByBECPUSatisfaction = "EvictPodByBECPUSatisfaction"

	AdjustBEByNodeCPUUsage = "AdjustBEByNodeCPUUsage"
)
View Source
const EmptyValueError string = "EmptyValueError"
View Source
const ErrCgroupDir = "cgroup path or file not exist"

Variables

View Source
var DefaultCgroupUpdaterFactory = NewCgroupUpdaterFactory()
View Source
var ErrResourceNotRegistered = errors.New("resource not registered")

Functions

func BlkIOUpdateFunc added in v1.3.0

func BlkIOUpdateFunc(resource ResourceUpdater) error

func CgroupUpdateCPUSharesFunc

func CgroupUpdateCPUSharesFunc(resource ResourceUpdater) error

func CgroupUpdateWithUnlimitedFunc

func CgroupUpdateWithUnlimitedFunc(resource ResourceUpdater) error

func CheckIfBlkQOSNeedUpdate added in v1.3.0

func CheckIfBlkQOSNeedUpdate(oldValue string, newValue string) bool

blkio.cost.weight: configure iocost weight blkio.throttle.read_bps_device: configure read bps blkio.throttle.read_iops_device: configure read iops blkio.throttle.write_bps_device: configure write bps blkio.throttle.write_iops_device: configure write iops

func CommonCgroupUpdateFunc

func CommonCgroupUpdateFunc(resource ResourceUpdater) error

func CommonDefaultUpdateFunc

func CommonDefaultUpdateFunc(resource ResourceUpdater) error

func IsCgroupDirErr added in v1.2.0

func IsCgroupDirErr(err error) bool

func IsCgroupPathExist added in v1.2.0

func IsCgroupPathExist(parentDir string, r sysutil.Resource) (bool, string)

func MergeConditionIfCPUSetIsLooser

func MergeConditionIfCPUSetIsLooser(oldValue, newValue string) (string, bool, error)

MergeConditionIfCPUSetIsLooser returns a merge condition where only do update when the new cpuset value is looser.

func MergeConditionIfValueIsLarger

func MergeConditionIfValueIsLarger(oldValue, newValue string) (string, bool, error)

MergeConditionIfValueIsLarger returns a merge condition where only do update when the new value is larger.

func ResourceCgroupDirErr added in v1.2.0

func ResourceCgroupDirErr(msg string) error

func UpdateResctrlSchemataFunc

func UpdateResctrlSchemataFunc(u ResourceUpdater) error

func UpdateResctrlTasksFunc

func UpdateResctrlTasksFunc(resource ResourceUpdater) error

Types

type CgroupReader

type CgroupReader interface {
	ReadCPUQuota(parentDir string) (int64, error)
	ReadCPUPeriod(parentDir string) (int64, error)
	ReadCPUShares(parentDir string) (int64, error)
	ReadCPUSet(parentDir string) (*cpuset.CPUSet, error)
	ReadCPUAcctUsage(parentDir string) (uint64, error)
	ReadCPUStat(parentDir string) (*sysutil.CPUStatRaw, error)
	ReadMemoryLimit(parentDir string) (int64, error)
	ReadMemoryStat(parentDir string) (*sysutil.MemoryStatRaw, error)
	ReadMemoryNumaStat(parentDir string) ([]sysutil.NumaMemoryPages, error)
	ReadCPUTasks(parentDir string) ([]int32, error)
	ReadPSI(parentDir string) (*PSIByResource, error)
}

func NewCgroupReader

func NewCgroupReader() CgroupReader

type CgroupResourceUpdater

type CgroupResourceUpdater struct {
	// contains filtered or unexported fields
}

func (*CgroupResourceUpdater) Clone

func (*CgroupResourceUpdater) GetLastUpdateTimestamp

func (u *CgroupResourceUpdater) GetLastUpdateTimestamp() time.Time

func (*CgroupResourceUpdater) GeteventHelper added in v1.2.0

func (u *CgroupResourceUpdater) GeteventHelper() *audit.EventHelper

func (*CgroupResourceUpdater) Key

func (u *CgroupResourceUpdater) Key() string

func (*CgroupResourceUpdater) MergeUpdate

func (u *CgroupResourceUpdater) MergeUpdate() (ResourceUpdater, error)

func (*CgroupResourceUpdater) Path

func (u *CgroupResourceUpdater) Path() string

func (*CgroupResourceUpdater) ResourceType

func (u *CgroupResourceUpdater) ResourceType() sysutil.ResourceType

func (*CgroupResourceUpdater) SetUpdateFunc

func (u *CgroupResourceUpdater) SetUpdateFunc(updateFunc UpdateFunc, mergeUpdateFunc MergeUpdateFunc)

func (*CgroupResourceUpdater) SeteventHelper added in v1.2.0

func (u *CgroupResourceUpdater) SeteventHelper(a *audit.EventHelper)

func (*CgroupResourceUpdater) UpdateLastUpdateTimestamp

func (u *CgroupResourceUpdater) UpdateLastUpdateTimestamp(time time.Time)

func (*CgroupResourceUpdater) Value

func (u *CgroupResourceUpdater) Value() string

type CgroupUpdaterFactoryImpl

type CgroupUpdaterFactoryImpl struct {
	// contains filtered or unexported fields
}

func (*CgroupUpdaterFactoryImpl) New

func (f *CgroupUpdaterFactoryImpl) New(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

func (*CgroupUpdaterFactoryImpl) Register

func (f *CgroupUpdaterFactoryImpl) Register(g NewResourceUpdaterFunc, resourceTypes ...sysutil.ResourceType)

type CgroupV1Reader

type CgroupV1Reader struct{}

func (*CgroupV1Reader) ReadCPUAcctUsage

func (r *CgroupV1Reader) ReadCPUAcctUsage(parentDir string) (uint64, error)

func (*CgroupV1Reader) ReadCPUPeriod

func (r *CgroupV1Reader) ReadCPUPeriod(parentDir string) (int64, error)

func (*CgroupV1Reader) ReadCPUQuota

func (r *CgroupV1Reader) ReadCPUQuota(parentDir string) (int64, error)

func (*CgroupV1Reader) ReadCPUSet

func (r *CgroupV1Reader) ReadCPUSet(parentDir string) (*cpuset.CPUSet, error)

func (*CgroupV1Reader) ReadCPUShares

func (r *CgroupV1Reader) ReadCPUShares(parentDir string) (int64, error)

func (*CgroupV1Reader) ReadCPUStat

func (r *CgroupV1Reader) ReadCPUStat(parentDir string) (*sysutil.CPUStatRaw, error)

func (*CgroupV1Reader) ReadCPUTasks

func (r *CgroupV1Reader) ReadCPUTasks(parentDir string) ([]int32, error)

func (*CgroupV1Reader) ReadMemoryLimit

func (r *CgroupV1Reader) ReadMemoryLimit(parentDir string) (int64, error)

func (*CgroupV1Reader) ReadMemoryNumaStat added in v1.2.0

func (r *CgroupV1Reader) ReadMemoryNumaStat(parentDir string) ([]sysutil.NumaMemoryPages, error)

func (*CgroupV1Reader) ReadMemoryStat

func (r *CgroupV1Reader) ReadMemoryStat(parentDir string) (*sysutil.MemoryStatRaw, error)

func (*CgroupV1Reader) ReadPSI added in v1.2.0

func (r *CgroupV1Reader) ReadPSI(parentDir string) (*PSIByResource, error)

type CgroupV2Reader

type CgroupV2Reader struct{}

func (*CgroupV2Reader) ReadCPUAcctUsage

func (r *CgroupV2Reader) ReadCPUAcctUsage(parentDir string) (uint64, error)

func (*CgroupV2Reader) ReadCPUPeriod

func (r *CgroupV2Reader) ReadCPUPeriod(parentDir string) (int64, error)

func (*CgroupV2Reader) ReadCPUQuota

func (r *CgroupV2Reader) ReadCPUQuota(parentDir string) (int64, error)

func (*CgroupV2Reader) ReadCPUSet

func (r *CgroupV2Reader) ReadCPUSet(parentDir string) (*cpuset.CPUSet, error)

func (*CgroupV2Reader) ReadCPUShares

func (r *CgroupV2Reader) ReadCPUShares(parentDir string) (int64, error)

func (*CgroupV2Reader) ReadCPUStat

func (r *CgroupV2Reader) ReadCPUStat(parentDir string) (*sysutil.CPUStatRaw, error)

func (*CgroupV2Reader) ReadCPUTasks

func (r *CgroupV2Reader) ReadCPUTasks(parentDir string) ([]int32, error)

func (*CgroupV2Reader) ReadMemoryLimit

func (r *CgroupV2Reader) ReadMemoryLimit(parentDir string) (int64, error)

func (*CgroupV2Reader) ReadMemoryNumaStat added in v1.2.0

func (r *CgroupV2Reader) ReadMemoryNumaStat(parentDir string) ([]sysutil.NumaMemoryPages, error)

func (*CgroupV2Reader) ReadMemoryStat

func (r *CgroupV2Reader) ReadMemoryStat(parentDir string) (*sysutil.MemoryStatRaw, error)

func (*CgroupV2Reader) ReadPSI added in v1.2.0

func (r *CgroupV2Reader) ReadPSI(parentDir string) (*PSIByResource, error)

type Config

type Config struct {
	ResourceForceUpdateSeconds int
}

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

type DefaultResourceUpdater

type DefaultResourceUpdater struct {
	// contains filtered or unexported fields
}

func (*DefaultResourceUpdater) Clone

func (*DefaultResourceUpdater) GetLastUpdateTimestamp

func (u *DefaultResourceUpdater) GetLastUpdateTimestamp() time.Time

func (*DefaultResourceUpdater) Key

func (u *DefaultResourceUpdater) Key() string

func (*DefaultResourceUpdater) MergeUpdate

func (u *DefaultResourceUpdater) MergeUpdate() (ResourceUpdater, error)

func (*DefaultResourceUpdater) Path

func (u *DefaultResourceUpdater) Path() string

func (*DefaultResourceUpdater) ResourceType

func (u *DefaultResourceUpdater) ResourceType() sysutil.ResourceType

func (*DefaultResourceUpdater) UpdateLastUpdateTimestamp

func (u *DefaultResourceUpdater) UpdateLastUpdateTimestamp(time time.Time)

func (*DefaultResourceUpdater) Value

func (u *DefaultResourceUpdater) Value() string

type GuestCgroupResourceUpdater

type GuestCgroupResourceUpdater struct {
	*CgroupResourceUpdater
	// contains filtered or unexported fields
}

type MergeConditionFunc

type MergeConditionFunc func(oldValue, newValue string) (mergedValue string, needMerge bool, err error)

type MergeUpdateFunc

type MergeUpdateFunc func(resource ResourceUpdater) (ResourceUpdater, error)

type NewResourceUpdaterFunc

type NewResourceUpdaterFunc func(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

type PSIByResource added in v1.2.0

type PSIByResource struct {
	CPU PSIStats
	Mem PSIStats
	IO  PSIStats
}

type PSILine added in v1.2.0

type PSILine struct {
	Avg10  float64
	Avg60  float64
	Avg300 float64
	Total  uint64
}

type PSIPath added in v1.2.0

type PSIPath struct {
	CPU string
	Mem string
	IO  string
}

type PSIStats added in v1.2.0

type PSIStats struct {
	Some *PSILine
	Full *PSILine

	FullSupported bool
}

func ParsePSIStats added in v1.2.0

func ParsePSIStats(r io.Reader) (PSIStats, error)

parsePSIStats parses the specified file for pressure stall information.

type ResctrlSchemataResourceUpdater

type ResctrlSchemataResourceUpdater struct {
	DefaultResourceUpdater
	// contains filtered or unexported fields
}

func (*ResctrlSchemataResourceUpdater) Clone

func (*ResctrlSchemataResourceUpdater) Key

type ResourceUpdateExecutor

type ResourceUpdateExecutor interface {
	Update(cacheable bool, updater ResourceUpdater) (updated bool, err error)
	UpdateBatch(cacheable bool, updaters ...ResourceUpdater)
	// LeveledUpdateBatch is to cacheable update resources by the order of resources' level.
	// For cgroup interfaces like `cpuset.cpus` and `memory.min`, reconciliation from top to bottom should keep the
	// upper value larger/broader than the lower. Thus a Leveled updater is implemented as follows:
	// 1. update batch of cgroup resources group by cgroup interface, i.e. cgroup filename.
	// 2. update each cgroup resource by the order of layers: firstly update resources from upper to lower by merging
	//    the new value with old value; then update resources from lower to upper with the new value.
	LeveledUpdateBatch(updaters [][]ResourceUpdater)
	Run(stopCh <-chan struct{})
}

func NewResourceUpdateExecutor

func NewResourceUpdateExecutor() ResourceUpdateExecutor

type ResourceUpdateExecutorImpl

type ResourceUpdateExecutorImpl struct {
	LeveledUpdateLock sync.Mutex
	ResourceCache     *cache.Cache
	Config            *Config
	// contains filtered or unexported fields
}

func (*ResourceUpdateExecutorImpl) LeveledUpdateBatch

func (e *ResourceUpdateExecutorImpl) LeveledUpdateBatch(updaters [][]ResourceUpdater)

func (*ResourceUpdateExecutorImpl) Run

func (e *ResourceUpdateExecutorImpl) Run(stopCh <-chan struct{})

Run runs the ResourceUpdateExecutor. TODO: run single executor when the qos manager starts.

func (*ResourceUpdateExecutorImpl) Update

func (e *ResourceUpdateExecutorImpl) Update(cacheable bool, resource ResourceUpdater) (bool, error)

Update updates the resources with the given cacheable attribute with the cacheable attribute directly.

func (*ResourceUpdateExecutorImpl) UpdateBatch

func (e *ResourceUpdateExecutorImpl) UpdateBatch(cacheable bool, updaters ...ResourceUpdater)

UpdateBatch updates a batch of resources with the given cacheable attribute. TODO: merge and resolve conflicts of batch updates from multiple callers.

type ResourceUpdater

type ResourceUpdater interface {
	ResourceType() sysutil.ResourceType
	Key() string
	Path() string
	Value() string
	MergeUpdate() (ResourceUpdater, error)
	Clone() ResourceUpdater
	GetLastUpdateTimestamp() time.Time
	UpdateLastUpdateTimestamp(time time.Time)
	// contains filtered or unexported methods
}

func CalculateResctrlL3TasksResource

func CalculateResctrlL3TasksResource(group string, taskIds []int32) (ResourceUpdater, error)

func MergeFuncUpdateCgroup

func MergeFuncUpdateCgroup(resource ResourceUpdater, mergeCondition MergeConditionFunc) (ResourceUpdater, error)

func NewBlkIOResourceUpdater added in v1.3.0

func NewBlkIOResourceUpdater(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

func NewCPUSharesCgroupUpdater

func NewCPUSharesCgroupUpdater(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

func NewCgroupUpdater

func NewCgroupUpdater(resourceType sysutil.ResourceType, parentDir string, value string, updateFunc UpdateFunc, e *audit.EventHelper) (ResourceUpdater, error)

func NewCommonCgroupUpdater

func NewCommonCgroupUpdater(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

NewCommonCgroupUpdater returns a CgroupResourceUpdater for updating known cgroup resources.

func NewCommonDefaultUpdater

func NewCommonDefaultUpdater(key string, file string, value string, e *audit.EventHelper) (ResourceUpdater, error)

NewCommonDefaultUpdater returns a DefaultResourceUpdater for update general files.

func NewCommonDefaultUpdaterWithUpdateFunc

func NewCommonDefaultUpdaterWithUpdateFunc(key string, file string, value string, updateFunc UpdateFunc, e *audit.EventHelper) (ResourceUpdater, error)

NewCommonDefaultUpdaterWithUpdateFunc returns a DefaultResourceUpdater for update general files with the given update function.

func NewDetailCgroupUpdater

func NewDetailCgroupUpdater(resource sysutil.Resource, parentDir string, value string, updateFunc UpdateFunc, e *audit.EventHelper) (ResourceUpdater, error)

NewDetailCgroupUpdater returns a new *CgroupResourceUpdater according to the given Resource, which is generally used for backwards compatibility. It is not guaranteed for updating successfully since it does not retrieve from the known cgroup resources.

func NewMergeableCgroupUpdaterIfCPUSetLooser

func NewMergeableCgroupUpdaterIfCPUSetLooser(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

func NewMergeableCgroupUpdaterIfValueLarger

func NewMergeableCgroupUpdaterIfValueLarger(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

func NewMergeableCgroupUpdaterWithCondition

func NewMergeableCgroupUpdaterWithCondition(resourceType sysutil.ResourceType, parentDir string, value string, mergeCondition MergeConditionFunc, e *audit.EventHelper) (ResourceUpdater, error)

func NewResctrlL3SchemataResource

func NewResctrlL3SchemataResource(group, schemataDelta string, l3Num int) ResourceUpdater

func NewResctrlMbSchemataResource

func NewResctrlMbSchemataResource(group, schemataDelta string, l3Num int) ResourceUpdater

func NewUnlimitedCgroupUpdater

func NewUnlimitedCgroupUpdater(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)

type ResourceUpdaterFactory

type ResourceUpdaterFactory interface {
	Register(g NewResourceUpdaterFunc, resourceTypes ...sysutil.ResourceType)
	New(resourceType sysutil.ResourceType, parentDir string, value string, e *audit.EventHelper) (ResourceUpdater, error)
}

func NewCgroupUpdaterFactory

func NewCgroupUpdaterFactory() ResourceUpdaterFactory

type UpdateFunc

type UpdateFunc func(resource ResourceUpdater) error

Jump to

Keyboard shortcuts

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