1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
7 const defaultSpread int64 = 10
9 // wantNice calculates appropriate nice values for a set of SLURM
10 // jobs. The returned slice will have len(jobs) elements.
12 // spread is a positive amount of space to leave between adjacent
13 // priorities when making adjustments. Generally, increasing spread
14 // reduces the total number of adjustments made. A smaller spread
15 // produces lower nice values, which is useful for old SLURM versions
16 // with a limited "nice" range and for sites where SLURM is also
17 // running non-Arvados jobs with low nice values.
19 // If spread<1, a sensible default (10) is used.
20 func wantNice(jobs []*slurmJob, spread int64) []int64 {
26 spread = defaultSpread
28 renice := make([]int64, len(jobs))
30 // highest usable priority (without going out of order)
32 for i, job := range jobs {
34 // renice[0] is always zero, so our highest
35 // priority container gets the highest
36 // possible slurm priority.
37 target = job.priority + job.nice
38 } else if space := target - job.priority; space >= 0 && space < (spread-1)*10 {
39 // Ordering is correct, and interval isn't too
40 // large. Leave existing nice value alone.
44 target -= (spread - 1)
45 if possible := job.priority + job.nice; target > possible {
46 // renice[i] is already 0, that's the
50 renice[i] = possible - target