Repository navigation
[tailscale] runtime: add TailscaleReadStackStats for per-goroutine stack info - #185
Merged
Merged
Conversation
…ack info We're working on reducing the standing memory of servers holding millions of idle long-polling connections. A big part of that is knowing which stack size class those goroutines' stacks are in, how much of the stack they actually use while parked, and whether the stacks grew during connection setup and were later shrunk back by the GC. The runtime doesn't expose any of that. Add runtime.TailscaleReadStackStats, modeled on ReadMemStats, which fills in a TailscaleStackStats for the calling goroutine: the current stack size (its size class), the bytes in use at the point of the call, the largest size the stack has ever been, and saturating counts of growths and shrinks. The runtime doesn't track a true high-water mark of stack usage, and doing so would cost work on every call, so MaxSize (the peak allocated size) is the proxy: a stack only doubles when the previous size overflowed, so peak usage was at least roughly MaxSize/2. Comparing it against Size shows whether the GC has already shrunk a goroutine's stack back down. The three backing fields on g are uint8s placed in what was alignment padding before g.sig, so g does not grow. They're reset in newproc1 because gs are recycled through the free list. Growths are recorded in newstack and shrinks in shrinkstack. The call itself takes no locks and costs about 7ns. Updates #184 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I7c2e9b41f6d8a05e3b9f1c4d2a8e6f7b0c1d3e5a
bradfitz
added a commit
to tailscale/tailscale
that referenced
this pull request
Sep 11, 2026
Updates tailscale/go#185 Updates tailscale/corp#29053 Updates #21064 Change-Id: Ic127c83b3ed7b472a23f62ec1a67f08b0de31556 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We're working on reducing the standing memory of servers holding
millions of idle long-polling connections. A big part of that is
knowing which stack size class those goroutines' stacks are in, how
much of the stack they actually use while parked, and whether the
stacks grew during connection setup and were later shrunk back by the
GC. The runtime doesn't expose any of that.
Add runtime.TailscaleReadStackStats, modeled on ReadMemStats, which
fills in a TailscaleStackStats for the calling goroutine: the current
stack size (its size class), the bytes in use at the point of the
call, the largest size the stack has ever been, and saturating counts
of growths and shrinks.
The runtime doesn't track a true high-water mark of stack usage, and
doing so would cost work on every call, so MaxSize (the peak allocated
size) is the proxy: a stack only doubles when the previous size
overflowed, so peak usage was at least roughly MaxSize/2. Comparing it
against Size shows whether the GC has already shrunk a goroutine's
stack back down.
The three backing fields on g are uint8s placed in what was alignment
padding before g.sig, so g does not grow. They're reset in newproc1
because gs are recycled through the free list. Growths are recorded
in newstack and shrinks in shrinkstack. The call itself takes no locks
and costs about 7ns.
Updates #184