Skip to content

Fix/optimize Resolve the performance overhead of calling large clusters#54

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
AutuSnow:fix/optimize
Feb 27, 2026
Merged

Fix/optimize Resolve the performance overhead of calling large clusters#54
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
AutuSnow:fix/optimize

Conversation

@AutuSnow
Copy link
Copy Markdown
Contributor

@AutuSnow AutuSnow commented Feb 5, 2026

Resolve the performance overhead of calling large clusters

Note: RemoveResourceClaimAllocate() requires rebuilding the cache during deletion, with a complexity of O (n). This is because cpuset does not support efficient differencing operations (one claim may have allocated CPUs that overlap with other claims). However, due to relatively few deletion operations, and the use of Get Shared CPUs ()
Very frequent calls (called every time a container is created/deleted)

Fixes:#53

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @AutuSnow!

It looks like this is your first PR to kubernetes-sigs/dra-driver-cpu 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/dra-driver-cpu has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 5, 2026
@AutuSnow
Copy link
Copy Markdown
Contributor Author

AutuSnow commented Feb 5, 2026

/assign @ffromani

Copy link
Copy Markdown
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix, this was indeed one of our TODOs.
Please verify this change is covered by tests, and feel free to add more coverage if not.

I wonder, in general, if and how we can assess the performance gains/changes of PRs.

Comment thread pkg/driver/pod_store.go Outdated
configs map[types.UID]PodCPUAssignments
mu sync.RWMutex
configs map[types.UID]PodCPUAssignments
sharedCPUContainers map[types.UID]struct{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used as set, so it should be used a set (k8s.io/apimachinery/pkg/util/sets)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have completed the modifications and added benchmark tests

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 5, 2026
@AutuSnow
Copy link
Copy Markdown
Contributor Author

AutuSnow commented Feb 9, 2026

@ffromani Can I take another look

Copy link
Copy Markdown
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR and sorry it took me so long to review again. Except micro-benchmarks, I'm not sure about the actual gain when operating the plugins, but the code becomes IMO a bit nicer, so we should move forward and merge. Please rebase.

I'm inclined into accept into 0.1.0, pending final review

Comment thread pkg/driver/cpu_allocation_store.go Outdated
Comment on lines +70 to +73
s.allocatedCPUs = cpuset.New()
for _, cpus := range s.resourceClaimAllocations {
s.allocatedCPUs = s.allocatedCPUs.Union(cpus)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps use s.allocatedCPUs = s.allocatedCPUs.Difference(cpus) like you do below in GetSharedCPUs?

Comment thread pkg/store/pod_config.go
@@ -61,10 +64,23 @@ func (s *PodConfigStore) SetContainerState(podUID types.UID, state *ContainerSta
s.mu.Lock()
defer s.mu.Unlock()

// Check if there's an existing state for this container that we need to clean up from cache.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we just override? what's the risk here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we just override? what's the risk here?

When a container restarts, SetContainerState is called again with the same containerName but a new containerUID. If we just override without cleanup, the old containerUID would remain as a stale entry in the sharedCPUContainers set, causing GetContainersWithSharedCPUs() to return UIDs for containers that no longer exist. The cleanup ensures we remove the old UID before inserting the new one.

Copy link
Copy Markdown
Contributor

@ffromani ffromani Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fully makes sense. Please make sure we have a unit test which demonstrates this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fully makes sense. Please make sure we have a unit test which demonstrates this.

I will do it this way

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Feb 25, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: AutuSnow / name: Snow (2655227)

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 25, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 25, 2026
Copy link
Copy Markdown
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase when you resubmit

Comment thread pkg/store/pod_config.go
@@ -61,10 +64,23 @@ func (s *PodConfigStore) SetContainerState(podUID types.UID, state *ContainerSta
s.mu.Lock()
defer s.mu.Unlock()

// Check if there's an existing state for this container that we need to clean up from cache.
Copy link
Copy Markdown
Contributor

@ffromani ffromani Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fully makes sense. Please make sure we have a unit test which demonstrates this.

Comment on lines +67 to +70
// TODO: CoreID is only unique within a socket. On multi-socket systems where CoreIDs repeat
// across sockets, this method may return CPUs from multiple sockets for the same CoreID.
// Consider refactoring core-level methods to use CoreKey{SocketID, CoreID} for correct
// disambiguation, similar to CPUTopology.CPUsByCore.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, but this in inherited from cpumanager code. We need to decide if and how drift from cpumanager. It's a post-0.1.0 decision

Copy link
Copy Markdown
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

this is a TODO we had. The fix is nice, contained and was in review since long time. I'm doing an exception and merging before 0.1.0.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AutuSnow, ffromani

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 27, 2026
@k8s-ci-robot k8s-ci-robot merged commit c12dee2 into kubernetes-sigs:main Feb 27, 2026
2 checks passed
@AutuSnow AutuSnow deleted the fix/optimize branch February 27, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants