1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #25461 from coolljt0725/fix_update_mem

Fix update memory without memoryswap
This commit is contained in:
Sebastiaan van Stijn 2016-08-09 16:02:55 +02:00 committed by GitHub
commit 8233e2b54d
3 changed files with 25 additions and 0 deletions

View file

@ -283,6 +283,11 @@ func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfi
cResources.CpusetMems = resources.CpusetMems
}
if resources.Memory != 0 {
// if memory limit smaller than already set memoryswap limit and doesn't
// update the memoryswap limit, then error out.
if resources.Memory > cResources.MemorySwap && resources.MemorySwap == 0 {
return fmt.Errorf("Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time")
}
cResources.Memory = resources.Memory
}
if resources.MemorySwap != 0 {

View file

@ -236,3 +236,17 @@ func (s *DockerSuite) TestUpdateStats(c *check.C) {
c.Assert(preMemLimit, checker.Equals, curMemLimit)
}
func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, memoryLimitSupport)
testRequires(c, swapMemorySupport)
name := "test-update-container"
dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "busybox", "top")
out, _, err := dockerCmdWithError("update", "--memory", "800M", name)
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "Memory limit should be smaller than already set memoryswap limit")
dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
}

View file

@ -67,6 +67,12 @@ a running container with kernel memory initialized.
**-m**, **--memory**=""
Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
Note that the memory should be smaller than the already set swap memory limit.
If you want update a memory limit bigger than the already set swap memory limit,
you should update swap memory limit at the same time. If you don't set swap memory
limit on docker create/run but only memory limit, the swap memory is double
the memory limit.
**--memory-reservation**=""
Memory soft limit (format: <number>[<unit>], where unit = b, k, m or g)