From f2db4ac2778145f76c6c5233966c82d692d22724 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 20 May 2020 11:40:34 -0400 Subject: [PATCH] cmd/tailscaled: SetGCPercent() if GOGC is not set. This cuts RSS from ~30MB to ~20MB on my machine, after the previous fix to get rid of unnecessary zstd buffers. Signed-off-by: Avery Pennarun --- cmd/tailscaled/tailscaled.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 6682c2831..17d17bef5 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -14,7 +14,9 @@ import ( "log" "net/http" "net/http/pprof" + "os" "runtime" + "runtime/debug" "time" "github.com/apenwarr/fixconsole" @@ -37,6 +39,14 @@ import ( const globalStateKey = "_daemon" func main() { + // We aren't very performance sensitive, and the parts that are + // performance sensitive (wireguard) try hard not to do any memory + // allocations. So let's be aggressive about garbage collection, + // unless the user specifically overrides it in the usual way. + if _, ok := os.LookupEnv("GOGC"); !ok { + debug.SetGCPercent(10) + } + defaultTunName := "tailscale0" if runtime.GOOS == "openbsd" { defaultTunName = "tun"