Skip to content

Commit

Permalink
Merge pull request moby#21760 from hqhq/hq_minimum_reservation
Browse files Browse the repository at this point in the history
Add minimum limit for memory reservation
  • Loading branch information
calavera committed Apr 8, 2016
2 parents 1e9115c + 50a6181 commit e626011
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions daemon/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi
logrus.Warnf("Your kernel does not support memory soft limit capabilities. Limitation discarded.")
resources.MemoryReservation = 0
}
if resources.MemoryReservation > 0 && resources.MemoryReservation < linuxMinMemory {
return warnings, fmt.Errorf("Minimum memory reservation allowed is 4MB")
}
if resources.Memory > 0 && resources.MemoryReservation > 0 && resources.Memory < resources.MemoryReservation {
return warnings, fmt.Errorf("Minimum memory limit should be larger than memory reservation limit, see usage")
}
Expand Down
5 changes: 5 additions & 0 deletions integration-cli/docker_cli_run_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
c.Assert(err, check.NotNil)
expected := "Minimum memory limit should be larger than memory reservation limit"
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))

out, _, err = dockerCmdWithError("run", "--memory-reservation", "1k", "busybox", "true")
c.Assert(err, check.NotNil)
expected = "Minimum memory reservation allowed is 4MB"
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
}

func (s *DockerSuite) TestStopContainerSignal(c *check.C) {
Expand Down

0 comments on commit e626011

Please sign in to comment.