Skip to content

Commit

Permalink
refactor(util): set non-root cgroup memory.max
Browse files Browse the repository at this point in the history
Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin committed Apr 22, 2024
1 parent d2f559c commit 2a2a349
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func refaultPolicyFunc(lastStats TmoStats, currStats TmoStats, conf *tmoconf.TMO
// Decrease offloading size if detecting the reclaim accuracy or scan efficiency is below the targets
return nil, math.Max(0, currStats.lastOffloadingTargetSize*reclaimAccuracyRatio)
} else {
// Try to increase offloading size but make sure not exceed the max probe of memory usage and 10% of inactive memory
// Try to increase offloading size but make sure not exceed the max probe of memory usage and 10% of inactive memory when the target size of last round is relatively small,
// which means reclaim accuracy and reclaim scan efficiency is low.
return nil, math.Min(math.Max(currStats.lastOffloadingTargetSize*OffloadingSizeScaleCoeff, currStats.memInactive*InactiveProbe), currStats.memUsage*conf.RefaultPolicyConf.MaxProbe)
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/util/cgroup/manager/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func SetSwapMaxWithAbsolutePathToParentCgroupRecursive(absCgroupPath string) err
}

parentDir := filepath.Dir(absCgroupPath)
if parentDir != absCgroupPath {
if parentDir != absCgroupPath && parentDir != common.GetCgroupRootPath(common.CgroupSubsysMemory) {
err = SetSwapMaxWithAbsolutePathToParentCgroupRecursive(parentDir)
if err != nil {
return err
Expand All @@ -333,7 +333,9 @@ func SetSwapMaxWithAbsolutePathRecursive(absCgroupPath string) error {
general.Infof("[SetSwapMaxWithAbsolutePathRecursive] on cgroup: %s", absCgroupPath)

// set swap max to parent cgroups recursively
_ = SetSwapMaxWithAbsolutePathToParentCgroupRecursive(filepath.Dir(absCgroupPath))
if err := SetSwapMaxWithAbsolutePathToParentCgroupRecursive(filepath.Dir(absCgroupPath)); err != nil {
return err
}

// set swap max to sub cgroups recursively
err := filepath.Walk(absCgroupPath, func(path string, info fs.FileInfo, err error) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/cgroup/manager/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func TestSwapMax(t *testing.T) {
return ioutil.WriteFile(f, []byte(data), 0700)
})

tmpDir, err := ioutil.TempDir("", "fake-cgroup")
tmpDir, err := ioutil.TempDir("", "tmp/fake-cgroup")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)

monkey.Patch(common.GetCgroupRootPath, func(s string) string { return filepath.Dir(tmpDir) })

sawpFile := filepath.Join(tmpDir, "memory.swap.max")
err = ioutil.WriteFile(sawpFile, []byte{}, 0700)
assert.NoError(t, err)
Expand Down

0 comments on commit 2a2a349

Please sign in to comment.