Bladeren bron

Remove the NO_MEMORY_LIMIT constant

Guillaume J. Charmes 12 jaren geleden
bovenliggende
commit
f68d107a13
5 gewijzigde bestanden met toevoegingen van 10 en 16 verwijderingen
  1. 1 4
      Makefile
  2. 1 2
      commands.go
  3. 7 2
      container.go
  4. 1 6
      docker/docker.go
  5. 0 2
      runtime_test.go

+ 1 - 4
Makefile

@@ -13,10 +13,7 @@ endif
 GIT_COMMIT = $(shell git rev-parse --short HEAD)
 GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "+CHANGES")
 
-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)"
+BUILD_OPTIONS = -ldflags "-X main.GIT_COMMIT $(GIT_COMMIT)$(GIT_STATUS)"
 
 SRC_DIR := $(GOPATH)/src
 

+ 1 - 2
commands.go

@@ -21,8 +21,7 @@ import (
 const VERSION = "0.1.6"
 
 var (
-	GIT_COMMIT      string
-	NO_MEMORY_LIMIT bool
+	GIT_COMMIT string
 )
 
 func (srv *Server) Name() string {

+ 7 - 2
container.go

@@ -373,10 +373,15 @@ func (container *Container) Start() error {
 		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.")
+	// Make sure the config is compatible with the current kernel
+	if container.Config.Memory > 0 && !container.runtime.capabilities.MemoryLimit {
+		log.Printf("WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
 		container.Config.Memory = 0
 	}
+	if container.Config.Memory > 0 && !container.runtime.capabilities.SwapLimit {
+		log.Printf("WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.\n")
+		container.Config.MemorySwap = -1
+	}
 
 	if err := container.generateLXCConfig(); err != nil {
 		return err

+ 1 - 6
docker/docker.go

@@ -14,8 +14,7 @@ import (
 )
 
 var (
-	GIT_COMMIT      string
-	NO_MEMORY_LIMIT string
+	GIT_COMMIT string
 )
 
 func main() {
@@ -39,15 +38,11 @@ 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)
 		}

+ 0 - 2
runtime_test.go

@@ -46,8 +46,6 @@ 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()