Skip to content

Commit f042dc5

Browse files
committed
cmd/containerd-shim: aggressive memory reclamation
To avoid having the shim hold on to too much memory, we've made a few adjustments to favor more aggressive reclamation of memory from the operating system. Typically, this would be negligible, on the order of a few megabytes, but this is impactful when running several containers. The first fix is to lower the threshold used to determine when to run the garbage collector. The second runs `runtime/debug.FreeOSMemory` at a regular interval. Under test, this result in a sustained memory usage of around 3.7 MB. Signed-off-by: Stephen J Day <[email protected]> (cherry picked from commit 0e8f084) Signed-off-by: Stephen J Day <[email protected]>
1 parent 0f46dd5 commit f042dc5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

cmd/containerd-shim/main_unix.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"os/exec"
1313
"os/signal"
1414
"runtime"
15+
"runtime/debug"
1516
"strings"
1617
"sync"
1718
"syscall"
19+
"time"
1820

1921
"github.com/containerd/containerd/events"
2022
"github.com/containerd/containerd/linux/proc"
@@ -58,6 +60,13 @@ func init() {
5860
}
5961

6062
func main() {
63+
debug.SetGCPercent(10)
64+
go func() {
65+
for range time.Tick(30 * time.Second) {
66+
debug.FreeOSMemory()
67+
}
68+
}()
69+
6170
if debugFlag {
6271
logrus.SetLevel(logrus.DebugLevel)
6372
}

0 commit comments

Comments
 (0)