diff --git a/e2e/rawexec/input/oversub.hcl b/e2e/rawexec/input/oversub.hcl new file mode 100644 index 000000000..c5e26bb33 --- /dev/null +++ b/e2e/rawexec/input/oversub.hcl @@ -0,0 +1,38 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +job "oversub" { + 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.max"] + } + + resources { + cpu = 100 + memory = 64 + memory_max = 128 + } + } + } +} diff --git a/e2e/rawexec/rawexec_test.go b/e2e/rawexec/rawexec_test.go index 8907e797e..2b000d1c8 100644 --- a/e2e/rawexec/rawexec_test.go +++ b/e2e/rawexec/rawexec_test.go @@ -18,6 +18,7 @@ func TestRawExec(t *testing.T) { ) t.Run("testOomAdj", testOomAdj) + t.Run("testOversubMemory", testOversubMemory) } func testOomAdj(t *testing.T) { @@ -27,3 +28,11 @@ func testOomAdj(t *testing.T) { logs := job.TaskLogs("group", "cat") must.StrContains(t, logs.Stdout, "0") } + +func testOversubMemory(t *testing.T) { + job, cleanup := jobs3.Submit(t, "./input/oversub.hcl") + t.Cleanup(cleanup) + + logs := job.TaskLogs("group", "cat") + must.StrContains(t, logs.Stdout, "134217728") // 128 mb memory_max +} diff --git a/website/content/docs/job-specification/resources.mdx b/website/content/docs/job-specification/resources.mdx index e6fe58988..f3ac22533 100644 --- a/website/content/docs/job-specification/resources.mdx +++ b/website/content/docs/job-specification/resources.mdx @@ -116,8 +116,9 @@ mechanism for memory pressure is specific to the task driver, operating system, and application runtime. The `memory_max` limit attribute is currently supported by the official -`docker`, `exec`, and `java` task drivers. Consult the documentation of -community-supported task drivers for their memory oversubscription support. +`raw_exec`, `docker`, `exec`, and `java` task drivers. Consult the +documentation of community-supported task drivers for their memory +oversubscription support. Memory oversubscription is opt-in. Nomad operators can enable [Memory Oversubscription in the scheduler configuration][api_sched_config]. Enterprise