8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/g1/g1EvacStats.hpp" 27 #include "gc/shared/gcId.hpp" 28 #include "trace/tracing.hpp" 29 30 void G1EvacStats::adjust_desired_plab_sz() { 31 if (PrintPLAB) { 32 gclog_or_tty->print(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " " 33 "unused = " SIZE_FORMAT " used = " SIZE_FORMAT " " 34 "undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT " " 35 "regions filled = %u direct_allocated = " SIZE_FORMAT " " 36 "failure_used = " SIZE_FORMAT " failure_waste = " SIZE_FORMAT ") ", 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 "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 // The size of the PLAB caps the amount of space that can be wasted at the 58 // end of the collection. In the worst case the last PLAB could be completely 59 // empty. 60 // This allows us to calculate the new PLAB size to achieve the 61 // TargetPLABWastePct given the latest memory usage and that the last buffer 62 // will be G1LastPLABAverageOccupancy full. 86 // 87 // We need to cover overflow when calculating the amount of space actually used 88 // by objects in PLABs when subtracting the region end waste. 89 // Region end waste may be higher than actual allocation. This may occur if many 90 // threads do not allocate anything but a few rather large objects. In this 91 // degenerate case the PLAB size would simply quickly tend to minimum PLAB size, 92 // which is an okay reaction. 93 size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; 94 95 size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct; 96 size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy); 97 // Take historical weighted average 98 _filter.sample(cur_plab_sz); 99 // Clip from above and below, and align to object boundary 100 size_t plab_sz; 101 plab_sz = MAX2(min_size(), (size_t)_filter.average()); 102 plab_sz = MIN2(max_size(), plab_sz); 103 plab_sz = align_object_size(plab_sz); 104 // Latch the result 105 _desired_net_plab_sz = plab_sz; 106 if (PrintPLAB) { 107 gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz); 108 } 109 } 110 if (PrintPLAB) { 111 gclog_or_tty->cr(); 112 } 113 // Clear accumulators for next round. 114 reset(); 115 } 116 | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/g1/g1EvacStats.hpp" 27 #include "gc/shared/gcId.hpp" 28 #include "logging/log.hpp" 29 #include "trace/tracing.hpp" 30 31 void G1EvacStats::adjust_desired_plab_sz() { 32 if (!ResizePLAB) { 33 log_debug(gc, plab)(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " " 34 "unused = " SIZE_FORMAT " used = " SIZE_FORMAT " " 35 "undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT " " 36 "regions filled = %u direct_allocated = " SIZE_FORMAT " " 37 "failure_used = " SIZE_FORMAT " failure_waste = " SIZE_FORMAT ") ", 38 _allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste, 39 _regions_filled, _direct_allocated, _failure_used, _failure_waste); 40 // Clear accumulators for next round. 41 reset(); 42 return; 43 } 44 45 assert(is_object_aligned(max_size()) && min_size() <= max_size(), 46 "PLAB clipping computation may be incorrect"); 47 48 if (_allocated == 0) { 49 assert((_unused == 0), 50 "Inconsistency in PLAB stats: " 51 "_allocated: " SIZE_FORMAT ", " 52 "_wasted: " SIZE_FORMAT ", " 53 "_region_end_waste: " SIZE_FORMAT ", " 54 "_unused: " SIZE_FORMAT ", " 55 "_used : " SIZE_FORMAT, 56 _allocated, _wasted, _region_end_waste, _unused, used()); 57 _allocated = 1; 58 } 59 // The size of the PLAB caps the amount of space that can be wasted at the 60 // end of the collection. In the worst case the last PLAB could be completely 61 // empty. 62 // This allows us to calculate the new PLAB size to achieve the 63 // TargetPLABWastePct given the latest memory usage and that the last buffer 64 // will be G1LastPLABAverageOccupancy full. 88 // 89 // We need to cover overflow when calculating the amount of space actually used 90 // by objects in PLABs when subtracting the region end waste. 91 // Region end waste may be higher than actual allocation. This may occur if many 92 // threads do not allocate anything but a few rather large objects. In this 93 // degenerate case the PLAB size would simply quickly tend to minimum PLAB size, 94 // which is an okay reaction. 95 size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; 96 97 size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct; 98 size_t const cur_plab_sz = (size_t)((double)total_waste_allowed / G1LastPLABAverageOccupancy); 99 // Take historical weighted average 100 _filter.sample(cur_plab_sz); 101 // Clip from above and below, and align to object boundary 102 size_t plab_sz; 103 plab_sz = MAX2(min_size(), (size_t)_filter.average()); 104 plab_sz = MIN2(max_size(), plab_sz); 105 plab_sz = align_object_size(plab_sz); 106 // Latch the result 107 _desired_net_plab_sz = plab_sz; 108 109 log_debug(gc, plab)(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " " 110 "unused = " SIZE_FORMAT " used = " SIZE_FORMAT " " 111 "undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT " " 112 "regions filled = %u direct_allocated = " SIZE_FORMAT " " 113 "failure_used = " SIZE_FORMAT " failure_waste = " SIZE_FORMAT ") " 114 " (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ")", 115 _allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste, 116 _regions_filled, _direct_allocated, _failure_used, _failure_waste, 117 cur_plab_sz, plab_sz); 118 119 // Clear accumulators for next round. 120 reset(); 121 } 122 |