|
@@ -25,6 +25,7 @@ var (
|
|
gpmLock sync.Mutex
|
|
gpmLock sync.Mutex
|
|
gpmWg sync.WaitGroup
|
|
gpmWg sync.WaitGroup
|
|
gpmCleanupPeriod = 60 * time.Second
|
|
gpmCleanupPeriod = 60 * time.Second
|
|
|
|
+ gpmChan = make(chan chan struct{})
|
|
)
|
|
)
|
|
|
|
|
|
// The networkNamespace type is the linux implementation of the Sandbox
|
|
// The networkNamespace type is the linux implementation of the Sandbox
|
|
@@ -56,7 +57,18 @@ func removeUnusedPaths() {
|
|
period := gpmCleanupPeriod
|
|
period := gpmCleanupPeriod
|
|
gpmLock.Unlock()
|
|
gpmLock.Unlock()
|
|
|
|
|
|
- for range time.Tick(period) {
|
|
|
|
|
|
+ ticker := time.NewTicker(period)
|
|
|
|
+ for {
|
|
|
|
+ var (
|
|
|
|
+ gc chan struct{}
|
|
|
|
+ gcOk bool
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ select {
|
|
|
|
+ case <-ticker.C:
|
|
|
|
+ case gc, gcOk = <-gpmChan:
|
|
|
|
+ }
|
|
|
|
+
|
|
gpmLock.Lock()
|
|
gpmLock.Lock()
|
|
pathList := make([]string, 0, len(garbagePathMap))
|
|
pathList := make([]string, 0, len(garbagePathMap))
|
|
for path := range garbagePathMap {
|
|
for path := range garbagePathMap {
|
|
@@ -71,6 +83,9 @@ func removeUnusedPaths() {
|
|
}
|
|
}
|
|
|
|
|
|
gpmWg.Done()
|
|
gpmWg.Done()
|
|
|
|
+ if gcOk {
|
|
|
|
+ close(gc)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,6 +101,18 @@ func removeFromGarbagePaths(path string) {
|
|
gpmLock.Unlock()
|
|
gpmLock.Unlock()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GC triggers garbage collection of namespace path right away
|
|
|
|
+// and waits for it.
|
|
|
|
+func GC() {
|
|
|
|
+ waitGC := make(chan struct{})
|
|
|
|
+
|
|
|
|
+ // Trigger GC now
|
|
|
|
+ gpmChan <- waitGC
|
|
|
|
+
|
|
|
|
+ // wait for gc to complete
|
|
|
|
+ <-waitGC
|
|
|
|
+}
|
|
|
|
+
|
|
// GenerateKey generates a sandbox key based on the passed
|
|
// GenerateKey generates a sandbox key based on the passed
|
|
// container id.
|
|
// container id.
|
|
func GenerateKey(containerID string) string {
|
|
func GenerateKey(containerID string) string {
|