Skip to content

Commit 5aa229f

Browse files
committed
[1.4] libct: switch to (*CPUSet).Fill
Now that we've updated to golang.org/x/sys@v0.37.0, CPUSet has a Fill helper that does the equivalent to our underflow trick to make setting all CPUs efficient. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> (cherry picked from commit 93f9a39) Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 18fbdbe commit 5aa229f

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased 1.4.z]
88

9+
### Fixed
10+
* Switched to `(*CPUSet).Fill` rather than our hacky optimisation when
11+
resetting the CPU affinity of runc. (#4926, #4927)
12+
913
## [1.4.0-rc.2] - 2025-10-10
1014

1115
> 私の役目は信じるかどうかではない。行うかどうかだ。

libcontainer/process_linux.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,8 @@ func tryResetCPUAffinity(pid int) {
185185
//
186186
// So we can just pass a very large array of set cpumask bits and the
187187
// kernel will silently convert that to the correct value very cheaply.
188-
189-
// Ideally, we would just set the array to 0xFF...FF. Unfortunately, the
190-
// size depends on the architecture. It is also a private newtype, so we
191-
// can't use (^0) or generics since those require us to be able to name the
192-
// type. However, we can just underflow the zero value instead.
193-
// TODO: Once <https://golang.org/cl/698015> is merged, switch to that.
194-
cpuset := unix.CPUSet{}
195-
for i := range cpuset {
196-
cpuset[i]-- // underflow to 0xFF..FF
197-
}
188+
var cpuset unix.CPUSet
189+
cpuset.Fill() // set all bits
198190
if err := unix.SchedSetaffinity(pid, &cpuset); err != nil {
199191
logrus.WithError(
200192
os.NewSyscallError("sched_setaffinity", err),

0 commit comments

Comments
 (0)