Skip to content

Commit

Permalink
wip: more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Nov 7, 2023
1 parent cf07b22 commit c7ccafc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hack/resources.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ job "resources" {
driver = "pledge"
config {
command = "/bin/cat"
args = ["/sys/fs/cgroup/nomad.slice/${NOMAD_ALLOC_ID}.${NOMAD_TASK_NAME}.scope/cpu.max"]
args = ["/sys/fs/cgroup/nomad.slice/reserve.slice/${NOMAD_ALLOC_ID}.${NOMAD_TASK_NAME}.scope/cpu.max"]
promises = "stdio rpath"
unveil = ["r:/sys/fs/cgroup/nomad.slice"]
}
Expand Down
22 changes: 9 additions & 13 deletions pkg/plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ func (p *PledgeDriver) StartTask(config *drivers.TaskConfig) (*drivers.TaskHandl
return nil, nil, fmt.Errorf("failed to compute cpu bandwidth: %w", err)
}

cores := config.Resources.NomadResources.Cpu.ReservedCores
p.logger.Trace("resources", "memory", memory, "memory_max", memoryMax, "bandwidth", bandwidth, "cores", cores)
cpuset := config.Resources.LinuxResources.CpusetCpus
p.logger.Trace("resources", "memory", memory, "memory_max", memoryMax, "compute", bandwidth, "cpuset", cpuset)

// with cgroups v2 this is just the task cgroup
cgroup := config.Resources.LinuxResources.CpusetCgroupPath

// create the environment for pledge
env := &pledge.Environment{
Expand All @@ -289,7 +292,7 @@ func (p *PledgeDriver) StartTask(config *drivers.TaskConfig) (*drivers.TaskHandl
Env: config.Env,
Dir: config.TaskDir().Dir,
User: config.User,
Cgroup: p.cgroup(config.AllocID, config.Name, cores),
Cgroup: cgroup,
Net: netns(config),
Memory: memory,
MemoryMax: memoryMax,
Expand Down Expand Up @@ -353,8 +356,8 @@ func (p *PledgeDriver) RecoverTask(handle *drivers.TaskHandle) error {

taskState.TaskConfig = handle.Config.Copy()

// cores reserved if any
cores := taskState.TaskConfig.Resources.NomadResources.Cpu.ReservedCores
// with cgroups v2 this is just the task cgroup
cgroup := taskState.TaskConfig.Resources.LinuxResources.CpusetCgroupPath

// re-create the environment for pledge
env := &pledge.Environment{
Expand All @@ -363,7 +366,7 @@ func (p *PledgeDriver) RecoverTask(handle *drivers.TaskHandle) error {
Env: handle.Config.Env,
Dir: handle.Config.TaskDir().Dir,
User: handle.Config.User,
Cgroup: p.cgroup(handle.Config.AllocID, handle.Config.Name, cores),
Cgroup: cgroup,
}

runner := pledge.Recover(taskState.PID, env)
Expand Down Expand Up @@ -518,10 +521,3 @@ func (p *PledgeDriver) ExecTask(taskID string, cmd []string, timeout time.Durati
// todo
return nil, fmt.Errorf("ExecTask not implemented")
}

func (*PledgeDriver) cgroup(allocID, task string, cores []uint16) string {
if len(cores) == 0 {
return fmt.Sprintf("/sys/fs/cgroup/nomad.slice/share.slice/%s.%s.scope", allocID, task)
}
return fmt.Sprintf("/sys/fs/cgroup/nomad.slice/reserve.slice/%s.%s.scope", allocID, task)
}

0 comments on commit c7ccafc

Please sign in to comment.