From 1967c8342aef1a81eb33a41d673bb8e702daa5df Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 11 Apr 2013 12:58:23 -0700 Subject: [PATCH] Allow to disable memory limit at compilation time --- Makefile | 5 ++++- commands.go | 8 +++++++- container.go | 11 +++++++++++ docker/docker.go | 9 ++++++++- runtime_test.go | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a6eb613830..c89f0f33b0 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,10 @@ endif GIT_COMMIT = $(shell git rev-parse --short HEAD) GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "+CHANGES") -BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS)" +NO_MEMORY_LIMIT ?= 0 +export NO_MEMORY_LIMIT + +BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS) -X main.NO_MEMORY_LIMIT $(NO_MEMORY_LIMIT)" SRC_DIR := $(GOPATH)/src diff --git a/commands.go b/commands.go index dc2bb20ac6..0229b1dee3 100644 --- a/commands.go +++ b/commands.go @@ -20,7 +20,10 @@ import ( const VERSION = "0.1.4" -var GIT_COMMIT string +var ( + GIT_COMMIT string + NO_MEMORY_LIMIT bool +) func (srv *Server) Name() string { return "docker" @@ -183,6 +186,9 @@ func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string func (srv *Server) CmdVersion(stdin io.ReadCloser, stdout io.Writer, args ...string) error { fmt.Fprintf(stdout, "Version:%s\n", VERSION) fmt.Fprintf(stdout, "Git Commit:%s\n", GIT_COMMIT) + if NO_MEMORY_LIMIT { + fmt.Fprintf(stdout, "Memory limit disabled\n") + } return nil } diff --git a/container.go b/container.go index e0b09935b5..53f29917dd 100644 --- a/container.go +++ b/container.go @@ -79,6 +79,11 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) { flTty := cmd.Bool("t", false, "Allocate a pseudo-tty") flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)") + if *flMemory > 0 && NO_MEMORY_LIMIT { + fmt.Fprintf(stdout, "WARNING: This version of docker has been compiled without memory limit support. Discarding -m.") + *flMemory = 0 + } + var flPorts ListOpts cmd.Var(&flPorts, "p", "Expose a container's port to the host (use 'docker port' to see the actual mapping)") @@ -355,6 +360,12 @@ func (container *Container) Start() error { if err := container.allocateNetwork(); err != nil { return err } + + if container.Config.Memory > 0 && NO_MEMORY_LIMIT { + log.Printf("WARNING: This version of docker has been compiled without memory limit support. Discarding the limit.") + container.Config.Memory = 0 + } + if err := container.generateLXCConfig(); err != nil { return err } diff --git a/docker/docker.go b/docker/docker.go index 76a0467be8..bbe0a0e7a8 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -13,7 +13,10 @@ import ( "syscall" ) -var GIT_COMMIT string +var ( + GIT_COMMIT string + NO_MEMORY_LIMIT string +) func main() { if docker.SelfPath() == "/sbin/init" { @@ -36,11 +39,15 @@ func main() { os.Setenv("DEBUG", "1") } docker.GIT_COMMIT = GIT_COMMIT + docker.NO_MEMORY_LIMIT = NO_MEMORY_LIMIT == "1" if *flDaemon { if flag.NArg() != 0 { flag.Usage() return } + if NO_MEMORY_LIMIT == "1" { + log.Printf("WARNING: This version of docker has been compiled without memory limit support.") + } if err := daemon(*pidfile); err != nil { log.Fatal(err) } diff --git a/runtime_test.go b/runtime_test.go index 55d2b54e7e..b990deaf38 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -48,6 +48,8 @@ func layerArchive(tarfile string) (io.Reader, error) { } func init() { + NO_MEMORY_LIMIT = os.Getenv("NO_MEMORY_LIMIT") == "1" + // Hack to run sys init during unit testing if SelfPath() == "/sbin/init" { SysInit()