{"record":{"id":"2e9ffdd14415cc1e","repo":"hashicorp/nomad","slug":"invalid-value-for-cpu-cfs-period","errorCode":null,"errorMessage":"invalid value for cpu_cfs_period","messagePattern":"invalid value for cpu_cfs_period","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1163,"sourceCode":"\t// Setting cpuset_cpus in driver config is no longer supported (it has\n\t// not worked correctly since Nomad 0.12)\n\tif driverConfig.CPUSetCPUs != \"\" {\n\t\td.logger.Warn(\"cpuset_cpus is no longer supported\")\n\t}\n\n\t// Enable tini (docker-init) init system.\n\tif driverConfig.Init {\n\t\thostConfig.Init = &driverConfig.Init\n\t}\n\n\t// Calculate CPU Quota\n\t// cfs_quota_us is the time per core, so we must\n\t// multiply the time by the number of cores available\n\t// See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu\n\tif driverConfig.CPUHardLimit {\n\t\tnumCores := runtime.NumCPU()\n\t\tif driverConfig.CPUCFSPeriod < 0 || driverConfig.CPUCFSPeriod > 1000000 {\n\t\t\treturn c, fmt.Errorf(\"invalid value for cpu_cfs_period\")\n\t\t}\n\t\tif driverConfig.CPUCFSPeriod == 0 {\n\t\t\tdriverConfig.CPUCFSPeriod = task.Resources.LinuxResources.CPUPeriod\n\t\t}\n\t\thostConfig.CPUPeriod = driverConfig.CPUCFSPeriod\n\t\thostConfig.CPUQuota = int64(task.Resources.LinuxResources.PercentTicks*float64(driverConfig.CPUCFSPeriod)) * int64(numCores)\n\t}\n\n\t// Windows does not support MemorySwap/MemorySwappiness #2193\n\tif runtime.GOOS == \"windows\" {\n\t\thostConfig.MemorySwap = 0\n\t\thostConfig.MemorySwappiness = nil\n\t} else {\n\t\thostConfig.MemorySwap = memory\n\n\t\t// disable swap explicitly in non-Windows environments\n\t\tif cgroupslib.MaybeDisableMemorySwappiness() != nil {\n\t\t\thostConfig.MemorySwappiness = new(int64(*(cgroupslib.MaybeDisableMemorySwappiness())))","sourceCodeStart":1145,"sourceCodeEnd":1181,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1145-L1181","documentation":"Nomad's Docker driver validates the user-supplied cpu_cfs_period driver option when CPUHardLimit is enabled. The CFS period must be within 0..1000000 microseconds; a negative value or one above 1,000,000 is rejected before any Docker API call is made. Period 0 means 'use the scheduler-derived default' (task.Resources.LinuxResources.CPUPeriod).","triggerScenarios":"Starting a task with a docker driver config where cpu_cfs_period is set to a negative number or a value greater than 1000000 while cpu_hard_limit is true, via createContainerConfig called from StartTask.","commonSituations":"Copy-pasting a Docker daemon --cpu-cfs-period style value in nanoseconds instead of microseconds; typos like 10000000 (extra zero); tuning attempts that exceed the kernel CFS period max.","solutions":["Set cpu_cfs_period to a value between 1 and 1000000 (microseconds), e.g. 100000","Remove the cpu_cfs_period option entirely so 0 falls back to the task's LinuxResources.CPUPeriod default","If you only wanted quota control, keep the default period and only adjust the CPU amount"],"exampleFix":"// before\ndriver {\n  docker {}\n  cpu_hard_limit = true\n  cpu_cfs_period = 5000000\n}\n// after\ndriver {\n  docker {}\n  cpu_hard_limit = true\n  cpu_cfs_period = 100000\n}","handlingStrategy":"validation","validationCode":"if p := jobDriverCfg.CPUCFSPeriod; p < 0 || p > 1000000 {\n  return fmt.Errorf(\"cpu_cfs_period must be 0..1000000, got %d\", p)\n}","typeGuard":"func validCFSPeriod(p int64) bool { return p == 0 || (p > 0 && p <= 1000000) }","tryCatchPattern":"period, err := resolveCFSPeriod(cfg); if err != nil { return fmt.Errorf(\"invalid cpu_cfs_period: %w\", err) }","preventionTips":["Keep cpu_cfs_period between 1000 and 1000000 microseconds","Omit the option to use the scheduler default","Add a CI lint on driver config ranges"],"tags":["docker","nomad-driver","config-validation","cpu"],"backgroundTag":"invalid-config-value","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"}