Skip to content

Commit

Permalink
feat(qrm): memory plugin support shared_cores with numa_binding
Browse files Browse the repository at this point in the history
  • Loading branch information
csfldf committed Mar 5, 2024
1 parent 1f7e397 commit 4be86c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/qrm-plugins/commonstate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import "github.com/kubewharf/katalyst-core/pkg/util/general"
// 2. applied by QRM framework according to ociPropertyName
//
// there may be new types of control knobs,
// we won't modified this struct to identify them,
// we won't modify this struct to identify them,
// and we will register custom per-control-knob executor to deal with them.
type ControlKnobInfo struct {
ControlKnobValue string `json:"control_knob_value"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func (p *DynamicPolicy) sharedCoresAllocationHandler(ctx context.Context,
return nil, fmt.Errorf("sharedCoresAllocationHandler got nil request")
}

return p.allocateNUMAsWithoutNUMABindingPods(ctx, req, apiconsts.PodAnnotationQoSLevelSharedCores)
switch req.Annotations[apiconsts.PodAnnotationMemoryEnhancementNumaBinding] {
case apiconsts.PodAnnotationMemoryEnhancementNumaBindingEnable:
return p.numaBindingAllocationHandler(ctx, req, apiconsts.PodAnnotationQoSLevelSharedCores)
default:
return p.allocateNUMAsWithoutNUMABindingPods(ctx, req, apiconsts.PodAnnotationQoSLevelSharedCores)
}

}

func (p *DynamicPolicy) reclaimedCoresAllocationHandler(ctx context.Context,
Expand All @@ -64,16 +70,16 @@ func (p *DynamicPolicy) dedicatedCoresAllocationHandler(ctx context.Context,

switch req.Annotations[apiconsts.PodAnnotationMemoryEnhancementNumaBinding] {
case apiconsts.PodAnnotationMemoryEnhancementNumaBindingEnable:
return p.dedicatedCoresWithNUMABindingAllocationHandler(ctx, req)
return p.numaBindingAllocationHandler(ctx, req, apiconsts.PodAnnotationQoSLevelDedicatedCores)
default:
return p.dedicatedCoresWithoutNUMABindingAllocationHandler(ctx, req)
}
}

func (p *DynamicPolicy) dedicatedCoresWithNUMABindingAllocationHandler(ctx context.Context,
req *pluginapi.ResourceRequest) (*pluginapi.ResourceAllocationResponse, error) {
func (p *DynamicPolicy) numaBindingAllocationHandler(ctx context.Context,
req *pluginapi.ResourceRequest, qosLevel string) (*pluginapi.ResourceAllocationResponse, error) {
if req.ContainerType == pluginapi.ContainerType_SIDECAR {
return p.dedicatedCoresWithNUMABindingAllocationSidecarHandler(ctx, req)
return p.numaBindingAllocationSidecarHandler(ctx, req, qosLevel)
}

reqInt, _, err := util.GetQuantityFromResourceReq(req)
Expand Down Expand Up @@ -170,7 +176,7 @@ func (p *DynamicPolicy) dedicatedCoresWithNUMABindingAllocationHandler(ctx conte
TopologyAwareAllocations: topologyAwareAllocations,
Labels: general.DeepCopyMap(req.Labels),
Annotations: general.DeepCopyMap(req.Annotations),
QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores,
QoSLevel: qosLevel,
}
p.state.SetAllocationInfo(v1.ResourceMemory, req.PodUid, req.ContainerName, allocationInfo)

Expand Down Expand Up @@ -203,10 +209,10 @@ func (p *DynamicPolicy) dedicatedCoresWithoutNUMABindingAllocationHandler(_ cont
return nil, fmt.Errorf("not support dedicated_cores without NUMA binding")
}

// dedicatedCoresWithNUMABindingAllocationSidecarHandler allocates for sidecar
// numaBindingAllocationSidecarHandler allocates for sidecar
// currently, we set cpuset of sidecar to the cpuset of its main container
func (p *DynamicPolicy) dedicatedCoresWithNUMABindingAllocationSidecarHandler(_ context.Context,
req *pluginapi.ResourceRequest) (*pluginapi.ResourceAllocationResponse, error) {
func (p *DynamicPolicy) numaBindingAllocationSidecarHandler(_ context.Context,
req *pluginapi.ResourceRequest, qosLevel string) (*pluginapi.ResourceAllocationResponse, error) {
podResourceEntries := p.state.GetPodResourceEntries()

podEntries := podResourceEntries[v1.ResourceMemory]
Expand Down Expand Up @@ -238,7 +244,7 @@ func (p *DynamicPolicy) dedicatedCoresWithNUMABindingAllocationSidecarHandler(_
TopologyAwareAllocations: nil, // not count sidecar quantity
Labels: general.DeepCopyMap(req.Labels),
Annotations: general.DeepCopyMap(req.Annotations),
QoSLevel: apiconsts.PodAnnotationQoSLevelDedicatedCores,
QoSLevel: qosLevel,
}

// update pod entries directly. if one of subsequent steps is failed,
Expand Down
18 changes: 11 additions & 7 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/policy_hint_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ import (
qosutil "github.com/kubewharf/katalyst-core/pkg/util/qos"
)

func (p *DynamicPolicy) sharedCoresHintHandler(_ context.Context,
func (p *DynamicPolicy) sharedCoresHintHandler(ctx context.Context,
req *pluginapi.ResourceRequest) (*pluginapi.ResourceHintsResponse, error) {
if req == nil {
return nil, fmt.Errorf("got nil request")
}

return util.PackResourceHintsResponse(req, string(v1.ResourceMemory),
map[string]*pluginapi.ListOfTopologyHints{
string(v1.ResourceMemory): nil, // indicates that there is no numa preference
})
if !qosutil.AnnotationsIndicateNUMABinding(req.Annotations) {
return util.PackResourceHintsResponse(req, string(v1.ResourceMemory),
map[string]*pluginapi.ListOfTopologyHints{
string(v1.ResourceMemory): nil, // indicates that there is no numa preference
})
}

return p.numaBindingHintHandler(ctx, req)
}

func (p *DynamicPolicy) reclaimedCoresHintHandler(ctx context.Context,
Expand All @@ -58,13 +62,13 @@ func (p *DynamicPolicy) dedicatedCoresHintHandler(ctx context.Context,

switch req.Annotations[apiconsts.PodAnnotationMemoryEnhancementNumaBinding] {
case apiconsts.PodAnnotationMemoryEnhancementNumaBindingEnable:
return p.dedicatedCoresWithNUMABindingHintHandler(ctx, req)
return p.numaBindingHintHandler(ctx, req)
default:
return p.dedicatedCoresWithoutNUMABindingHintHandler(ctx, req)
}
}

func (p *DynamicPolicy) dedicatedCoresWithNUMABindingHintHandler(_ context.Context,
func (p *DynamicPolicy) numaBindingHintHandler(_ context.Context,
req *pluginapi.ResourceRequest) (*pluginapi.ResourceHintsResponse, error) {
// currently, we set cpuset of sidecar to the cpuset of its main container,
// so there is no numa preference here.
Expand Down
7 changes: 3 additions & 4 deletions pkg/agent/qrm-plugins/memory/dynamicpolicy/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ func (ai *AllocationInfo) Clone() *AllocationInfo {
return clone
}

// CheckNumaBinding returns true if the AllocationInfo is for pod with
// dedicated-qos and numa-binding enhancement
// CheckNumaBinding returns true if the AllocationInfo is for pod with numa-binding enhancement
func (ai *AllocationInfo) CheckNumaBinding() bool {
return ai.QoSLevel == consts.PodAnnotationQoSLevelDedicatedCores &&
ai.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] == consts.PodAnnotationMemoryEnhancementNumaBindingEnable
return ai.Annotations[consts.PodAnnotationMemoryEnhancementNumaBinding] ==
consts.PodAnnotationMemoryEnhancementNumaBindingEnable
}

// CheckMainContainer returns true if the AllocationInfo is for main container
Expand Down

0 comments on commit 4be86c6

Please sign in to comment.