Browse code

Remove the NO_MEMORY_LIMIT constant

Guillaume J. Charmes authored on 2013/04/19 13:08:20
Showing 5 changed files
... ...
@@ -13,10 +13,7 @@ endif
13 13
 GIT_COMMIT = $(shell git rev-parse --short HEAD)
14 14
 GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "+CHANGES")
15 15
 
16
-NO_MEMORY_LIMIT ?= 0
17
-export NO_MEMORY_LIMIT
18
-
19
-BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS) -X main.NO_MEMORY_LIMIT $(NO_MEMORY_LIMIT)"
16
+BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS)"
20 17
 
21 18
 SRC_DIR := $(GOPATH)/src
22 19
 
... ...
@@ -21,8 +21,7 @@ import (
21 21
 const VERSION = "0.1.6"
22 22
 
23 23
 var (
24
-	GIT_COMMIT      string
25
-	NO_MEMORY_LIMIT bool
24
+	GIT_COMMIT string
26 25
 )
27 26
 
28 27
 func (srv *Server) Name() string {
... ...
@@ -373,10 +373,15 @@ func (container *Container) Start() error {
373 373
 		return err
374 374
 	}
375 375
 
376
-	if container.Config.Memory > 0 && NO_MEMORY_LIMIT {
377
-		log.Printf("WARNING: This version of docker has been compiled without memory limit support. Discarding the limit.")
376
+	// Make sure the config is compatible with the current kernel
377
+	if container.Config.Memory > 0 && !container.runtime.capabilities.MemoryLimit {
378
+		log.Printf("WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
378 379
 		container.Config.Memory = 0
379 380
 	}
381
+	if container.Config.Memory > 0 && !container.runtime.capabilities.SwapLimit {
382
+		log.Printf("WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.\n")
383
+		container.Config.MemorySwap = -1
384
+	}
380 385
 
381 386
 	if err := container.generateLXCConfig(); err != nil {
382 387
 		return err
... ...
@@ -14,8 +14,7 @@ import (
14 14
 )
15 15
 
16 16
 var (
17
-	GIT_COMMIT      string
18
-	NO_MEMORY_LIMIT string
17
+	GIT_COMMIT string
19 18
 )
20 19
 
21 20
 func main() {
... ...
@@ -39,15 +38,11 @@ func main() {
39 39
 		os.Setenv("DEBUG", "1")
40 40
 	}
41 41
 	docker.GIT_COMMIT = GIT_COMMIT
42
-	docker.NO_MEMORY_LIMIT = NO_MEMORY_LIMIT == "1"
43 42
 	if *flDaemon {
44 43
 		if flag.NArg() != 0 {
45 44
 			flag.Usage()
46 45
 			return
47 46
 		}
48
-		if NO_MEMORY_LIMIT == "1" {
49
-			log.Printf("WARNING: This version of docker has been compiled without memory limit support.")
50
-		}
51 47
 		if err := daemon(*pidfile); err != nil {
52 48
 			log.Fatal(err)
53 49
 		}
... ...
@@ -46,8 +46,6 @@ func layerArchive(tarfile string) (io.Reader, error) {
46 46
 }
47 47
 
48 48
 func init() {
49
-	NO_MEMORY_LIMIT = os.Getenv("NO_MEMORY_LIMIT") == "1"
50
-
51 49
 	// Hack to run sys init during unit testing
52 50
 	if SelfPath() == "/sbin/init" {
53 51
 		SysInit()