Skip to content

Commit

Permalink
feat: support to update reservedForReclaim dynamicly
Browse files Browse the repository at this point in the history
Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin committed Aug 15, 2024
1 parent 8ea7721 commit e9e0642
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (cra *cpuResourceAdvisor) updateNumasAvailableResource() {
reservePoolInfo, _ := cra.metaCache.GetPoolInfo(state.PoolNameReserve)
cpusPerNuma := cra.metaServer.CPUsPerNuma()

coreNumReservedForReclaim := cra.conf.GetDynamicConfiguration().MinReclaimedResourceForAllocate[v1.ResourceCPU]
cra.reservedForReclaim = machine.GetCoreNumReservedForReclaim(int(coreNumReservedForReclaim.Value()), cra.metaServer.NumNUMANodes)

for id := 0; id < cra.metaServer.NumNUMANodes; id++ {
reservePoolNuma := 0
if cpuset, ok := reservePoolInfo.TopologyAwareAssignments[id]; ok {
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/machine/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func getCPUInstructionInfo(cpuInfo string) sets.String {
// per numa reserved resource is taken in a fair way with even step, e.g.
// 4 -> 1 1 1 1; 2 -> 1 0 1 0
func GetCoreNumReservedForReclaim(numReservedCores, numNumaNodes int) map[int]int {
if numReservedCores <= 0 {
numReservedCores = 1
}
if numNumaNodes < 0 {
numNumaNodes = 1
}
reservedPerNuma := numReservedCores / numNumaNodes
step := numNumaNodes / numReservedCores

Expand Down
75 changes: 75 additions & 0 deletions pkg/util/machine/cpu_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
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 machine

import (
"testing"

"github.com/stretchr/testify/assert"
)

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

tests := []struct {
name string
numReservedCores int
numNumaNodes int
want map[int]int
}{
{
name: "reserve 4",
numReservedCores: 4,
numNumaNodes: 4,
want: map[int]int{0: 1, 1: 1, 2: 1, 3: 1},
},
{
name: "reserve 2",
numReservedCores: 2,
numNumaNodes: 4,
want: map[int]int{0: 1, 1: 0, 2: 1, 3: 0},
},
{
name: "reserve 3",
numReservedCores: 3,
numNumaNodes: 4,
want: map[int]int{0: 1, 1: 1, 2: 1, 3: 1},
},
{
name: "reserve 0",
numReservedCores: 0,
numNumaNodes: 4,
want: map[int]int{0: 1, 1: 0, 2: 0, 3: 0},
},
{
name: "reserve 1",
numReservedCores: 1,
numNumaNodes: 4,
want: map[int]int{0: 1, 1: 0, 2: 0, 3: 0},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

r := GetCoreNumReservedForReclaim(tt.numReservedCores, tt.numNumaNodes)
assert.Equal(t, tt.want, r)
})
}
}

0 comments on commit e9e0642

Please sign in to comment.