Skip to content

Commit

Permalink
libctr: Reset the inherited cpu affinity
Browse files Browse the repository at this point in the history
Old kernels do that automatically, but new kernels remember
the affinity that was set before the cgroup move due to

https://lore.kernel.org/lkml/20220922180041.1768141-1-longman@redhat.com

This is undesirable for containers, because they inherit
the systemd affinity when the should really move to the container
space cpus.

Signed-off-by: Martin Sivak <msivak@redhat.com>
Signed-off-by: Peter Hunt <pehunt@redhat.com>
  • Loading branch information
haircommander committed Sep 28, 2023
1 parent 1614cab commit f96de14
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"syscall"
"time"

"github.com/opencontainers/runc/libcontainer/cgroups"
Expand Down Expand Up @@ -144,6 +145,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(), nil); err != nil && !errors.Is(err, syscall.EINVAL) && !errors.Is(err, syscall.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

0 comments on commit f96de14

Please sign in to comment.