Skip to content

Commit

Permalink
refactor(sysadvisor): bind reclaim_cores contianers to non-exclusive …
Browse files Browse the repository at this point in the history
…numas

Signed-off-by: linzhecheng <linzhecheng@bytedance.com>
  • Loading branch information
cheney-lin committed Sep 12, 2023
1 parent 8873dde commit 3f650a4
Showing 1 changed file with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ limitations under the License.
package plugin

import (
"context"
"fmt"
"sync"

"k8s.io/apimachinery/pkg/util/errors"

apiconsts "github.com/kubewharf/katalyst-api/pkg/consts"
"github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/memory/dynamicpolicy/memoryadvisor"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/helper"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types"
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/consts"
Expand All @@ -39,13 +44,15 @@ const (
type memsetBinder struct {
mutex sync.RWMutex
metaReader metacache.MetaReader
metaServer *metaserver.MetaServer
emitter metrics.MetricEmitter
containerMemset map[consts.PodContainerName]machine.CPUSet
}

func NewMemsetBinder(conf *config.Configuration, extraConfig interface{}, metaReader metacache.MetaReader, metaServer *metaserver.MetaServer, emitter metrics.MetricEmitter) MemoryAdvisorPlugin {
return &memsetBinder{
metaReader: metaReader,
metaServer: metaServer,
emitter: emitter,
}
}
Expand All @@ -55,18 +62,51 @@ func (mb *memsetBinder) reclaimedContainersFilter(ci *types.ContainerInfo) bool
}

func (mb *memsetBinder) Reconcile(status *types.MemoryPressureStatus) error {
var (
errList []error
)

allNUMAs := mb.metaServer.CPUDetails.NUMANodes()

availNUMAs := allNUMAs

containerMemset := make(map[consts.PodContainerName]machine.CPUSet)
containers := make([]*types.ContainerInfo, 0)
mb.metaReader.RangeContainer(func(podUID string, containerName string, containerInfo *types.ContainerInfo) bool {
if mb.reclaimedContainersFilter(containerInfo) {
containers = append(containers, containerInfo)
return true
}

reclaimEnable, err := helper.PodEnableReclaim(context.Background(), mb.metaServer, podUID, true)
if err != nil {
errList = append(errList, err)
return true
}

if containerInfo.IsNumaExclusive() && !reclaimEnable {
memset := machine.GetCPUAssignmentNUMAs(containerInfo.TopologyAwareAssignments)
if memset.IsEmpty() {
errList = append(errList, fmt.Errorf("contianer(%v/%v) TopologyAwareAssignments is empty", containerInfo.PodName, containerName))

Check failure on line 90 in pkg/agent/sysadvisor/plugin/qosaware/resource/memory/plugin/memset_binder.go

View workflow job for this annotation

GitHub Actions / Lint

`contianer` is a misspelling of `container` (misspell)
return true
}
availNUMAs = availNUMAs.Difference(memset)
}
return true
})

err := errors.NewAggregate(errList)
if err != nil {
return err
}

if availNUMAs.IsEmpty() {
availNUMAs = allNUMAs
general.InfoS("availNUMAs is empty, have to bind all NUMAs to reclaimed_cores containers")
}

for _, ci := range containers {
memset := machine.GetCPUAssignmentNUMAs(ci.TopologyAwareAssignments)
containerMemset[native.GeneratePodContainerName(ci.PodUID, ci.ContainerName)] = memset
containerMemset[native.GeneratePodContainerName(ci.PodUID, ci.ContainerName)] = availNUMAs
}
mb.mutex.Lock()
defer mb.mutex.Unlock()
Expand Down

0 comments on commit 3f650a4

Please sign in to comment.