32

In nodejs v8 module, there's a function called getHeapStatistics which return an object that contains information about memory usage:

{ 
  total_heap_size: 221540352,
  total_heap_size_executable: 5242880,
  total_physical_size: 221540352,
  total_available_size: 1286110104,
  used_heap_size: 189179192,
  heap_size_limit: 1501560832,
  malloced_memory: 16384,
  peak_malloced_memory: 1325112,
  does_zap_garbage: 0 
}

What's the meaning of each field?

superhero
  • 6,281
  • 11
  • 59
  • 91
王如锵
  • 941
  • 7
  • 17

2 Answers2

22

Some good explanation from gc-heap-stats package:

  • total_heap_size: Number of bytes V8 has allocated for the heap. This can grow if usedHeap needs more.
  • used_heap_size: Number of bytes in used by application data
  • total_heap_size_executable: Number of bytes for compiled bytecode and JITed code
  • heap_size_limit: The absolute limit the heap cannot exceed (default limit or --max_old_space_size)
  • total_physical_size: Committed size

From Node.JS docs:

  • does_zap_garbage is a 0/1 boolean, which signifies whether the --zap_code_space option is enabled or not. This makes V8 overwrite heap garbage with a bit pattern. The RSS footprint (resident memory set) gets bigger because it continuously touches all heap pages and that makes them less likely to get swapped out by the operating system.

Self descriptive:

  • total_available_size: Available heap size
  • malloced_memory: current amount of memory, obtained via malloc
  • peak_malloced_memory: peak amount of memory, obtained via malloc
Jehy
  • 4,729
  • 1
  • 38
  • 55
  • 5
    "Other fields are pretty self descriptive." I disagree, someone coming in here through google may be trying to find out about one of these specifically, in order to learn. if not to much trouble, I would like you to expand your answer to include the missing parts, even if it's to you "self descriptive" :) to the next person it may not be – superhero Dec 13 '17 at 10:10
  • 1
    Ok, I expanded my answer. – Jehy Dec 15 '17 at 11:17
  • Wondering, how peak_malloced_memory is obtained and how long is it kept for statistic purposes... – JustAMartin Sep 03 '19 at 07:48
  • 1
    what is total_available_size? is it `total_heap_size - used_heap_size`? is it `heap_size_limit - used_heap_size - total_heap_size_executable`? this does not seem self descriptive – ldanilek Dec 12 '22 at 22:30
2

There's V8 API documentation directly generated from the sources, but the details of HeapStatistics are not explained.

user835611
  • 2,309
  • 2
  • 21
  • 29