These questions are a little difficult to answer because goroutine stacks are allocated from the heap. Go does not have a clear separation between the stack and the heap that exists in C.
Does heap, stack, or both enter the general distribution field?
The TotalAlloc field of the MemStats structure includes all of the memory requested by the Go run operation from the OS for the Go heap. It does not include memory allocated for goroutine stacks. Initially, I thought it was, but I was wrong. Sorry for the confusion. I hope this answer will be more accurate.
(To be precise, I must mention that in a program using cgo, each thread (and not goroutine - usually more goroutines than threads) will have a stack allocated by the OS, this stack is not allocated by Go runtime and is not counted in TotalAlloc. It used only for cgo calls.)
, which heap fields do not include stacks of numbers? Which heap fields include numbers for the stack?
These fields include numbers for goroutine strings: HeapIdle, HeapReleased.
These fields do not include numbers for goroutine strings: HeapAlloc, HeapInUse, HeapObjects.
The HeapSys field does not include memory used by the currently active goroutine stacks, but includes memory for goroutine stacks that were once used but then freed.
which stack fields do not contain numbers for the heap?
I do not know how to answer this question in a way that makes sense. Stack fields report goroutine package information.
iant
source share