-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers/raw_exec: enable configuring raw_exec task to have no memory …
…limit (#19670) * drivers/raw_exec: enable configuring raw_exec task to have no memory limit This PR makes it possible to configure a raw_exec task to not have an upper memory limit, which is how the driver would behave pre-1.7. This is done by setting memory_max = -1. The cluster (or node pool) must have memory oversubscription enabled. * cl: add cl
- Loading branch information
Showing
8 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
drivers: Enable configuring a raw_exec task to not have an upper memory limit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//go:build linux | ||
|
||
package executor | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/hashicorp/nomad/plugins/drivers" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
func Test_computeMemory(t *testing.T) { | ||
cases := []struct { | ||
memory int64 | ||
memoryMax int64 | ||
expSoft int64 | ||
expHard int64 | ||
}{ | ||
{ | ||
// typical case; only 'memory' is set and that is used as the hard | ||
// memory limit | ||
memory: 100, | ||
memoryMax: 0, | ||
expSoft: 0, | ||
expHard: mbToBytes(100), | ||
}, | ||
{ | ||
// oversub case; both 'memory' and 'memory_max' are set and used as | ||
// the soft and hard memory limits | ||
memory: 100, | ||
memoryMax: 200, | ||
expSoft: mbToBytes(100), | ||
expHard: mbToBytes(200), | ||
}, | ||
{ | ||
// special oversub case; 'memory' is set and 'memory_max' is set to | ||
// -1; which indicates there should be no hard limit (i.e. -1 / max) | ||
memory: 100, | ||
memoryMax: memoryNoLimit, | ||
expSoft: mbToBytes(100), | ||
expHard: memoryNoLimit, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
name := fmt.Sprintf("(%d,%d)", tc.memory, tc.memoryMax) | ||
t.Run(name, func(t *testing.T) { | ||
command := &ExecCommand{ | ||
Resources: &drivers.Resources{ | ||
NomadResources: &structs.AllocatedTaskResources{ | ||
Memory: structs.AllocatedMemoryResources{ | ||
MemoryMB: tc.memory, | ||
MemoryMaxMB: tc.memoryMax, | ||
}, | ||
}, | ||
}, | ||
} | ||
hard, soft := (*UniversalExecutor)(nil).computeMemory(command) | ||
must.Eq(t, tc.expSoft, soft) | ||
must.Eq(t, tc.expHard, hard) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
job "oversubmax" { | ||
type = "batch" | ||
|
||
constraint { | ||
attribute = "${attr.kernel.name}" | ||
value = "linux" | ||
} | ||
|
||
group "group" { | ||
reschedule { | ||
attempts = 0 | ||
unlimited = false | ||
} | ||
|
||
restart { | ||
attempts = 0 | ||
mode = "fail" | ||
} | ||
|
||
task "cat" { | ||
driver = "raw_exec" | ||
|
||
config { | ||
command = "bash" | ||
args = ["-c", "cat /sys/fs/cgroup/$(cat /proc/self/cgroup | cut -d':' -f3)/memory.{low,max}"] | ||
} | ||
|
||
resources { | ||
cpu = 100 | ||
memory = 64 | ||
memory_max = -1 # unlimited | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters