I posted this question on stackoverflow 
(http://stackoverflow.com/questions/33780781/when-does-the-v8-gc-trigger-its-first-minor-gc-cycle-scavenge)
 
but I think I should have first posted it here. In any case, I'm confused 
as to why V8 triggers 4 scavenges when I have only allocated one MB and 
have explicitly set the min, max, and target new space to one MB. Now, I 
can imagine that v8 might startup with some 'hidden' objects already on the 
heap which might result in one scavenge being triggered before the user 
code allocates a full MB, but it should still not result in 4 scavenges. 
Either my math is wrong, or I'm missing something.

Here is the sample code that results in 4 GC cycles on the new space:

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 < NUM_SMIS_IN_MB; i++) {
    y.push(i);
  }}

allocateMB();



Here is the execution:

➜  ~  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) -> 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) -> 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) -> 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) -> 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

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to