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

client: ensure minimal cgroup controllers enabled #15027

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/15027.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a bug where Nomad could not detect cores on recent RHEL systems
```
30 changes: 28 additions & 2 deletions client/lib/cgutil/cpuset_manager_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-set"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/lib/cpuset"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -54,16 +55,21 @@ type cpusetManagerV2 struct {
}

func NewCpusetManagerV2(parent string, reservable []uint16, logger hclog.Logger) CpusetManager {
if err := minimumRootControllers(); err != nil {
logger.Error("failed to enabled minimum set of cgroup controllers; disable cpuset management", "error", err)
return new(NoopCpusetManager)
}

parentAbs := filepath.Join(CgroupRoot, parent)
if err := os.MkdirAll(parentAbs, 0o755); err != nil {
logger.Warn("failed to ensure nomad parent cgroup exists; disable cpuset management", "error", err)
logger.Error("failed to ensure nomad parent cgroup exists; disable cpuset management", "error", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change these log entries to say "disabling cpuset management"? "disable" sounds like we're telling the cluster administrator to do it.

return new(NoopCpusetManager)
}

if len(reservable) == 0 {
// read from group
if cpus, err := GetCPUsFromCgroup(parent); err != nil {
logger.Warn("failed to lookup cpus from parent cgroup; disable cpuset management", "error", err)
logger.Error("failed to lookup cpus from parent cgroup; disable cpuset management", "error", err)
return new(NoopCpusetManager)
} else {
reservable = cpus
Expand All @@ -80,6 +86,26 @@ func NewCpusetManagerV2(parent string, reservable []uint16, logger hclog.Logger)
}
}

// minimumControllers sets the minimum set of required controllers on the
// /sys/fs/cgroup/cgroup.subtree_control file - ensuring [cpuset, cpu, io, memory, pids]
// are enabled.
func minimumRootControllers() error {
e := new(editor)
s, err := e.read("cgroup.subtree_control")
if err != nil {
return err
}
required := set.From[string]([]string{"cpuset", "cpu", "io", "memory", "pids"})
enabled := set.From[string](strings.Fields(s))
needed := required.Difference(enabled)
sb := new(strings.Builder)
for _, controller := range needed.List() {
sb.WriteString("+" + controller + " ")
tgross marked this conversation as resolved.
Show resolved Hide resolved
}
activation := sb.String()
return e.write("cgroup.subtree_control", activation)
}

func (c *cpusetManagerV2) Init() {
c.logger.Debug("initializing with", "cores", c.initial)
}
Expand Down