github.com/kubewharf/katalyst-core@v0.5.3/pkg/util/cgroup/manager/manager.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package manager 18 19 import ( 20 "sync" 21 22 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common" 23 v1 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v1" 24 v2 "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager/v2" 25 ) 26 27 var ( 28 initManagerOnce sync.Once 29 manager Manager 30 ) 31 32 // Manager cgroup operation interface for different sub-systems. 33 // if v1 and v2 versioned cgroup system will perform different 34 // actions, it should be organized in manager; otherwise, implement in 35 // general util file instead. 36 type Manager interface { 37 ApplyMemory(absCgroupPath string, data *common.MemoryData) error 38 ApplyCPU(absCgroupPath string, data *common.CPUData) error 39 ApplyCPUSet(absCgroupPath string, data *common.CPUSetData) error 40 ApplyNetCls(absCgroupPath string, data *common.NetClsData) error 41 ApplyIOCostQoS(absCgroupPath string, devID string, data *common.IOCostQoSData) error 42 ApplyIOCostModel(absCgroupPath string, devID string, data *common.IOCostModelData) error 43 ApplyIOWeight(absCgroupPath string, devID string, weight uint64) error 44 ApplyUnifiedData(absCgroupPath, cgroupFileName, data string) error 45 46 GetMemory(absCgroupPath string) (*common.MemoryStats, error) 47 GetNumaMemory(absCgroupPath string) (map[int]*common.MemoryNumaMetrics, error) 48 GetCPU(absCgroupPath string) (*common.CPUStats, error) 49 GetCPUSet(absCgroupPath string) (*common.CPUSetStats, error) 50 GetIOCostQoS(absCgroupPath string) (map[string]*common.IOCostQoSData, error) 51 GetIOCostModel(absCgroupPath string) (map[string]*common.IOCostModelData, error) 52 GetDeviceIOWeight(absCgroupPath string, devID string) (uint64, bool, error) 53 GetIOStat(absCgroupPath string) (map[string]map[string]string, error) 54 GetMetrics(relCgroupPath string, subsystems map[string]struct{}) (*common.CgroupMetrics, error) 55 56 GetPids(absCgroupPath string) ([]string, error) 57 GetTasks(absCgroupPath string) ([]string, error) 58 } 59 60 // GetManager returns a cgroup instance for both v1/v2 version 61 func GetManager() Manager { 62 initManagerOnce.Do(func() { 63 if common.CheckCgroup2UnifiedMode() { 64 manager = v2.NewManager() 65 } else { 66 manager = v1.NewManager() 67 } 68 }) 69 return manager 70 }