Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 4823147

Browse files
authored
Merge pull request #398 from joshwget/mem-swappiness
Add mem_swappiness
2 parents a348354 + 7c5bc9d commit 4823147

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

config/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type ServiceConfigV1 struct {
4545
MacAddress string `yaml:"mac_address,omitempty"`
4646
MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"`
4747
MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"`
48+
MemSwappiness yaml.StringorInt `yaml:"mem_swappiness,omitempty"`
4849
Name string `yaml:"name,omitempty"`
4950
Net string `yaml:"net,omitempty"`
5051
OomScoreAdj yaml.StringorInt `yaml:"oom_score_adj,omitempty"`
@@ -112,6 +113,7 @@ type ServiceConfig struct {
112113
MacAddress string `yaml:"mac_address,omitempty"`
113114
MemLimit yaml.StringorInt `yaml:"mem_limit,omitempty"`
114115
MemSwapLimit yaml.StringorInt `yaml:"memswap_limit,omitempty"`
116+
MemSwappiness yaml.StringorInt `yaml:"mem_swappiness,omitempty"`
115117
NetworkMode string `yaml:"network_mode,omitempty"`
116118
Networks *yaml.Networks `yaml:"networks,omitempty"`
117119
OomScoreAdj yaml.StringorInt `yaml:"oom_score_adj,omitempty"`

docker/service/convert.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,18 @@ func Convert(c *config.ServiceConfig, ctx project.Context, clientFactory compose
181181
}
182182
}
183183

184+
memorySwappiness := int64(c.MemSwappiness)
185+
184186
resources := container.Resources{
185-
CgroupParent: c.CgroupParent,
186-
Memory: int64(c.MemLimit),
187-
MemorySwap: int64(c.MemSwapLimit),
188-
CPUShares: int64(c.CPUShares),
189-
CPUQuota: int64(c.CPUQuota),
190-
CpusetCpus: c.CPUSet,
191-
Ulimits: ulimits,
192-
Devices: deviceMappings,
187+
CgroupParent: c.CgroupParent,
188+
Memory: int64(c.MemLimit),
189+
MemorySwap: int64(c.MemSwapLimit),
190+
MemorySwappiness: &memorySwappiness,
191+
CPUShares: int64(c.CPUShares),
192+
CPUQuota: int64(c.CPUQuota),
193+
CpusetCpus: c.CPUSet,
194+
Ulimits: ulimits,
195+
Devices: deviceMappings,
193196
}
194197

195198
networkMode := c.NetworkMode

docker/service/convert_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ func TestGroupAdd(t *testing.T) {
9898
}, hostCfg.GroupAdd))
9999
}
100100

101+
func TestMemSwappiness(t *testing.T) {
102+
ctx := &ctx.Context{}
103+
sc := &config.ServiceConfig{
104+
MemSwappiness: yaml.StringorInt(10),
105+
}
106+
_, hostCfg, err := Convert(sc, ctx.Context, nil)
107+
assert.Nil(t, err)
108+
109+
assert.Equal(t, int64(10), *hostCfg.MemorySwappiness)
110+
}
111+
101112
func TestOomScoreAdj(t *testing.T) {
102113
ctx := &ctx.Context{}
103114
sc := &config.ServiceConfig{

0 commit comments

Comments
 (0)