/* * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #include "precompiled.hpp" #include "gc_implementation/g1/g1EvacStats.hpp" void G1EvacStats::adjust_desired_plab_sz(uint no_of_gc_workers) { if (PrintPLAB) { gclog_or_tty->print(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " " "unused = " SIZE_FORMAT " used = " SIZE_FORMAT " " "undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT" " "regions filled = %u inline_allocated = " SIZE_FORMAT") ", _allocated, _wasted, _unused, used(), _undo_waste, _region_end_waste, _regions_filled, _inline_allocated); } if (ResizePLAB) { assert(is_object_aligned(max_size()) && min_size() <= max_size(), "PLAB clipping computation may be incorrect"); if (_allocated == 0) { assert((_unused == 0), err_msg("Inconsistency in PLAB stats: " "_allocated: "SIZE_FORMAT", " "_wasted: "SIZE_FORMAT", " "_region_end_waste: "SIZE_FORMAT", " "_unused: "SIZE_FORMAT", " "_used : "SIZE_FORMAT, _allocated, _wasted, _region_end_waste, _unused, used())); _allocated = 1; } // Calculate the new PLAB size as the amount of space that could be wasted to // keep TargetPLABWastePct given latest memory usage, the amount of GC workers, // and that the last buffer will be half full (TargetSurvivorRatio). // // E.g. assume that we used 100 words and a TargetPLABWastePct of 10. If we had // one thread, we could waste up to 10 words to meet that percentage. Given that // we also assume that that buffer is typically half-full, the new desired PLAB size // is 20 words (because we use a single worker thread). // // We account region end waste fully to PLAB allocation (in the calculation of // what we consider as "used" below). This is not completely fair, but is a // conservative assumption because PLABs may be sized flexibly while we cannot // adjust inline allocations. // We need to cover overflow when calculating the amount of space actually used // by objects in PLABs when subtracting the region end waste. // This is a possible situation if many threads do not allocate anything but a // few rather large objects. In this degenerate case the PLAB size would simply quickly // tend to minimum PLAB size, which is an okay reaction. // Allocation during GC will try to minimize region end waste. size_t used_for_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; size_t cur_plab_sz = (used_for_calculation * TargetPLABWastePct) / (no_of_gc_workers * TargetSurvivorRatio); // Take historical weighted average _filter.sample(cur_plab_sz); // Clip from above and below, and align to object boundary size_t plab_sz; plab_sz = MAX2(min_size(), (size_t)_filter.average()); plab_sz = MIN2(max_size(), plab_sz); plab_sz = align_object_size(plab_sz); // Latch the result _desired_plab_sz = plab_sz; if (PrintPLAB) { gclog_or_tty->print_cr(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz); } } // Clear accumulators for next round. reset(); }