Skip to content

Commit e3b6399

Browse files
Add cpuset_mems to docker driver.
Signed-off-by: Shishir Mahajan <smahajan@roblox.com>
1 parent a4254f9 commit e3b6399

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

drivers/docker/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ var (
341341
"cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false),
342342
"command": hclspec.NewAttr("command", "string", false),
343343
"cpuset_cpus": hclspec.NewAttr("cpuset_cpus", "string", false),
344+
"cpuset_mems": hclspec.NewAttr("cpuset_mems", "string", false),
344345
"cpu_hard_limit": hclspec.NewAttr("cpu_hard_limit", "bool", false),
345346
"cpu_cfs_period": hclspec.NewDefault(
346347
hclspec.NewAttr("cpu_cfs_period", "number", false),
@@ -433,6 +434,7 @@ type TaskConfig struct {
433434
CPUCFSPeriod int64 `codec:"cpu_cfs_period"`
434435
CPUHardLimit bool `codec:"cpu_hard_limit"`
435436
CPUSetCPUs string `codec:"cpuset_cpus"`
437+
CPUSetMEMs string `codec:"cpuset_mems"`
436438
Devices []DockerDevice `codec:"devices"`
437439
DNSSearchDomains []string `codec:"dns_search_domains"`
438440
DNSOptions []string `codec:"dns_options"`

drivers/docker/driver.go

+7
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,13 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
888888
hostConfig.CPUSetCPUs = driverConfig.CPUSetCPUs
889889
}
890890

891+
// This translates to docker create/run --cpuset-mems option.
892+
// --cpuset-mems is the list of memory nodes on which processes
893+
// in this cpuset are allowed to allocate memory.
894+
if driverConfig.CPUSetMEMs != "" {
895+
hostConfig.CPUSetMEMs = driverConfig.CPUSetMEMs
896+
}
897+
891898
// Enable tini (docker-init) init system.
892899
if driverConfig.Init {
893900
hostConfig.Init = driverConfig.Init

drivers/docker/driver_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,28 @@ func TestDockerDriver_CPUSetCPUs(t *testing.T) {
15531553
}
15541554
}
15551555

1556+
func TestDockerDriver_CPUSetMEMs(t *testing.T) {
1557+
ci.Parallel(t)
1558+
testutil.DockerCompatible(t)
1559+
if runtime.GOOS == "windows" {
1560+
t.Skip("Windows does not support cpuset_mems")
1561+
}
1562+
1563+
task, cfg, _ := dockerTask(t)
1564+
1565+
cfg.CPUSetMEMs = "0"
1566+
require.NoError(t, task.EncodeConcreteDriverConfig(cfg))
1567+
1568+
client, d, handle, cleanup := dockerSetup(t, task, nil)
1569+
defer cleanup()
1570+
require.NoError(t, d.WaitUntilStarted(task.ID, 5*time.Second))
1571+
1572+
container, err := client.InspectContainer(handle.containerID)
1573+
require.NoError(t, err)
1574+
1575+
require.Equal(t, cfg.CPUSetMEMs, container.HostConfig.CPUSetMEMs)
1576+
}
1577+
15561578
func TestDockerDriver_MemoryHardLimit(t *testing.T) {
15571579
ci.Parallel(t)
15581580
testutil.DockerCompatible(t)

website/content/docs/drivers/docker.mdx

+17-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The `docker` driver supports the following configuration in the job spec. Only
8484
}
8585
```
8686

87-
- `cpuset_cpus` <sup>Beta</sup> - (Optional) CPUs in which to allow execution
87+
- `cpuset_cpus` - (Optional) CPUs in which to allow execution
8888
(0-3, 0,1). Limit the specific CPUs or cores a container can use. A
8989
comma-separated list or hyphen-separated range of CPUs a container can use, if
9090
you have more than one CPU. The first CPU is numbered 0. A valid value might
@@ -100,6 +100,22 @@ config {
100100
}
101101
```
102102

103+
- `cpuset_mems` - (Optional) MEMs in which to allow execution
104+
(0-3, 0,1). Limit the specific memory nodes a container process is allowed
105+
to allocate memory. A comma-separated list or hyphen-separated range of memory
106+
nodes a container can use, if you have more than one memory node. The first
107+
memory node is numbered 0. A valid value might be 0-3 (to use the first, second,
108+
third, and fourth memory node) or 1,3 (to use the second and fourth memory node).
109+
110+
Note: `cpuset_mems` pins the workload to the memory nodes but doesn't give the workload
111+
exclusive access to those memory nodes.
112+
113+
```hcl
114+
config {
115+
cpuset_mems = "0-3"
116+
}
117+
```
118+
103119
- `dns_search_domains` - (Optional) A list of DNS search domains for
104120
the container to use. If you are using bridge networking mode with a
105121
`network` block in the task group, you must set all DNS options in

0 commit comments

Comments
 (0)