QQ截图20150323191419.png [11456] 227 ms: Scavenge 6.0 (41.5) -> 5.0 (41.5) MB, 2.0 ms [allocation failure]. [11456] Memory allocator, used: 42468 KB, available: 1456668 KB [11456] New space, used: 521 KB, available: 1526 KB, committed: 4096 KB [11456] Old pointers, used: 1619 KB, available: 0 KB, committed: 1903 KB [11456] Old data space, used: 1700 KB, available: 24 KB, committed: 2207 KB [11456] Code space, used: 925 KB, available: 0 KB, committed: 996 KB [11456] Map space, used: 289 KB, available: 0 KB, committed: 1135 KB [11456] Cell space, used: 8 KB, available: 0 KB, committed: 128 KB [11456] PropertyCell space, used: 27 KB, available: 0 KB, committed: 64 KB [11456] Large object space, used: 0 KB, available: 1455627 KB, committed: 0 KB [11456] All spaces, used: 5093 KB, available: 1551 KB, committed: 10531 KB [11456] External memory reported: 16 KB [11456] Total time spent in GC : 8.9 ms [11456] 285 ms: Scavenge 6.8 (41.5) -> 5.6 (42.5) MB, 3.2 ms [allocation failure]. [11456] Memory allocator, used: 43492 KB, available: 1455644 KB [11456] New space, used: 327 KB, available: 3768 KB, committed: 8192 KB [11456] Old pointers, used: 2144 KB, available: 0 KB, committed: 2911 KB [11456] Old data space, used: 1829 KB, available: 24 KB, committed: 2207 KB [11456] Code space, used: 995 KB, available: 0 KB, committed: 996 KB [11456] Map space, used: 395 KB, available: 0 KB, committed: 1135 KB [11456] Cell space, used: 9 KB, available: 0 KB, committed: 128 KB [11456] PropertyCell space, used: 27 KB, available: 0 KB, committed: 64 KB [11456] Large object space, used: 0 KB, available: 1454603 KB, committed: 0 KB [11456] All spaces, used: 5729 KB, available: 3793 KB, committed: 15634 KB [11456] External memory reported: 30 KB !
我也没有找到相关文档,同求解释,下面根据V8的GC原理简单推测下好了。V8采用分代回收机制,分别是新生代和老生代,上面的Scavenge是新生代采用的垃圾回收的算法,Mark-Sweep是老生代采用的垃圾回收算法。
-
285 ms: Scavenge 6.8 (41.5) -> 5.6 (42.5) MB, 3.2 ms [allocation failure]
程序运行到285毫秒的时候(日志时间,V8采用了相对时间而不是绝对时间),V8对新生代进行了基于Scavenge算法的垃圾回收,新生代内存占用从6.8MB空间释放到了5.6MB(默认最大值是64MB),全局内存占用从41.5MB上升到了42.5MB(默认最大值是1400MB+64MB),用了3.2毫秒。最后的allocation failure目测不是真的失败,不是很清楚具体含义。 -
Memory allocator, used: 43492 KB, available: 1455644 KB
全局内存分配情况,使用了42.5MB内存,还有1421.5MB可用。 (加起来差不多是1400MB+64MB) -
New space, used: 327 KB, available: 3768 KB, committed: 8192 KB等下面的条目 新生代里的内存占用详情,具体每项的含义不是特别清楚(应该也不需要看这么仔细吧),used就是占用了多少内存,available是可用的内存,committed是什么东西?
@amoa400 新生代内存占用从6.8MB空间释放到了5.6MB(默认最大值是64MB), 这个 64M 是那个地方设定的呢
@lik0914 需要在启动node进程的时候通过参数设置,–max-new-space-size
[1136] 1048 ms: Scavenge 225.9 (263.0) -> 225.9 (263.0) MB, 1 ms [Runtime::PerformGC]. [1136] 1050 ms: Scavenge 226.6 (263.0) -> 226.6 (264.0) MB, 1 ms [Runtime::PerformGC]. [1136] 1052 ms: Scavenge 227.4 (264.0) -> 227.4 (265.0) MB, 1 ms [Runtime::PerformGC]. [1136] 1054 ms: Scavenge 228.1 (265.0) -> 228.1 (266.0) MB, 1 ms [Runtime::PerformGC]. 这里值得是整个对内存的大小吧,新生代内存不可能开到228M的
@lik0914 这个是node的c++源码里面决定的。代码路径在deps/v8/src/heap 参考文件spaces.cc,heap.cc 里面有这样一段代码
··· // semispace_size_ should be a power of 2 and old_generation_size_ should // be a multiple of Page::kPageSize. reserved_semispace_size_(8 * (kPointerSize / 4) * MB), max_semi_space_size_(8 * (kPointerSize / 4) * MB), initial_semispace_size_(Page::kPageSize), max_old_generation_size_(700ul * (kPointerSize / 4) * MB), max_executable_size_(256ul * (kPointerSize / 4) * MB), // Variables set based on semispace_size_ and old_generation_size_ in // ConfigureHeap. // Will be 4 * reserved_semispace_size_ to ensure that young // generation can be aligned to its size.
···
max_semi_space_size_ 就是设置的值,这里的值根据一个Page::kPageSize来决定大小
@hinson0 谢谢, 例如 285 ms: Scavenge 6.8 (41.5) -> 5.6 (42.5) MB, 3.2 ms [allocation failure] 这样的日志, 具体的意思,从哪可以参考出来, 此行还提示 分配失败