Skip to content

runc exec: implement CPU affinity #4327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jun 27, 2024

Currently a draft until runtime-spec vNext is released.

As per

CPU affinity can be set in two ways:

  1. When creating/starting a container, in config.json's
    Process.ExecCPUAffinity, which is when applied to all execs.
  2. When running an exec, in process.json's CPUAffinity, which
    applied to a given exec and overrides the value from (1).

Add some basic tests.

Note that older kernels (RHEL8, Ubuntu 20.04) change CPU affinity of a
process to that of a container's cgroup, as soon as it is moved to that
cgroup, while newer kernels (Ubuntu 24.04, Fedora 41) don't do that.

Because of the above,

  • it's impossible to really test initial CPU affinity without adding
    debug logging to libcontainer/nsenter;
  • for older kernels, there can be a brief moment when exec's affinity
    is different than either initial or final affinity being set;
  • exec's final CPU affinity, if not specified, can be different
    depending on the kernel, therefore we don't test it.

Fixes: #3922

@kolyshkin kolyshkin force-pushed the exec-cpu-aff branch 9 times, most recently from d94301d to 80643c5 Compare January 15, 2025 21:01
@kolyshkin kolyshkin changed the title [testing] runc exec: implement CPU affinity Jan 16, 2025
@kolyshkin kolyshkin added this to the 1.3.0-rc.1 milestone Feb 14, 2025
@cyphar
Copy link
Member

cyphar commented Feb 27, 2025

https://github.com/opencontainers/runtime-spec/releases/tag/v1.2.1

@rata
Copy link
Member

rata commented Feb 28, 2025

The deadline we have to publish rc1 is today and this is in the milestone but in draft. @kolyshkin what do you want to do with this?

@cyphar
Copy link
Member

cyphar commented Feb 28, 2025

@rata I spoke to him earlier this week and he said that he'd like to keep it in -rc.1 if possible and that it's trivial to update this once runtime-spec 1.2.1 is released. I just released 1.2.1 of the runtime-spec so I guess he will work on this when he wakes up.

Personally I think we can safely move the deadline for -rc.1 to next week. If this isn't ready by then we can do the release without it.

@rata
Copy link
Member

rata commented Feb 28, 2025

@cyphar thanks! I'm fine cutting -rc.1 next week, I'm also fine cutting -rc.1 today and adding this just after -rc.1 (it's basically the same thing). But yeah, I wouldn't let rc.1 slip longer than next week.

@kolyshkin kolyshkin marked this pull request as ready for review February 28, 2025 19:34
@kolyshkin kolyshkin requested review from thaJeztah, cyphar and rata and removed request for thaJeztah and cyphar February 28, 2025 19:34
@kolyshkin
Copy link
Contributor Author

This is now ready for review

@kolyshkin
Copy link
Contributor Author

Removed runtime.UnlockOSThread(), added test for toCPUSet. PTAL @lifubang @cyphar @rata

@kolyshkin kolyshkin force-pushed the exec-cpu-aff branch 2 times, most recently from 43d1b00 to 25c05be Compare March 2, 2025 22:25
@kolyshkin kolyshkin requested review from lifubang and cyphar March 2, 2025 22:25
As per
- opencontainers/runtime-spec#1253
- opencontainers/runtime-spec#1261

CPU affinity can be set in two ways:
1. When creating/starting a container, in config.json's
   Process.ExecCPUAffinity, which is when applied to all execs.
2. When running an exec, in process.json's CPUAffinity, which
   applied to a given exec and overrides the value from (1).

Add some basic tests.

Note that older kernels (RHEL8, Ubuntu 20.04) change CPU affinity of a
process to that of a container's cgroup, as soon as it is moved to that
cgroup, while newer kernels (Ubuntu 24.04, Fedora 41) don't do that.

Because of the above,
 - it's impossible to really test initial CPU affinity without adding
   debug logging to libcontainer/nsenter;
 - for older kernels, there can be a brief moment when exec's affinity
   is different than either initial or final affinity being set;
 - exec's final CPU affinity, if not specified, can be different
   depending on the kernel, therefore we don't test it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@lifubang lifubang merged commit 0ebf331 into opencontainers:main Mar 3, 2025
34 checks passed
@rata
Copy link
Member

rata commented Mar 3, 2025

Is anyone working on the rc.1 PR? I can do it, otherwise

@lifubang
Copy link
Member

lifubang commented Mar 3, 2025

Is anyone working on the rc.1 PR? I can do it, otherwise

All tasks in 1.3.0-rc.1 are completed now, I think it's time to release v1.3.0-rc.1.

@rata
Copy link
Member

rata commented Mar 3, 2025

I'm working on the PR :)

@rata rata mentioned this pull request Mar 3, 2025
@@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
methods no longer ignore `Process.IOPriority` and `Process.Scheduler`
settings. (#4585)

### Added
* CPU affinity support for `runc exec`. (#4327)
Copy link
Member

Choose a reason for hiding this comment

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

Late to the party, but https://github.com/opencontainers/runc/blob/main/docs/spec-conformance.md had to be synced with the spec v1.2.1

Copy link
Member

Choose a reason for hiding this comment

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

Wanna make a PR so it's included in the next rc? :)

Copy link
Member

Choose a reason for hiding this comment

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

starlingx-github pushed a commit to starlingx/integ that referenced this pull request Apr 21, 2025
This change updates runc package from 1.1.12 to 1.3.0.rc2.

Note that this change packages release candidate (RC) of 1.3.0 and
not the final formal 1.3.0 release. A task is created to update this
to the final release version in the follow-up change. Formal release
is expected near the end of the month but to avoid delays in STX
release, we move ahead with this release binaries as we do not
expect major changes between formal release and this release.
Also, note that 1.3 is preferred over latest 1.2 patch release as
1.3 contains a desirable CPU affinity feature.
Ref: opencontainers/runc#4327

Test Plan:
PASS: AIO-SX fresh installs with k8s versions 1.29, 1.30, 1.31
      successful. System healthy. No alarms. Kubernetes cluster
      healthy.
PASS: AIO-SX kubernetes upgrade successful from 1.29 to 1.30.

Story: 2011413
Task: 51995

Change-Id: I661489342f2c3c7e562ef56bef4f03b67bda97db
Signed-off-by: Kaustubh Dhokte <kaustubh.dhokte@windriver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue joining cgroups cpuset with kernel scheduler task "random" distribution
5 participants