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

Commit 9aa966c

Browse files
authored
Merge pull request #431 from lox/support-memory-reservation
Support mem_reservation service property
2 parents f5739a7 + 221aecf commit 9aa966c

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

config/schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ var schemaDataV1 = `{
8686
"log_opt": {"type": "object"},
8787
"mac_address": {"type": "string"},
8888
"mem_limit": {"type": ["number", "string"]},
89+
"mem_reservation": {"type": ["number", "string"]},
8990
"memswap_limit": {"type": ["number", "string"]},
9091
"mem_swappiness": {"type": "integer"},
9192
"net": {"type": "string"},
@@ -298,6 +299,7 @@ var servicesSchemaDataV2 = `{
298299
299300
"mac_address": {"type": "string"},
300301
"mem_limit": {"type": ["number", "string"]},
302+
"mem_reservation": {"type": ["number", "string"]},
301303
"memswap_limit": {"type": ["number", "string"]},
302304
"mem_swappiness": {"type": "integer"},
303305
"network_mode": {"type": "string"},

config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type ServiceConfig struct {
117117
Logging Log `yaml:"logging,omitempty"`
118118
MacAddress string `yaml:"mac_address,omitempty"`
119119
MemLimit yaml.MemStringorInt `yaml:"mem_limit,omitempty"`
120+
MemReservation yaml.MemStringorInt `yaml:"mem_reservation,omitempty"`
120121
MemSwapLimit yaml.MemStringorInt `yaml:"memswap_limit,omitempty"`
121122
MemSwappiness yaml.MemStringorInt `yaml:"mem_swappiness,omitempty"`
122123
NetworkMode string `yaml:"network_mode,omitempty"`

docker/service/convert.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,17 @@ func Convert(c *config.ServiceConfig, ctx project.Context, clientFactory compose
182182
memorySwappiness := int64(c.MemSwappiness)
183183

184184
resources := container.Resources{
185-
CgroupParent: c.CgroupParent,
186-
Memory: int64(c.MemLimit),
187-
MemorySwap: int64(c.MemSwapLimit),
188-
MemorySwappiness: &memorySwappiness,
189-
CPUShares: int64(c.CPUShares),
190-
CPUQuota: int64(c.CPUQuota),
191-
CpusetCpus: c.CPUSet,
192-
Ulimits: ulimits,
193-
Devices: deviceMappings,
194-
OomKillDisable: &c.OomKillDisable,
185+
CgroupParent: c.CgroupParent,
186+
Memory: int64(c.MemLimit),
187+
MemoryReservation: int64(c.MemReservation),
188+
MemorySwap: int64(c.MemSwapLimit),
189+
MemorySwappiness: &memorySwappiness,
190+
CPUShares: int64(c.CPUShares),
191+
CPUQuota: int64(c.CPUQuota),
192+
CpusetCpus: c.CPUSet,
193+
Ulimits: ulimits,
194+
Devices: deviceMappings,
195+
OomKillDisable: &c.OomKillDisable,
195196
}
196197

197198
networkMode := c.NetworkMode

docker/service/convert_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ func TestMemSwappiness(t *testing.T) {
138138
assert.Equal(t, int64(10), *hostCfg.MemorySwappiness)
139139
}
140140

141+
func TestMemReservation(t *testing.T) {
142+
ctx := &ctx.Context{}
143+
sc := &config.ServiceConfig{
144+
MemReservation: 100000,
145+
}
146+
_, hostCfg, err := Convert(sc, ctx.Context, nil)
147+
assert.Nil(t, err)
148+
149+
assert.Equal(t, int64(100000), hostCfg.MemoryReservation)
150+
}
151+
141152
func TestOomKillDisable(t *testing.T) {
142153
ctx := &ctx.Context{}
143154
sc := &config.ServiceConfig{

0 commit comments

Comments
 (0)