Skip to content

Commit

Permalink
iocost: using default io.cost.model
Browse files Browse the repository at this point in the history
default io.cost.model applied to HDD disks

Signed-off-by: Robin Lu <robin.lu@bytedance.com>
  • Loading branch information
lubinszARM committed Apr 8, 2024
1 parent ef4b3ff commit e4c0f72
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
29 changes: 12 additions & 17 deletions pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,40 @@ var (
ioCgroupRootPath = cgcommon.GetCgroupRootPath(cgcommon.CgroupSubsysIO)
)

func applyIOCostModel(ioCostModelConfigs map[DevModel]*common.IOCostModelData, devsIDToModel map[string]DevModel) {
func applyIOCostModelWithDefault(ioCostModelConfigs map[DevModel]*common.IOCostModelData, devsIDToModel map[string]DevModel) {
curDevIDToIOCostModelData, err := manager.GetIOCostModelWithAbsolutePath(ioCgroupRootPath)
if err != nil {
general.Errorf("GetIOCostModelWithAbsolutePath failed with error: %v", err)
return
}

for devID, devModel := range devsIDToModel {
for devID := range devsIDToModel {
var expectedModelData, curModelData *common.IOCostModelData

if ioCostModelConfigs[devModel] != nil {
expectedModelData = ioCostModelConfigs[devModel]
} else {
expectedModelData = ioCostModelConfigs[DevModelDefault]
}

expectedModelData = ioCostModelConfigs[DevModelDefault]
if expectedModelData == nil {
general.Errorf("there is no expected io cost Model Data for devID: %s, devModel: %s", devID, devModel)
general.Errorf("there is no expected io cost Model Data for devID: %s", devID)
continue
}

curModelData = curDevIDToIOCostModelData[devID]
if curModelData == nil {
general.Errorf("there is no current io cost Model Data for devID: %s, devModel: %s", devID, devModel)
general.Errorf("there is no current io cost Model Data for devID: %s", devID)
continue
}

if (*curModelData) != (*expectedModelData) {
err = manager.ApplyIOCostModelWithAbsolutePath(ioCgroupRootPath, devID, expectedModelData)
if err != nil {
general.Errorf("ApplyIOCostModelWithAbsolutePath for devID: %s, devModel: %s, failed with error: %v",
devID, devModel, err)
general.Errorf("ApplyIOCostModelWithAbsolutePath for devID: %s, failed with error: %v",
devID, err)
} else {
general.Errorf("ApplyIOCostModelWithAbsolutePath for devID: %s, devModel: %s successfully",
devID, devModel)
general.Infof("ApplyIOCostModelWithAbsolutePath for devID: %s successfully:%v ",
devID, expectedModelData)
}
} else {
general.Infof("modelData isn't changed, skip ApplyIOCostModelWithAbsolutePath for devID: %s, devModel: %s ",
devID, devModel)
general.Infof("modelData isn't changed, skip ApplyIOCostModelWithAbsolutePath for devID: %s, modelData=%v ",
devID, expectedModelData)
}
}
}
Expand Down Expand Up @@ -242,7 +237,7 @@ func applyIOCostConfig(conf *config.Configuration, emitter metrics.MetricEmitter
}

applyIOCostQoSWithDefault(ioCostQoSConfigs, devsIDToModel)
applyIOCostModel(ioCostModelConfigs, devsIDToModel)
applyIOCostModelWithDefault(ioCostModelConfigs, devsIDToModel)
}

func SetIOCost(conf *coreconfig.Configuration,
Expand Down
17 changes: 16 additions & 1 deletion pkg/agent/qrm-plugins/io/handlers/iocost/iocost_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,22 @@ func Test_applyIOCostModel(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
applyIOCostModel(tt.args.ioCostModelConfigs, tt.args.devsIDToModel)
applyIOCostModelWithDefault(tt.args.ioCostModelConfigs, tt.args.devsIDToModel)
})
}
}

func TestApplyIOCostQoSWithDefault(t *testing.T) {
// Mocking the necessary dependencies
ioCostQoSConfigs := make(map[DevModel]*common.IOCostQoSData)
ioCostQoSConfigs[DevModelDefaultHDD] = &common.IOCostQoSData{Enable: 1}
ioCostQoSConfigs[DevModelDefault] = &common.IOCostQoSData{Enable: 1}

devsIDToModel := map[string]DevModel{
"devID1": DevModelDefaultHDD,
"devID2": DevModelDefaultHDD,
}

// Call the function under test
applyIOCostQoSWithDefault(ioCostQoSConfigs, devsIDToModel)
}
4 changes: 4 additions & 0 deletions pkg/util/cgroup/manager/v2/fs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func (m *manager) ApplyIOCostModel(absCgroupPath string, devID string, data *com
}

dataContent := data.String()
if data.CtrlMode == common.IOCostCtrlModeAuto {
dataContent = "ctrl=auto"
}

if err, applied, oldData := common.WriteFileIfChange(absCgroupPath, "io.cost.model", fmt.Sprintf("%s %s", devID, dataContent)); err != nil {
return err
} else if applied {
Expand Down

0 comments on commit e4c0f72

Please sign in to comment.