英文:
understanding V8's heap information in nodejs
问题
从文档中,v8.getHeapSpaceStatistics() 返回类似以下内容,
[
{
"space_name": "new_space",
"space_size": 2063872,
"space_used_size": 951112,
"space_available_size": 80824,
"physical_space_size": 2063872
},
...
]
还有 v8.getHeapStatistics(),返回
{
total_heap_size: 7326976,
total_heap_size_executable: 4194304,
total_physical_size: 7326976,
total_available_size: 1152656,
used_heap_size: 3476208,
heap_size_limit: 1535115264,
malloced_memory: 16384,
peak_malloced_memory: 1127496,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0
}
有人可以解释一下这些键和空间实际代表什么吗?
英文:
from the docs, v8.getHeapSpaceStatistics() returns something like this,
[
{
"space_name": "new_space",
"space_size": 2063872,
"space_used_size": 951112,
"space_available_size": 80824,
"physical_space_size": 2063872
},
...
]
Also v8.getHeapStatistics(), returns
{
total_heap_size: 7326976,
total_heap_size_executable: 4194304,
total_physical_size: 7326976,
total_available_size: 1152656,
used_heap_size: 3476208,
heap_size_limit: 1535115264,
malloced_memory: 16384,
peak_malloced_memory: 1127496,
does_zap_garbage: 0,
number_of_native_contexts: 1,
number_of_detached_contexts: 0
}
Can somebody please explain what these keys and spaces actually mean?
答案1
得分: 8
V8 管理堆内存使用不同的空间,new_space
用于快速垃圾回收的新对象,而 old_space
用于生命周期较长的对象。v8.getHeapSpaceStatistics()
返回有关不同空间的统计信息。
这篇文章详细解释了不同空间的内容:http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection
以下是文章中解释的摘录:
> New-space(新空间):大多数对象都在此分配。New-space 很小,设计成能够独立于其他空间快速进行垃圾回收。
>
> Old-pointer-space(旧指针空间):包含大多数可能具有指向其他对象指针的对象。大多数对象在 new-space 存活一段时间后会被移动到此空间。
>
> Old-data-space(旧数据空间):包含仅包含原始数据(没有指向其他对象的指针)的对象。字符串、装箱数字和未装箱双精度数组在 new-space 存活一段时间后会被移动到此空间。
>
> Large-object-space(大对象空间):此空间包含大于其他空间大小限制的对象。每个对象都有自己的内存 mmap 区域。大对象永远不会被垃圾回收器移动。
>
> Code-space(代码空间):代码对象,包含 JIT 编译的指令,分配在此处。这是唯一具有可执行内存的空间(尽管代码也可以分配在大对象空间,这些也是可执行的)。
>
> Cell-space(单元空间)、property-cell-space(属性单元空间)和 map-space(映射空间):这些空间包含 Cells、PropertyCells 和 Maps,分别包含相同大小的对象,并对它们所指向的对象类型有一些约束,这简化了收集过程。
关于 v8.getHeapStatistics()
中不同字段的含义已经在这里回答过了:https://stackoverflow.com/questions/41541843/nodejs-v8-getheapstatistics-method
英文:
V8 manages heap in different spaces, new_space
is used for new objects which are quickly garbaged collected, while old_space
is for longer lived objects. v8.getHeapSpaceStatistics()
returns statistics about the different spaces.
This article has a more detailed explanation of the different spaces: http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection
Here is a quote of the explanation in the article:
> New-space: Most objects are allocated here. New-space is small and is designed to be garbage collected very quickly, independent of other spaces.
>
> Old-pointer-space: Contains most objects which may have pointers to other objects. Most objects are moved here after surviving in new-space for a while.
>
> Old-data-space: Contains objects which just contain raw data (no pointers to other objects). Strings, boxed numbers, and arrays of unboxed doubles are moved here after surviving in new-space for a while.
>
> Large-object-space: This space contains objects which are larger than the size limits of other spaces. Each object gets its own mmap'd region of memory. Large objects are never moved by the garbage collector.
>
> Code-space: Code objects, which contain JITed instructions, are allocated here. This is the only space with executable memory (although Codes may be allocated in large-object-space, and those are executable, too).
>
> Cell-space, property-cell-space and map-space: These spaces contain Cells, PropertyCells, and Maps, respectively. Each of these spaces contains objects which are all the same size and has some constraints on what kind of objects they point to, which simplifies collection.
The meaning of the different fields in v8.getHeapStatistics()
has already been answered here:
https://stackoverflow.com/questions/41541843/nodejs-v8-getheapstatistics-method
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论