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

docker: use correct effective cpuset filename on legacy cgroups v1 systems #20294

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20294.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
docker: Fixed a bug where cpuset cgroup would not be updated on cgroup v1 systems
```
14 changes: 12 additions & 2 deletions drivers/docker/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"time"

"github.com/hashicorp/nomad/client/lib/cgroupslib"
"github.com/hashicorp/nomad/helper"
)

Expand Down Expand Up @@ -49,8 +50,17 @@ func (c *cpuset) watch() {
}
}

func effectiveCpusetFile() string {
switch cgroupslib.GetMode() {
case cgroupslib.CG1:
return "cpuset.effective_cpus"
default:
return "cpuset.cpus.effective"
}
}

func (c *cpuset) copyCpuset(source, destination string) {
source = filepath.Join(source, "cpuset.cpus.effective")
source = filepath.Join(source, effectiveCpusetFile())
destination = filepath.Join(destination, "cpuset.cpus")

// read the current value of usable cores
Expand All @@ -67,7 +77,7 @@ func (c *cpuset) copyCpuset(source, destination string) {
}

// otherwise write the new value
err = os.WriteFile(destination, b, 0644)
err = os.WriteFile(destination, b, 0o644)
if err != nil {
return
}
Expand Down
19 changes: 19 additions & 0 deletions drivers/docker/cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/testutil"
"github.com/shoenig/test/must"
)

Expand Down Expand Up @@ -42,3 +43,21 @@ func Test_cpuset_watch(t *testing.T) {

must.Eq(t, 1, hits)
}

func Test_effectiveCpusetFile_cgroupsv1(t *testing.T) {
testutil.CgroupsCompatibleV1(t)

ci.Parallel(t)

result := effectiveCpusetFile()
must.Eq(t, "cpuset.effective_cpus", result)
}

func Test_effectiveCpusetFile_cgroupsv2(t *testing.T) {
testutil.CgroupsCompatibleV2(t)

ci.Parallel(t)

result := effectiveCpusetFile()
must.Eq(t, "cpuset.cpus.effective", result)
}
Loading