< prev index next >

src/share/vm/gc/g1/g1EvacStats.cpp

Print this page
rev 8875 : [mq]: 8067341-modify-plab-sizing-algorithm-to-waste-less
rev 8876 : [mq]: jon-eric-reviews
rev 8877 : [mq]: more-reviews


  37                         _allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste,
  38                         _regions_filled, _direct_allocated, _failure_used, _failure_waste);
  39   }
  40 
  41   if (ResizePLAB) {
  42 
  43     assert(is_object_aligned(max_size()) && min_size() <= max_size(),
  44            "PLAB clipping computation may be incorrect");
  45 
  46     if (_allocated == 0) {
  47       assert((_unused == 0),
  48              err_msg("Inconsistency in PLAB stats: "
  49                      "_allocated: "SIZE_FORMAT", "
  50                      "_wasted: "SIZE_FORMAT", "
  51                      "_region_end_waste: "SIZE_FORMAT", "
  52                      "_unused: "SIZE_FORMAT", "
  53                      "_used  : "SIZE_FORMAT,
  54                      _allocated, _wasted, _region_end_waste, _unused, used()));
  55       _allocated = 1;
  56     }
  57     // We account region end waste fully to PLAB allocation. This is not completely fair,
  58     // but is a conservative assumption because PLABs may be sized flexibly while we
  59     // cannot adjust direct allocations.
  60     // In some cases, wasted_frac may become > 1 but that just reflects the problem
  61     // with region_end_waste.
  62     double wasted_frac    = (double)(_unused + _wasted + _region_end_waste) / (double)_allocated;
  63     size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
  64     if (target_refills == 0) {
  65       target_refills = 1;
  66     }
  67     size_t cur_plab_sz = used() / target_refills;

























  68     // Take historical weighted average
  69     _filter.sample(cur_plab_sz);
  70     // Clip from above and below, and align to object boundary
  71     size_t plab_sz;
  72     plab_sz = MAX2(min_size(), (size_t)_filter.average());
  73     plab_sz = MIN2(max_size(), plab_sz);
  74     plab_sz = align_object_size(plab_sz);
  75     // Latch the result
  76     _desired_net_plab_sz = plab_sz;
  77     if (PrintPLAB) {
  78       gclog_or_tty->print_cr(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz);
  79     }
  80   }
  81   // Clear accumulators for next round.
  82   reset();
  83 }
  84 


  37                         _allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste,
  38                         _regions_filled, _direct_allocated, _failure_used, _failure_waste);
  39   }
  40 
  41   if (ResizePLAB) {
  42 
  43     assert(is_object_aligned(max_size()) && min_size() <= max_size(),
  44            "PLAB clipping computation may be incorrect");
  45 
  46     if (_allocated == 0) {
  47       assert((_unused == 0),
  48              err_msg("Inconsistency in PLAB stats: "
  49                      "_allocated: "SIZE_FORMAT", "
  50                      "_wasted: "SIZE_FORMAT", "
  51                      "_region_end_waste: "SIZE_FORMAT", "
  52                      "_unused: "SIZE_FORMAT", "
  53                      "_used  : "SIZE_FORMAT,
  54                      _allocated, _wasted, _region_end_waste, _unused, used()));
  55       _allocated = 1;
  56     }
  57     // Calculate the new PLAB size as the amount of space that could be wasted to
  58     // keep TargetPLABWastePct given latest memory usage and that the last buffer
  59     // will be G1PLABPercent full.
  60     //
  61     // E.g. assume that if in the current GC 100 words were allocated and a
  62     // TargetPLABWastePct of 10 had been set.
  63     //
  64     // So we could waste up to 10 words to meet that percentage. Given that we
  65     // also assume that that buffer is typically half-full, the new desired PLAB
  66     // size is 20 words.
  67     //
  68     // The amount of allocation performed is we can spend is independent of the
  69     // number of threads, so is the maximum waste we can spend in total. So if we used
  70     // n threads to allocate, each of them can spend maximum waste/n words in
  71     // a first rough approximation. The number of threads only comes into play later
  72     // when actually retrieving the actual desired PLAB size.
  73     //
  74     // After calculating this optimal PLAB size the algorithm applies the usual
  75     // exponential decaying average over this value to guess the next PLAB size.
  76     //
  77     // We account region end waste fully to PLAB allocation (in the calculation of
  78     // what we consider as "used_for_waste_calculation" below). This is not
  79     // completely fair, but is a conservative assumption because PLABs may be sized
  80     // flexibly while we cannot adjust inline allocations.
  81     // Allocation during GC will try to minimize region end waste so this impact
  82     // should be minimal.
  83     
  84     // We need to cover overflow when calculating the amount of space actually used
  85     // by objects in PLABs when subtracting the region end waste.
  86     // This is a possible situation if many threads do not allocate anything but a
  87     // few rather large objects. In this degenerate case the PLAB size would simply quickly
  88     // tend to minimum PLAB size, which is an okay reaction.
  89     size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0;
  90 
  91     size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
  92     size_t const cur_plab_sz = (double)total_waste_allowed / G1LastPLABAverageOccupancy;
  93     // Take historical weighted average
  94     _filter.sample(cur_plab_sz);
  95     // Clip from above and below, and align to object boundary
  96     size_t plab_sz;
  97     plab_sz = MAX2(min_size(), (size_t)_filter.average());
  98     plab_sz = MIN2(max_size(), plab_sz);
  99     plab_sz = align_object_size(plab_sz);
 100     // Latch the result
 101     _desired_net_plab_sz = plab_sz;
 102     if (PrintPLAB) {
 103       gclog_or_tty->print_cr(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz);
 104     }
 105   }
 106   // Clear accumulators for next round.
 107   reset();
 108 }
 109 
< prev index next >