From 4aef0237657e052c14f88562490415085fbfa820 Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Tue, 26 May 2026 17:13:48 -0700 Subject: [PATCH] cmd/tailscaled,types/logger: remove TS_DEBUG_MEMORY and associated logger Commit e5a8cf3b1 added feature/runtimemetrics, which emits heap bytes and total process memory as clientmetrics when the NodeAttrEmitRuntimeMetrics capability is set. That subsumes the job of the TS_DEBUG_MEMORY envknob, whose only effect is to prefix every log line with Go heap+stack and Maxrss via logger.RusagePrefixLog. Updates tailscale/corp#39434 Signed-off-by: Jordan Whited --- cmd/tailscaled/tailscaled.go | 3 --- types/logger/rusage.go | 23 ----------------------- types/logger/rusage_stub.go | 11 ----------- types/logger/rusage_syscall.go | 29 ----------------------------- 4 files changed, 66 deletions(-) delete mode 100644 types/logger/rusage.go delete mode 100644 types/logger/rusage_stub.go delete mode 100644 types/logger/rusage_syscall.go diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 9ecf84055..42126f0c9 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -460,9 +460,6 @@ func run() (err error) { return nil } - if envknob.Bool("TS_DEBUG_MEMORY") { - logf = logger.RusagePrefixLog(logf) - } logf = logger.RateLimitedFn(logf, 5*time.Second, 5, 100) if envknob.Bool("TS_PLEASE_PANIC") { diff --git a/types/logger/rusage.go b/types/logger/rusage.go deleted file mode 100644 index c1bbbaa53..000000000 --- a/types/logger/rusage.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Tailscale Inc & contributors -// SPDX-License-Identifier: BSD-3-Clause - -package logger - -import ( - "fmt" - "runtime" -) - -// RusagePrefixLog returns a Logf func wrapping the provided logf func that adds -// a prefixed log message to each line with the current binary memory usage -// and max RSS. -func RusagePrefixLog(logf Logf) Logf { - return func(f string, argv ...any) { - var m runtime.MemStats - runtime.ReadMemStats(&m) - goMem := float64(m.HeapInuse+m.StackInuse) / (1 << 20) - maxRSS := rusageMaxRSS() - pf := fmt.Sprintf("%.1fM/%.1fM %s", goMem, maxRSS, f) - logf(pf, argv...) - } -} diff --git a/types/logger/rusage_stub.go b/types/logger/rusage_stub.go deleted file mode 100644 index e94478ef7..000000000 --- a/types/logger/rusage_stub.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Tailscale Inc & contributors -// SPDX-License-Identifier: BSD-3-Clause - -//go:build windows || wasm || plan9 || tamago - -package logger - -func rusageMaxRSS() float64 { - // TODO(apenwarr): Substitute Windows equivalent of Getrusage() here. - return 0 -} diff --git a/types/logger/rusage_syscall.go b/types/logger/rusage_syscall.go deleted file mode 100644 index 25b026994..000000000 --- a/types/logger/rusage_syscall.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Tailscale Inc & contributors -// SPDX-License-Identifier: BSD-3-Clause - -//go:build !windows && !wasm && !plan9 && !tamago - -package logger - -import ( - "runtime" - - "golang.org/x/sys/unix" -) - -func rusageMaxRSS() float64 { - var ru unix.Rusage - err := unix.Getrusage(unix.RUSAGE_SELF, &ru) - if err != nil { - return 0 - } - - rss := float64(ru.Maxrss) - if runtime.GOOS == "darwin" || runtime.GOOS == "ios" { - rss /= 1 << 20 // ru_maxrss is bytes on darwin - } else { - // ru_maxrss is kilobytes elsewhere (linux, openbsd, etc) - rss /= 1 << 10 - } - return rss -}