Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioweight: adding pod level setting #550

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/katalyst-agent/app/options/qrm/io_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type WritebackThrottlingOption struct {

type IOCostOption struct {
EnableSettingIOCost bool
CheckWBTDisabled bool
IOCostQoSConfigFile string
IOCostModelConfigFile string
}
Expand All @@ -62,6 +63,7 @@ func NewIOOptions() *IOOptions {
},
IOCostOption: IOCostOption{
EnableSettingIOCost: false,
CheckWBTDisabled: true,
IOCostQoSConfigFile: "",
IOCostModelConfigFile: "",
},
Expand All @@ -88,6 +90,8 @@ func (o *IOOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.WBTValueNVME, "writeback throttling value for NVME")
fs.BoolVar(&o.EnableSettingIOCost, "enable-io-cost",
o.EnableSettingIOCost, "if set it to true, io.cost setting will be executed")
fs.BoolVar(&o.CheckWBTDisabled, "check-wbt-disabled",
o.CheckWBTDisabled, "if set it to true, wbt should be disabled")
fs.StringVar(&o.IOCostQoSConfigFile, "io-cost-qos-config-file",
o.IOCostQoSConfigFile, "the absolute path of io.cost.qos qos config file")
fs.StringVar(&o.IOCostModelConfigFile, "io-cost-model-config-file",
Expand All @@ -107,6 +111,7 @@ func (o *IOOptions) ApplyTo(conf *qrmconfig.IOQRMPluginConfig) error {
conf.WBTValueSSD = o.WBTValueSSD
conf.WBTValueNVME = o.WBTValueNVME
conf.EnableSettingIOCost = o.EnableSettingIOCost
conf.CheckWBTDisabled = o.CheckWBTDisabled
conf.IOCostQoSConfigFile = o.IOCostQoSConfigFile
conf.IOCostModelConfigFile = o.IOCostModelConfigFile
conf.EnableSettingIOWeight = o.EnableSettingIOWeight
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/iocost/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
DevModelBcache DevModel = "bcache"
DevModelDeviceMapper DevModel = "dm"

sysDiskPrefix = "/sys/block"

IOStatMetricCostVrate = "cost.vrate"

MetricNameIOCostVrate = "iocost_vrate"
Expand Down
39 changes: 39 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ package iocost

import (
"fmt"
"io/ioutil"
"path/filepath"
"strconv"
"sync"

"github.com/kubewharf/katalyst-core/pkg/config"
coreconfig "github.com/kubewharf/katalyst-core/pkg/config"
dynamicconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic"
coreconsts "github.com/kubewharf/katalyst-core/pkg/consts"
"github.com/kubewharf/katalyst-core/pkg/metaserver"
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/helper"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
cgcommon "github.com/kubewharf/katalyst-core/pkg/util/cgroup/common"
Expand Down Expand Up @@ -236,6 +239,33 @@ func applyIOCostConfig(conf *config.Configuration, emitter metrics.MetricEmitter
applyIOCostModelWithDefault(ioCostModelConfigs, devsIDToModel)
}

func checkWBTDisabled(targetDiskType float64, diskPath string, emitter metrics.MetricEmitter, metaServer *metaserver.MetaServer) (bool, error) {
dir, err := ioutil.ReadDir(diskPath)
if err != nil {
general.Errorf("failed to readdir:%v, err:%v", sysDiskPrefix, err)
return false, err
}
for _, entry := range dir {
diskType, err := helper.GetDeviceMetric(metaServer.MetricsFetcher, emitter, coreconsts.MetricIODiskType, entry.Name())
if err != nil {
general.Errorf("failed to read MetricIODiskType, err:%v", err)
return false, err
}

if diskType == targetDiskType {
WBTValue, err := helper.GetDeviceMetric(metaServer.MetricsFetcher, emitter, coreconsts.MetricIODiskWBTValue, entry.Name())
if err != nil {
general.Errorf("failed to read MetricIODiskWBTValue, err:%v", err)
return false, err
}
if WBTValue != 0 {
return false, nil
}
}
}
return true, nil
}

func SetIOCost(conf *coreconfig.Configuration,
_ interface{},
_ *dynamicconfig.DynamicAgentConfiguration,
Expand Down Expand Up @@ -265,6 +295,15 @@ func SetIOCost(conf *coreconfig.Configuration,
return
}

// Strict mode: checking wbt file.
if conf.CheckWBTDisabled {
disabled, err := checkWBTDisabled(coreconsts.DiskTypeHDD, sysDiskPrefix, emitter, metaServer)
if !disabled {
general.Infof("wbt for HDD disks should be disabled, err=%v", err)
return
}
}

if !cgcommon.CheckCgroup2UnifiedMode() {
general.Infof("not in cgv2 environment, skip IOAsyncTaskFunc")
return
Expand Down
13 changes: 13 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func TestSetIOCost(t *testing.T) {
IOQRMPluginConfig: &qrm.IOQRMPluginConfig{
IOCostOption: qrm.IOCostOption{
EnableSettingIOCost: true,
CheckWBTDisabled: true,
},
},
},
Expand Down Expand Up @@ -411,3 +412,15 @@ func TestApplyIOCostQoSWithDefault(t *testing.T) {
// Call the function under test
applyIOCostQoSWithDefault(ioCostQoSConfigs, devsIDToModel)
}

func TestCheckWBTDisabled(t *testing.T) {
t.Parallel()
metaServer, err := makeMetaServer()
assert.NoError(t, err)

result, _ := checkWBTDisabled(1.0, sysDiskPrefix, metrics.DummyMetrics{}, metaServer)
assert.False(t, result)

result, _ = checkWBTDisabled(1.0, "notExist", metrics.DummyMetrics{}, metaServer)
assert.False(t, result)
}
32 changes: 32 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/ioweight/ioweight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ package ioweight

import (
"context"
"fmt"
"strconv"

v1 "k8s.io/api/core/v1"

"github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate"
coreconfig "github.com/kubewharf/katalyst-core/pkg/config"
dynamicconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic"
Expand Down Expand Up @@ -64,6 +67,26 @@ func applyIOWeightCgroupLevelConfig(conf *coreconfig.Configuration, emitter metr
}
}

func applyPodIOWeight(pod *v1.Pod, defaultDevID, qosLevelDefaultValue string) error {
ioWeightValue, err := strconv.ParseInt(qosLevelDefaultValue, 10, 64)
if err != nil {
return fmt.Errorf("strconv.ParseInt failed, string=%v, err=%v", qosLevelDefaultValue, err)
}

podAbsCGPath, err := common.GetPodAbsCgroupPath(common.CgroupSubsysIO, string(pod.UID))
if err != nil {
return fmt.Errorf("GetPodAbsCgroupPath for pod: %s/%s failed with error: %v", pod.Namespace, pod.Name, err)
}

err = cgroupmgr.ApplyIOWeightWithAbsolutePath(podAbsCGPath, defaultDevID, uint64(ioWeightValue))
if err != nil {
return fmt.Errorf("ApplyIOWeightWithAbsolutePath for pod: %s/%s failed with error: %v", pod.Namespace, pod.Name, err)
}

general.Infof("ApplyIOWeightWithRelativePath for pod: %s/%s, weight: %d successfully", pod.Namespace, pod.Name, ioWeightValue)
return nil
}

func applyIOWeightQoSLevelConfig(conf *coreconfig.Configuration,
emitter metrics.MetricEmitter, metaServer *metaserver.MetaServer,
) {
Expand Down Expand Up @@ -102,6 +125,15 @@ func applyIOWeightQoSLevelConfig(conf *coreconfig.Configuration,
if !ok {
continue
}

// setup pod level.
err = applyPodIOWeight(pod, defaultDevID, qosLevelDefaultValue)
if err != nil {
general.Errorf("Failed to apply IO weight for pod %s/%s: %v", pod.Namespace, pod.Name, err)
continue
}

// setup contaienr level.
for _, containerStatus := range pod.Status.ContainerStatuses {
podUID, containerID := string(pod.UID), native.TrimContainerIDPrefix(containerStatus.ContainerID)
err := cgroupmgr.ApplyUnifiedDataForContainer(podUID, containerID, extraControlKnobConfigs[controlKnobKeyIOWeight].CgroupSubsysName, cgroupIOWeightName, qosLevelDefaultValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,24 @@ func TestIOWeightTaskFunc(t *testing.T) {
},
}, metrics.DummyMetrics{}, metaServerEmpty)
}

func TestApplyPodIOWeight(t *testing.T) {
t.Parallel()

pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
UID: "test-uid",
Namespace: "default",
Name: "test-pod",
},
}

defaultDevID := "test-dev-id"
qosLevelDefaultValue := "500"

err := applyPodIOWeight(pod, defaultDevID, qosLevelDefaultValue)
assert.Error(t, err)

err = applyPodIOWeight(pod, defaultDevID, "test")
assert.Error(t, err)
}
1 change: 1 addition & 0 deletions pkg/config/agent/qrm/io_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type WritebackThrottlingOption struct {

type IOCostOption struct {
EnableSettingIOCost bool
CheckWBTDisabled bool
IOCostQoSConfigFile string
IOCostModelConfigFile string
}
Expand Down
Loading