title: When does the V8 GC trigger its first minor gc cycle (scavenge)?
body: <p>I'm trying to understand how this simple code that allocates one megabyte:</p>
  
  <pre><code>var BYTES_IN_MB = 1024 * 1024; // 1MB = 1024KB = 1024(KB/MB)*1024(B/KB)
  var BYTES_IN_SMI = 4;
  var NUM_SMIS_IN_MB = BYTES_IN_MB/BYTES_IN_SMI;
  
  var y = [];
  function allocateMB() {
    for(var i = 0; i &lt; NUM_SMIS_IN_MB; i++) {
      y.push(i);
    }
  }
  
  allocateMB();
  </code></pre>
  
  <p>Results in 4 minor gc cycles (scavenges). As you can see, we explicitly set the size of the new space to one megabyte. The expected result was to see one scavenge, but I don't understand why we see four instead.</p>
  
  <pre><code>➜  ~  d8
  V8 version 4.5.103.35 [console: readline]
  ➜  ~  d8 --trace_gc --trace_gc_verbose  --min_semi_space_size=1 --max_semi_space_size=1 --target_semi_space_size=1 --semi_space_growth_factor=0 allocateMB.js
  [2853:0x7fa1fa012600]        6 ms: Scavenge 1.7 (36.9) -&gt; 1.2 (36.9) MB, 0.3 / 0 ms [allocation failure].
  [2853:0x7fa1fa012600] Memory allocator,   used:  37752 KB, available: 1461384 KB
  [2853:0x7fa1fa012600] New space,          used:    281 KB, available:    726 KB, committed:   2015 KB
  [2853:0x7fa1fa012600] Old space,          used:    674 KB, available:      0 KB, committed:    794 KB
  [2853:0x7fa1fa012600] Code space,         used:    194 KB, available:      0 KB, committed:    261 KB
  [2853:0x7fa1fa012600] Map space,          used:     34 KB, available:      0 KB, committed:     59 KB
  [2853:0x7fa1fa012600] Large object space, used:      0 KB, available: 1460343 KB, committed:      0 KB
  [2853:0x7fa1fa012600] All spaces,         used:   1185 KB, available: 1461069 KB, committed:   3130 KB
  [2853:0x7fa1fa012600] External memory reported:      0 KB
  [2853:0x7fa1fa012600] Total time spent in GC  : 0.3 ms
  [2853:0x7fa1fa012600]        7 ms: Scavenge 1.5 (36.9) -&gt; 1.3 (36.9) MB, 0.4 / 0 ms [allocation failure].
  [2853:0x7fa1fa012600] Memory allocator,   used:  37752 KB, available: 1461384 KB
  [2853:0x7fa1fa012600] New space,          used:    397 KB, available:    610 KB, committed:   2015 KB
  [2853:0x7fa1fa012600] Old space,          used:    691 KB, available:      0 KB, committed:    794 KB
  [2853:0x7fa1fa012600] Code space,         used:    194 KB, available:      0 KB, committed:    261 KB
  [2853:0x7fa1fa012600] Map space,          used:     34 KB, available:      0 KB, committed:     59 KB
  [2853:0x7fa1fa012600] Large object space, used:      0 KB, available: 1460343 KB, committed:      0 KB
  [2853:0x7fa1fa012600] All spaces,         used:   1317 KB, available: 1460954 KB, committed:   3130 KB
  [2853:0x7fa1fa012600] External memory reported:      0 KB
  [2853:0x7fa1fa012600] Total time spent in GC  : 0.7 ms
  [2853:0x7fa1fa012600]        8 ms: Scavenge 1.9 (36.9) -&gt; 1.5 (36.9) MB, 0.2 / 0 ms [allocation failure].
  [2853:0x7fa1fa012600] Memory allocator,   used:  37752 KB, available: 1461384 KB
  [2853:0x7fa1fa012600] New space,          used:    596 KB, available:    411 KB, committed:   2015 KB
  [2853:0x7fa1fa012600] Old space,          used:    691 KB, available:      0 KB, committed:    794 KB
  [2853:0x7fa1fa012600] Code space,         used:    194 KB, available:      0 KB, committed:    261 KB
  [2853:0x7fa1fa012600] Map space,          used:     34 KB, available:      0 KB, committed:     59 KB
  [2853:0x7fa1fa012600] Large object space, used:      0 KB, available: 1460343 KB, committed:      0 KB
  [2853:0x7fa1fa012600] All spaces,         used:   1516 KB, available: 1460755 KB, committed:   3130 KB
  [2853:0x7fa1fa012600] External memory reported:      0 KB
  [2853:0x7fa1fa012600] Total time spent in GC  : 0.9 ms
  [2853] Limited new space size due to high promotion rate: 1 MB
  [2853:0x7fa1fa012600]        8 ms: Scavenge 1.5 (36.9) -&gt; 1.5 (37.9) MB, 0.7 / 0 ms [allocation failure].
  [2853:0x7fa1fa012600] Memory allocator,   used:  38776 KB, available: 1460360 KB
  [2853:0x7fa1fa012600] New space,          used:      0 KB, available:   1007 KB, committed:   2015 KB
  [2853:0x7fa1fa012600] Old space,          used:   1287 KB, available:    102 KB, committed:   1801 KB
  [2853:0x7fa1fa012600] Code space,         used:    194 KB, available:      0 KB, committed:    261 KB
  [2853:0x7fa1fa012600] Map space,          used:     34 KB, available:      0 KB, committed:     59 KB
  [2853:0x7fa1fa012600] Large object space, used:      0 KB, available: 1459319 KB, committed:      0 KB
  [2853:0x7fa1fa012600] All spaces,         used:   1516 KB, available: 1460430 KB, committed:   4138 KB
  [2853:0x7fa1fa012600] External memory reported:      0 KB
  [2853:0x7fa1fa012600] Total time spent in GC  : 1.6 ms
  </code></pre>