Skip to content

Commit

Permalink
fix(qrm): fix advisor drop cache handler missing nbytes parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
csfldf committed Mar 6, 2024
1 parent d74807b commit c7d9d3f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,17 @@ func (p *DynamicPolicy) handleAdvisorDropCache(
return fmt.Errorf("get container id of pod: %s container: %s failed with error: %v", entryName, subEntryName, err)
}

container, err := p.metaServer.GetContainerSpec(entryName, subEntryName)
if err != nil || container == nil {
return fmt.Errorf("get container spec for pod: %s, container: %s failed with error: %v", entryName, subEntryName, err)
}

dropCacheWorkName := util.GetContainerAsyncWorkName(entryName, subEntryName, memoryPluginAsyncWorkTopicDropCache)
// start a asynchronous work to drop cache for the container whose numaset changed and doesn't require numa_binding
err = p.asyncWorkers.AddWork(dropCacheWorkName,
&asyncworker.Work{
Fn: cgroupmgr.DropCacheWithTimeoutForContainer,
Params: []interface{}{entryName, containerID, dropCacheTimeoutSeconds},
Params: []interface{}{entryName, containerID, dropCacheTimeoutSeconds, GetFullyDropCacheBytes(container)},
DeliveredAt: time.Now()}, asyncworker.DuplicateWorkPolicyOverride)

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,22 +460,13 @@ func (p *DynamicPolicy) adjustAllocationEntries() error {
}
}

memoryLimit := container.Resources.Limits[v1.ResourceMemory]
memoryReq := container.Resources.Requests[v1.ResourceMemory]
memoryLimitBytes := memoryLimit.Value()
memoryReqBytes := memoryReq.Value()

if memoryLimitBytes == 0 {
memoryLimitBytes = memoryReqBytes
}

dropCacheWorkName := util.GetContainerAsyncWorkName(podUID, containerName,
memoryPluginAsyncWorkTopicDropCache)
// start a asynchronous work to drop cache for the container whose numaset changed and doesn't require numa_binding
err = p.asyncWorkers.AddWork(dropCacheWorkName,
&asyncworker.Work{
Fn: cgroupmgr.DropCacheWithTimeoutForContainer,
Params: []interface{}{podUID, containerID, dropCacheTimeoutSeconds, memoryLimitBytes},
Params: []interface{}{podUID, containerID, dropCacheTimeoutSeconds, GetFullyDropCacheBytes(container)},
DeliveredAt: time.Now()}, asyncworker.DuplicateWorkPolicyOverride)

if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ import (
"github.com/kubewharf/katalyst-core/pkg/util/general"
)

func GetFullyDropCacheBytes(container *v1.Container) int64 {
if container == nil {
return 0
}

memoryLimit := container.Resources.Limits[v1.ResourceMemory]
memoryReq := container.Resources.Requests[v1.ResourceMemory]
fullyDropCacheBytes := memoryLimit.Value()

if fullyDropCacheBytes == 0 {
fullyDropCacheBytes = memoryReq.Value()
}

return fullyDropCacheBytes
}

// GetReservedMemory is used to spread total reserved memories into per-numa level.
// this reserve resource calculation logic should be kept in qrm, if advisor wants
// to get this info, it should depend on the returned checkpoint (through cpu-server)
Expand Down
79 changes: 79 additions & 0 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
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 (
"testing"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

func TestGetFullyDropCacheBytes(t *testing.T) {
type args struct {
container *v1.Container
}
tests := []struct {
name string
args args
want int64
}{
{
name: "contaienr with both request and limit",
args: args{
container: &v1.Container{
Name: "c1",
Resources: v1.ResourceRequirements{
Limits: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("3Gi"),
},
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("2Gi"),
},
},
},
},
want: 3221225472,
},
{
name: "contaienr only with request",
args: args{
container: &v1.Container{
Name: "c1",
Resources: v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("2Gi"),
},
},
},
},
want: 2147483648,
},
{
name: "nil container",
args: args{},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetFullyDropCacheBytes(tt.args.container); got != tt.want {
t.Errorf("GetFullyDropCacheBytes() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit c7d9d3f

Please sign in to comment.