{"record":{"id":"6fb15bea50abb5ac","repo":"hashicorp/nomad","slug":"failed-to-set-subtree-control-on-cpuset-share-part","errorCode":null,"errorMessage":"failed to set subtree control on cpuset share partition: %w","messagePattern":"failed to set subtree control on cpuset share partition: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/lib/cgroupslib/init.go","lineNumber":172,"sourceCode":"\t\t\treturn fmt.Errorf(\"failed to set subtree control on nomad cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(cores, NomadCgroupParent, cpusetFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write root partition cpuset: %w\", err)\n\t\t}\n\n\t\tlog.Debug(\"top level partition root nomad.slice cgroup initialized\")\n\n\t\t//\n\t\t// configuring nomad.slice/share (member)\n\t\t//\n\n\t\tif err := mkCG(NomadCgroupParent, SharePartition()); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create share cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(activation, NomadCgroupParent, SharePartition(), subtreeFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set subtree control on cpuset share partition: %w\", err)\n\t\t}\n\n\t\tlog.Debug(\"partition member nomad.slice/share cgroup initialized\")\n\n\t\t//\n\t\t// configuring nomad.slice/reserve (member)\n\t\t//\n\n\t\tif err := mkCG(NomadCgroupParent, ReservePartition()); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create share cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(activation, NomadCgroupParent, ReservePartition(), subtreeFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set subtree control on cpuset reserve partition: %w\", err)\n\t\t}\n\n\t\tlog.Debug(\"partition member nomad.slice/reserve cgroup initialized\")\n\t}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/lib/cgroupslib/init.go#L154-L190","documentation":"After creating nomad.slice/share, Init() writes the controller activation list to its cgroup.subtree_control so task-level child cgroups under share can use the controllers. A write failure here leaves the share partition non-functional for spawning task cgroups.","triggerScenarios":"writeCG(activation, NomadCgroupParent, SharePartition(), subtreeFile) fails — EACCES on the file, EBUSY because processes already exist inside nomad.slice/share making controller re-enable fail, or a requested controller is not available.","commonSituations":"Stale nomad.slice/share from a previous Nomad run still containing running processes; agent without cgroup write privileges; host kernel missing a controller Nomad tries to activate (e.g. no memory controller in cgroup.controllers).","solutions":["Stop tasks/Nomad, verify nomad.slice/share/cgroup.procs is empty, then retry Init (EBUSY only occurs with active processes).","Run with sufficient privileges or systemd Delegate=yes so subtree_control is writable.","Check /sys/fs/cgroup/cgroup.controllers contains the controllers Nomad needs; upgrade kernel or adjust config if missing.","Boot with required cgroup controllers enabled (cgroup_no_v1 / systemd unified hierarchy for v2)."],"exampleFix":"# before: stale processes block subtree_control\n$ cat /sys/fs/cgroup/nomad.slice/share/cgroup.procs\n1234\n// after: drain and clear the cgroup first\n$ sudo systemctl stop nomad && kill 1234; sudo systemctl start nomad","handlingStrategy":"retry","validationCode":"func shareIsEmpty(shareDir string) (bool, error) {\n  b, err := os.ReadFile(filepath.Join(shareDir, \"cgroup.procs\"))\n  if err != nil { return false, err }\n  return len(strings.TrimSpace(string(b))) == 0, nil\n}","typeGuard":"func subtreeWritable(dir string) bool {\n  return syscall.Access(filepath.Join(dir, \"cgroup.subtree_control\"), syscall.W_OK) == nil\n}","tryCatchPattern":"if err := cgroupslib.Init(logger, cores); err != nil {\n  if strings.Contains(err.Error(), \"subtree control on cpuset share\") {\n    // EBUSY: drain tasks under nomad.slice/share, then retry once\n    return retryAfterDrain(err)\n  }\n  return err\n}","preventionTips":["Drain/stop all tasks before restarting the Nomad client so share cgroup procs are empty.","Verify required controllers exist in /sys/fs/cgroup/cgroup.controllers.","Grant cgroup delegation so subtree_control is writable.","Do not manually enable/disable controllers in nomad.slice/share out-of-band."],"tags":["linux","cgroups","cgroupv2","subtree-control"],"backgroundTag":"cgroup-write-permission-denied","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}