Files
nomad/client/lib/proclib/wrangler_cg2_linux.go
Seth Hoenig 2e1974a574 client: refactor cpuset partitioning (#18371)
* client: refactor cpuset partitioning

This PR updates the way Nomad client manages the split between tasks
that make use of resources.cpus vs. resources.cores.

Previously, each task was explicitly assigned which CPU cores they were
able to run on. Every time a task was started or destroyed, all other
tasks' cpusets would need to be updated. This was inefficient and would
crush the Linux kernel when a client would try to run ~400 or so tasks.

Now, we make use of cgroup heirarchy and cpuset inheritence to efficiently
manage cpusets.

* cr: tweaks for feedback
2023-09-12 09:11:11 -05:00

49 lines
1.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build linux
package proclib
import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/lib/cgroupslib"
)
// LinuxWranglerCG2 is an implementation of ProcessWrangler that leverages
// cgroups v2 on modern Linux systems.
//
// e.g. Ubuntu 22.04 / RHEL 9 and later versions.
type LinuxWranglerCG2 struct {
task Task
log hclog.Logger
cg cgroupslib.Lifecycle
}
func newCG2(c *Configs) create {
logger := c.Logger.Named("cg2")
cgroupslib.Init(logger, c.UsableCores.String())
return func(task Task) ProcessWrangler {
return &LinuxWranglerCG2{
task: task,
log: c.Logger,
cg: cgroupslib.Factory(task.AllocID, task.Task, task.Cores),
}
}
}
func (w LinuxWranglerCG2) Initialize() error {
w.log.Trace("initialize cgroup", "task", w.task)
return w.cg.Setup()
}
func (w *LinuxWranglerCG2) Kill() error {
w.log.Trace("force kill processes in cgroup", "task", w.task)
return w.cg.Kill()
}
func (w *LinuxWranglerCG2) Cleanup() error {
w.log.Trace("remove cgroup", "task", w.task)
return w.cg.Teardown()
}