Jelajahi Sumber

Merge pull request #272 from estesp/gc-startup-fix

Check GC loop is active/necessary before triggering GC
Madhu Venugopal 10 tahun lalu
induk
melakukan
2dcc09a8ef
1 mengubah file dengan 12 tambahan dan 4 penghapusan
  1. 12 4
      libnetwork/sandbox/namespace_linux.go

+ 12 - 4
libnetwork/sandbox/namespace_linux.go

@@ -107,12 +107,20 @@ func removeFromGarbagePaths(path string) {
 // GC triggers garbage collection of namespace path right away
 // GC triggers garbage collection of namespace path right away
 // and waits for it.
 // and waits for it.
 func GC() {
 func GC() {
-	waitGC := make(chan struct{})
+	gpmLock.Lock()
+	if len(garbagePathMap) == 0 {
+		// No need for GC if map is empty
+		gpmLock.Unlock()
+		return
+	}
+	gpmLock.Unlock()
 
 
-	// Trigger GC now
+	// if content exists in the garbage paths
+	// we can trigger GC to run, providing a
+	// channel to be notified on completion
+	waitGC := make(chan struct{})
 	gpmChan <- waitGC
 	gpmChan <- waitGC
-
-	// wait for gc to complete
+	// wait for GC completion
 	<-waitGC
 	<-waitGC
 }
 }