Skip to content
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

runc exec: implement CPU affinity #4327

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

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 2 times, most recently from 02dc5e9 to 6cfd75f Compare January 9, 2025 02:46
This is to include
 - opencontainers/runtime-spec#1261
 - opencontainers/runtime-spec#1253

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the exec-cpu-aff branch 7 times, most recently from d94301d to 80643c5 Compare January 15, 2025 21:01
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>
@kolyshkin kolyshkin changed the title [testing] runc exec: implement CPU affinity Jan 16, 2025
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
1 participant