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

libctr: Reset the inherited cpu affinity #4041

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ func (p *setnsProcess) start() (retErr error) {
}
}
}
// Reset the inherited cpu affinity. Old kernels do that automatically, but
// new kernels remember the affinity that was set before the cgroup move.
// This is undesirable, because it inherits the systemd affinity when the container
// should really move to the container space cpus.
if err := unix.SchedSetaffinity(p.pid(), &unix.CPUSet{}); err != nil && err != unix.EINVAL && err != unix.ENODEV {
return fmt.Errorf("error resetting pid %d affinity: %w", p.pid(), err)
}

if p.intelRdtPath != "" {
// if Intel RDT "resource control" filesystem path exists
_, err := os.Stat(p.intelRdtPath)
Expand Down Expand Up @@ -419,6 +427,14 @@ func (p *initProcess) start() (retErr error) {
if err := p.manager.Apply(p.pid()); err != nil {
return fmt.Errorf("unable to apply cgroup configuration: %w", err)
}

// Reset the inherited cpu affinity. Old kernels do that automatically, but
// new kernels remember the affinity that was set before the cgroup move.
// This is undesirable, because it inherits the systemd affinity when the container
// should really move to the container space cpus.
if err := unix.SchedSetaffinity(p.pid(), &unix.CPUSet{}); err != nil && err != unix.EINVAL && err != unix.ENODEV {
return fmt.Errorf("error resetting pid %d affinity: %w", p.pid(), err)
}
if p.intelRdtManager != nil {
if err := p.intelRdtManager.Apply(p.pid()); err != nil {
return fmt.Errorf("unable to apply Intel RDT configuration: %w", err)
Expand Down