-
Notifications
You must be signed in to change notification settings - Fork 121
feat(qrm, sysadvisor): Periodically (every 300s) clean up excessive (>2000) dying mem cgroups #1069
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
Open
Zera-Algorithm
wants to merge
5
commits into
kubewharf:main
Choose a base branch
from
Zera-Algorithm:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+642
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1e252d
feat(qrm, sysadvisor): Periodically (every 300s) clean up excessive (…
Zera-Algorithm 2c55d2e
fix(cgroup): Add logging for dying memcg reclamation amount
Zera-Algorithm 21bb4b9
fix(sys-advisor, qrm): encapsulate `GetCgroupNrDyingDescendants` in c…
Zera-Algorithm ec7c420
fix(sys-advisor, qrm-plugin): add unit tests, and remove duplicate pa…
Zera-Algorithm 5827e06
feat(sys-advisor): add a control switch for enabling or disabling dyi…
Zera-Algorithm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_advisor_handler_dying_memcg_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| Copyright 2022 The Katalyst Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package dynamicpolicy | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "github.com/bytedance/mockey" | ||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc" | ||
| "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor" | ||
| "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/util" | ||
| "github.com/kubewharf/katalyst-core/pkg/consts" | ||
| "github.com/kubewharf/katalyst-core/pkg/metrics" | ||
| "github.com/kubewharf/katalyst-core/pkg/util/asyncworker" | ||
| cgroupmgr "github.com/kubewharf/katalyst-core/pkg/util/cgroup/manager" | ||
| "github.com/kubewharf/katalyst-core/pkg/util/machine" | ||
| ) | ||
|
|
||
| var dyingMemcgReclaimTestMutex sync.Mutex | ||
|
|
||
| func TestDynamicPolicy_handleAdvisorDyingMemcgReclaim(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("empty cgroup path", func(t *testing.T) { | ||
| t.Parallel() | ||
| dyingMemcgReclaimTestMutex.Lock() | ||
| defer dyingMemcgReclaimTestMutex.Unlock() | ||
| p := &DynamicPolicy{} | ||
| calculationInfo := &advisorsvc.CalculationInfo{ | ||
| CalculationResult: &advisorsvc.CalculationResult{ | ||
| Values: map[string]string{}, | ||
| }, | ||
| } | ||
|
|
||
| err := p.handleAdvisorDyingMemcgReclaim(nil, nil, nil, metrics.DummyMetrics{}, nil, "pod", "container", calculationInfo, nil) | ||
| assert.Error(t, err) | ||
| }) | ||
|
|
||
| t.Run("disabled dying memcg reclaim", func(t *testing.T) { | ||
| t.Parallel() | ||
| dyingMemcgReclaimTestMutex.Lock() | ||
| defer dyingMemcgReclaimTestMutex.Unlock() | ||
| defer mockey.UnPatchAll() | ||
|
|
||
| p := &DynamicPolicy{ | ||
| defaultAsyncLimitedWorkers: asyncworker.NewAsyncLimitedWorkers("test", 1, metrics.DummyMetrics{}), | ||
| } | ||
|
|
||
| disableSwapCalled := false | ||
| addWorkCalled := false | ||
| getEffectiveCalled := false | ||
|
|
||
| mockey.Mock(cgroupmgr.DisableSwapMaxWithAbsolutePathRecursive).IncludeCurrentGoRoutine().To(func(_ string) error { | ||
| disableSwapCalled = true | ||
| return nil | ||
| }).Build() | ||
| mockey.Mock((*asyncworker.AsyncLimitedWorkers).AddWork).IncludeCurrentGoRoutine().To(func(_ *asyncworker.AsyncLimitedWorkers, _ *asyncworker.Work, _ asyncworker.DuplicateWorkPolicy) error { | ||
| addWorkCalled = true | ||
| return nil | ||
| }).Build() | ||
| mockey.Mock(cgroupmgr.GetEffectiveCPUSetWithAbsolutePath).IncludeCurrentGoRoutine().To(func(_ string) (machine.CPUSet, machine.CPUSet, error) { | ||
| getEffectiveCalled = true | ||
| return machine.NewCPUSet(0), machine.NewCPUSet(0), nil | ||
| }).Build() | ||
|
|
||
| calculationInfo := &advisorsvc.CalculationInfo{ | ||
| CgroupPath: "/sys/fs/cgroup/kubepods/burstable", | ||
| CalculationResult: &advisorsvc.CalculationResult{ | ||
| Values: map[string]string{ | ||
| string(memoryadvisor.ControlKnobKeySwapMax): consts.ControlKnobOFF, | ||
| string(memoryadvisor.ControlKnowKeyDyingMemcgReclaim): consts.ControlKnobOFF, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err := p.handleAdvisorDyingMemcgReclaim(nil, nil, nil, metrics.DummyMetrics{}, nil, "pod", "container", calculationInfo, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, disableSwapCalled) | ||
| assert.False(t, addWorkCalled) | ||
| assert.False(t, getEffectiveCalled) | ||
| }) | ||
|
|
||
| t.Run("enabled dying memcg reclaim", func(t *testing.T) { | ||
| t.Parallel() | ||
| dyingMemcgReclaimTestMutex.Lock() | ||
| defer dyingMemcgReclaimTestMutex.Unlock() | ||
| defer mockey.UnPatchAll() | ||
|
|
||
| p := &DynamicPolicy{ | ||
| defaultAsyncLimitedWorkers: asyncworker.NewAsyncLimitedWorkers("test", 1, metrics.DummyMetrics{}), | ||
| } | ||
|
|
||
| setSwapCalled := false | ||
| var capturedWork *asyncworker.Work | ||
| var capturedPolicy asyncworker.DuplicateWorkPolicy | ||
| mems := machine.NewCPUSet(0, 1) | ||
|
|
||
| mockey.Mock(cgroupmgr.SetSwapMaxWithAbsolutePathRecursive).IncludeCurrentGoRoutine().To(func(_ string) error { | ||
| setSwapCalled = true | ||
| return nil | ||
| }).Build() | ||
| mockey.Mock(cgroupmgr.GetEffectiveCPUSetWithAbsolutePath).IncludeCurrentGoRoutine().To(func(_ string) (machine.CPUSet, machine.CPUSet, error) { | ||
| return machine.NewCPUSet(0), mems, nil | ||
| }).Build() | ||
| mockey.Mock((*asyncworker.AsyncLimitedWorkers).AddWork).IncludeCurrentGoRoutine().To(func(_ *asyncworker.AsyncLimitedWorkers, work *asyncworker.Work, policy asyncworker.DuplicateWorkPolicy) error { | ||
| capturedWork = work | ||
| capturedPolicy = policy | ||
| return nil | ||
| }).Build() | ||
|
|
||
| calculationInfo := &advisorsvc.CalculationInfo{ | ||
| CgroupPath: "/sys/fs/cgroup/kubepods/burstable", | ||
| CalculationResult: &advisorsvc.CalculationResult{ | ||
| Values: map[string]string{ | ||
| string(memoryadvisor.ControlKnobKeySwapMax): consts.ControlKnobON, | ||
| string(memoryadvisor.ControlKnowKeyDyingMemcgReclaim): consts.ControlKnobON, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| emitter := metrics.DummyMetrics{} | ||
| err := p.handleAdvisorDyingMemcgReclaim(nil, nil, nil, emitter, nil, "pod", "container", calculationInfo, nil) | ||
| assert.NoError(t, err) | ||
| assert.True(t, setSwapCalled) | ||
| assert.NotNil(t, capturedWork) | ||
|
|
||
| expectedAbsPath := "/sys/fs/cgroup/kubepods/burstable" | ||
| expectedWorkName := util.GetCgroupAsyncWorkName("/sys/fs/cgroup/kubepods/burstable", memoryPluginAsyncWorkTopicDyingMemcgReclaim) | ||
| assert.Equal(t, expectedWorkName, capturedWork.Name) | ||
| assert.Equal(t, asyncworker.DuplicateWorkPolicy(asyncworker.DuplicateWorkPolicyOverride), capturedPolicy) | ||
| assert.Equal(t, expectedAbsPath, capturedWork.Params[0]) | ||
| assert.Equal(t, emitter, capturedWork.Params[1]) | ||
| assert.Equal(t, "pod", capturedWork.Params[2]) | ||
| assert.Equal(t, "container", capturedWork.Params[3]) | ||
| assert.Equal(t, mems, capturedWork.Params[4]) | ||
| assert.Equal(t, reflect.ValueOf(cgroupmgr.DyingMemcgReclaimWithAbsolutePath).Pointer(), reflect.ValueOf(capturedWork.Fn).Pointer()) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to put this configuration in MemoryAdvisorOptions?