Skip to content

Commit f96de14

Browse files
committed
libctr: Reset the inherited cpu affinity
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>
1 parent 1614cab commit f96de14

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libcontainer/process_linux.go

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"runtime"
1313
"strconv"
14+
"syscall"
1415
"time"
1516

1617
"github.com/opencontainers/runc/libcontainer/cgroups"
@@ -144,6 +145,14 @@ func (p *setnsProcess) start() (retErr error) {
144145
}
145146
}
146147
}
148+
// Reset the inherited cpu affinity. Old kernels do that automatically, but
149+
// new kernels remember the affinity that was set before the cgroup move.
150+
// This is undesirable, because it inherits the systemd affinity when the container
151+
// should really move to the container space cpus.
152+
if err = unix.SchedSetaffinity(p.pid(), nil); err != nil && !errors.Is(err, syscall.EINVAL) && !errors.Is(err, syscall.ENODEV) {
153+
return fmt.Errorf("error resetting pid %d affinity: %w", p.pid(), err)
154+
}
155+
147156
if p.intelRdtPath != "" {
148157
// if Intel RDT "resource control" filesystem path exists
149158
_, err := os.Stat(p.intelRdtPath)

0 commit comments

Comments
 (0)