Interpreting the heap statistics requires some knowledge of how Go organizes memory. Go divides the virtual address space of the heap into "spans", which are contiguous regions of memory 8K or larger. A span may be in one of three states:
-
An "idle" span contains no objects or other data. The physical memory backing an idle span can be released back to the OS (but the virtual address space never is), or it can be converted into an "in use" or "stack" span.
-
An "in use" span contains at least one heap object and may have free space available to allocate more heap objects.
-
A "stack" span is used for goroutine stacks. Stack spans are not considered part of the heap. A span can change between heap and stack memory; it is never used for both simultaneously.
为了解释heap统计数据需要了解一些Go是如何组织内存的知识。Go把heap的虚拟地址空间划分成若干个“spans”,这些“spans”的占据着连续的内存区域,每个为8k或者更大。一个span会有以下三种状态:
- 一个
idle span不包含任何对象或其他数据。支持idle span物理内存可以被释放回OS,(但虚拟地址空间不会)或者会被转换成in use span或stack span。- 一个
in use span至少包含一个head对象并拥有空闲的空间用于分配更多的head对象。- 一个
stack span被用于goroutines栈。stack span不被认为是heap的一部分。一个span可以heap和stack内存之间变化;但它不能同时用于两者。