{"record":{"id":"5aa19657c7d88795","repo":"hashicorp/nomad","slug":"memorymaxmb-value-d-should-be-larger-than-memor","errorCode":null,"errorMessage":"MemoryMaxMB value (%d) should be larger than MemoryMB value (%d)","messagePattern":"MemoryMaxMB value \\((.+?)\\) should be larger than MemoryMB value \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":2466,"sourceCode":"\n\t// Ensure each numa bound device matches a device requested for task\n\tif r.NUMA != nil {\n\t\tfor _, numaDevice := range r.NUMA.Devices {\n\t\t\tif !devices.Contains(numaDevice) {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"numa device %q not requested as task resource\", numaDevice))\n\t\t\t}\n\t\t}\n\t}\n\n\t// Ensure the numa block is valid\n\tif err := r.NUMA.Validate(); err != nil {\n\t\tmErr.Errors = append(mErr.Errors, err)\n\t}\n\n\t// Ensure memory_max is greater than memory, unless it is set to 0 or -1 which\n\t// are both sentinel values\n\tif (r.MemoryMaxMB != 0 && r.MemoryMaxMB != MemoryNoLimit) && r.MemoryMaxMB < r.MemoryMB {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"MemoryMaxMB value (%d) should be larger than MemoryMB value (%d)\", r.MemoryMaxMB, r.MemoryMB))\n\t}\n\n\tif r.SecretsMB > r.MemoryMB {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"SecretsMB value (%d) cannot be larger than MemoryMB value (%d)\", r.SecretsMB, r.MemoryMB))\n\t}\n\tif r.SecretsMB < 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"SecretsMB value (%d) cannot be negative\", r.SecretsMB))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// Merge merges this resource with another resource.\n// COMPAT(0.10): Remove in 0.10\nfunc (r *Resources) Merge(other *Resources) {\n\tif other.CPU != 0 {\n\t\tr.CPU = other.CPU\n\t}","sourceCodeStart":2448,"sourceCodeEnd":2484,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L2448-L2484","documentation":"Nomad's Resources.Validate() rejects a task resource block where memory_max (MemoryMaxMB) is set but lower than memory (MemoryMB). memory_max is a hard ceiling for memory and must be >= the soft limit; 0 (unset) and -1 (MemoryNoLimit sentinel) are allowed exceptions. This keeps resource specifications internally consistent so the scheduler and cgroup limits are sane.","triggerScenarios":"Submitting a job (nomad job run / API jobs POST) whose task Resources has MemoryMaxMB set to a positive value smaller than MemoryMB, e.g. memory = 512, memory_max = 256.","commonSituations":"Hand-writing HCL/JSON job files and swapping the two values; templating memory_max from a smaller variable; editing generated job specs after downsizing memory_max; copying specs where memory_max was tuned per-environment.","solutions":["Set MemoryMaxMB (memory_max) to a value greater than or equal to MemoryMB (memory)","Remove memory_max or set it to -1 to use the MemoryNoLimit sentinel (or 0 to leave unset)","Swap the values if you accidentally inverted memory and memory_max"],"exampleFix":"// before\nresources {\n  memory     = 512\n  memory_max = 256\n}\n// after\nresources {\n  memory     = 512\n  memory_max = 1024\n}","handlingStrategy":"validation","validationCode":"if r.MemoryMaxMB != 0 && r.MemoryMaxMB != MemoryNoLimit && r.MemoryMaxMB < r.MemoryMB {\n    return fmt.Errorf(\"memory_max (%d) must be >= memory (%d)\", r.MemoryMaxMB, r.MemoryMB)\n}","typeGuard":"func validMemoryMax(mem, memMax int) bool {\n    return memMax == 0 || memMax == MemoryNoLimit || memMax >= mem\n}","tryCatchPattern":null,"preventionTips":["Always set memory_max >= memory in templates","Default memory_max to -1 (no limit) unless you explicitly need a ceiling","Run nomad job validate in CI before submitting jobs"],"tags":["nomad","resources","validation","memory"],"backgroundTag":"resource-spec-validation","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}