< prev index next >

src/share/vm/gc_implementation/shenandoah/shenandoahPacer.cpp

Print this page
rev 10511 : Fix MacOS/Clang build failure
rev 10543 : [backport] Application pacing precision fixes
rev 10558 : [backport] Exponential backoff with pacing
rev 10559 : [backport] More detailed pacing histogram
rev 10563 : [backport] Pacer for evacuation should print "Avail" to capture discounting
rev 10566 : [backport] Pacer should account actual size for elastic TLABs
rev 10575 : Fix x86_32 build
rev 10599 : [backport] Convert magic value to ShenandoahPacingSurcharge
rev 10620 : [backport] Evac reserve: make sure GC has untouchable space to move the objects into

*** 33,48 **** * * Here, we do not know how large would be the collection set, and what are the * relative performances of the each stage in the concurrent cycle, and so we have to * make some assumptions. * ! * We assume, for pessimistic reasons, that the entire heap is full of alive objects, ! * and it will be evacuated fully. Therefore, we count live objects visited by all three ! * stages against the heap used at the beginning of the collection. That means if there ! * are dead objects, they would not be accounted for in this budget, and that would mean ! * allocation would be pacified excessively. But that *also* means the collection cycle ! * would finish earlier than pacer expects. * * The allocatable space when GC is running is "free" at the start of cycle, but the * accounted budget is based on "used". So, we need to adjust the tax knowing that. * Also, since we effectively count the used space three times (mark, evac, update-refs), * we need to multiply the tax by 3. Example: for 10 MB free and 90 MB used, GC would --- 33,54 ---- * * Here, we do not know how large would be the collection set, and what are the * relative performances of the each stage in the concurrent cycle, and so we have to * make some assumptions. * ! * For concurrent mark, there is no clear notion of progress. The moderately accurate ! * and easy to get metric is the amount of live objects the mark had encountered. But, ! * that does directly correlate with the used heap, because the heap might be fully ! * dead or fully alive. We cannot assume either of the extremes: we would either allow ! * application to run out of memory if we assume heap is fully dead but it is not, and, ! * conversely, we would pacify application excessively if we assume heap is fully alive ! * but it is not. So we need to guesstimate the particular expected value for heap liveness. ! * The best way to do this is apparently recording the past history. ! * ! * For concurrent evac and update-refs, we are walking the heap per-region, and so the ! * notion of progress is clear: we get reported the "used" size from the processed regions ! * and use the global heap-used as the baseline. * * The allocatable space when GC is running is "free" at the start of cycle, but the * accounted budget is based on "used". So, we need to adjust the tax knowing that. * Also, since we effectively count the used space three times (mark, evac, update-refs), * we need to multiply the tax by 3. Example: for 10 MB free and 90 MB used, GC would
*** 51,97 **** */ void ShenandoahPacer::setup_for_mark() { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! size_t used = _heap->used(); size_t free = _heap->free_set()->available(); size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; ! double tax = 1.0 * used / taxable; // base tax for available free space tax *= 3; // mark is phase 1 of 3, claim 1/3 of free for it ! tax = MAX2<double>(1, tax); // never allocate more than GC collects during the cycle ! tax *= 1.1; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Mark. Used: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", ! used / M, free / M, non_taxable / M, tax); } void ShenandoahPacer::setup_for_evac() { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! size_t cset = _heap->collection_set()->live_data(); size_t free = _heap->free_set()->available(); size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; ! double tax = 1.0 * cset / taxable; // base tax for available free space tax *= 2; // evac is phase 2 of 3, claim 1/2 of remaining free ! tax = MAX2<double>(1, tax); // never allocate more than GC collects during the cycle ! tax *= 1.1; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Evacuation. CSet: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", ! cset / M, free / M, non_taxable / M, tax); } void ShenandoahPacer::setup_for_updaterefs() { assert(ShenandoahPacing, "Only be here when pacing is enabled"); --- 57,102 ---- */ void ShenandoahPacer::setup_for_mark() { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! size_t live = update_and_get_progress_history(); size_t free = _heap->free_set()->available(); size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; ! double tax = 1.0 * live / taxable; // base tax for available free space tax *= 3; // mark is phase 1 of 3, claim 1/3 of free for it ! tax *= ShenandoahPacingSurcharge; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Mark. Expected Live: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", ! live / M, free / M, non_taxable / M, tax); } void ShenandoahPacer::setup_for_evac() { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! size_t used = _heap->collection_set()->used(); size_t free = _heap->free_set()->available(); size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; ! double tax = 1.0 * used / taxable; // base tax for available free space tax *= 2; // evac is phase 2 of 3, claim 1/2 of remaining free ! tax = MAX2<double>(1, tax); // never allocate more than GC processes during the phase ! tax *= ShenandoahPacingSurcharge; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Evacuation. Used CSet: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", ! used / M, free / M, non_taxable / M, tax); } void ShenandoahPacer::setup_for_updaterefs() { assert(ShenandoahPacing, "Only be here when pacing is enabled");
*** 101,116 **** size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; double tax = 1.0 * used / taxable; // base tax for available free space tax *= 1; // update-refs is phase 3 of 3, claim the remaining free ! tax = MAX2<double>(1, tax); // never allocate more than GC collects during the cycle ! tax *= 1.1; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Update-Refs. Used: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", used / M, free / M, non_taxable / M, tax); } /* --- 106,121 ---- size_t non_taxable = free * ShenandoahPacingCycleSlack / 100; size_t taxable = free - non_taxable; double tax = 1.0 * used / taxable; // base tax for available free space tax *= 1; // update-refs is phase 3 of 3, claim the remaining free ! tax = MAX2<double>(1, tax); // never allocate more than GC processes during the phase ! tax *= ShenandoahPacingSurcharge; // additional surcharge to help unclutter heap restart_with(non_taxable, tax); ! log_info(gc, ergo)("Pacer for Update Refs. Used: " SIZE_FORMAT "M, Free: " SIZE_FORMAT "M, Non-Taxable: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", used / M, free / M, non_taxable / M, tax); } /*
*** 132,155 **** log_info(gc, ergo)("Pacer for Idle. Initial: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", initial / M, tax); } void ShenandoahPacer::restart_with(jlong non_taxable_bytes, jdouble tax_rate) { STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t)); ! intptr_t initial = (size_t)(non_taxable_bytes * tax_rate) >> LogHeapWordSize; intptr_t cur; do { cur = OrderAccess::load_acquire(&_budget); } while (Atomic::cmpxchg(initial, &_budget, cur) != cur); OrderAccess::release_store(&_tax_rate, tax_rate); } bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! intptr_t tax = MAX2<intptr_t>(1, words * OrderAccess::load_acquire(&_tax_rate)); intptr_t cur = 0; intptr_t new_val = 0; do { cur = OrderAccess::load_acquire(&_budget); --- 137,184 ---- log_info(gc, ergo)("Pacer for Idle. Initial: " SIZE_FORMAT "M, Alloc Tax Rate: %.1fx", initial / M, tax); } + size_t ShenandoahPacer::update_and_get_progress_history() { + if (_progress == -1) { + // First initialization, report some prior + Atomic::store((intptr_t)PACING_PROGRESS_ZERO, &_progress); + return (size_t) (_heap->capacity() * 0.1); + } else { + // Record history, and reply historical data + _progress_history->add(_progress); + Atomic::store((intptr_t)PACING_PROGRESS_ZERO, &_progress); + return (size_t) (_progress_history->avg() * HeapWordSize); + } + } + void ShenandoahPacer::restart_with(jlong non_taxable_bytes, jdouble tax_rate) { STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t)); ! { ! intptr_t initial = (size_t) (non_taxable_bytes * tax_rate) >> LogHeapWordSize; intptr_t cur; do { cur = OrderAccess::load_acquire(&_budget); } while (Atomic::cmpxchg(initial, &_budget, cur) != cur); + } + OrderAccess::release_store(&_tax_rate, tax_rate); + + { + intptr_t cur, val; + do { + cur = OrderAccess::load_acquire(&_epoch); + val = cur + 1; + } while (Atomic::cmpxchg(val, &_epoch, cur) != cur); + } } bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); ! intptr_t tax = MAX2<intptr_t>(1, (intptr_t)(words * OrderAccess::load_acquire(&_tax_rate))); intptr_t cur = 0; intptr_t new_val = 0; do { cur = OrderAccess::load_acquire(&_budget);
*** 160,202 **** new_val = cur - tax; } while (Atomic::cmpxchg(new_val, &_budget, cur) != cur); return true; } void ShenandoahPacer::pace_for_alloc(size_t words) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); // Fast path: try to allocate right away if (claim_for_alloc(words, false)) { return; } ! size_t max_wait_ms = ShenandoahPacingMaxDelay; double start = os::elapsedTime(); while (true) { // We could instead assist GC, but this would suffice for now. // This code should also participate in safepointing. ! os::sleep(Thread::current(), 1, true); double end = os::elapsedTime(); ! size_t ms = (size_t)((end - start) * 1000); ! if (ms > max_wait_ms) { // Spent local time budget to wait for enough GC progress. // Breaking out and allocating anyway, which may mean we outpace GC, // and start Degenerated GC cycle. ! _delays.add(ms); // Forcefully claim the budget: it may go negative at this point, and // GC should replenish for this and subsequent allocations claim_for_alloc(words, true); break; } if (claim_for_alloc(words, false)) { // Acquired enough permit, nice. Can allocate now. ! _delays.add(ms); break; } } } --- 189,259 ---- new_val = cur - tax; } while (Atomic::cmpxchg(new_val, &_budget, cur) != cur); return true; } + void ShenandoahPacer::unpace_for_alloc(intptr_t epoch, size_t words) { + assert(ShenandoahPacing, "Only be here when pacing is enabled"); + + if (_epoch != epoch) { + // Stale ticket, no need to unpace. + return; + } + + intptr_t tax = MAX2<intptr_t>(1, (intptr_t)(words * OrderAccess::load_acquire(&_tax_rate))); + Atomic::add(tax, &_budget); + } + + intptr_t ShenandoahPacer::epoch() { + return OrderAccess::load_acquire(&_epoch); + } + void ShenandoahPacer::pace_for_alloc(size_t words) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); // Fast path: try to allocate right away if (claim_for_alloc(words, false)) { return; } ! size_t max = ShenandoahPacingMaxDelay; double start = os::elapsedTime(); + size_t total = 0; + size_t cur = 0; + while (true) { // We could instead assist GC, but this would suffice for now. // This code should also participate in safepointing. ! // Perform the exponential backoff, limited by max. ! ! cur = cur * 2; ! if (total + cur > max) { ! cur = (max > total) ? (max - total) : 0; ! } ! cur = MAX2<size_t>(1, cur); ! ! os::sleep(Thread::current(), cur, true); double end = os::elapsedTime(); ! total = (size_t)((end - start) * 1000); ! ! if (total > max) { // Spent local time budget to wait for enough GC progress. // Breaking out and allocating anyway, which may mean we outpace GC, // and start Degenerated GC cycle. ! _delays.add(total); // Forcefully claim the budget: it may go negative at this point, and // GC should replenish for this and subsequent allocations claim_for_alloc(words, true); break; } if (claim_for_alloc(words, false)) { // Acquired enough permit, nice. Can allocate now. ! _delays.add(total); break; } } }
*** 214,225 **** out->cr(); out->print_cr("Actual pacing delays histogram:"); out->cr(); ! out->print_cr("%10s - %10s %12s", "From", "To", "Count"); for (int c = _delays.min_level(); c <= _delays.max_level(); c++) { ! out->print("%7d ms - %7d ms:", (c == 0) ? 0 : 1 << (c - 1), 1 << c); ! out->print_cr(SIZE_FORMAT_W(12), _delays.level(c)); } out->cr(); } --- 271,292 ---- out->cr(); out->print_cr("Actual pacing delays histogram:"); out->cr(); ! out->print_cr("%10s - %10s %12s%12s", "From", "To", "Count", "Sum"); ! ! size_t total_count = 0; ! size_t total_sum = 0; for (int c = _delays.min_level(); c <= _delays.max_level(); c++) { ! int l = (c == 0) ? 0 : 1 << (c - 1); ! int r = 1 << c; ! size_t count = _delays.level(c); ! size_t sum = count * (r - l) / 2; ! total_count += count; ! total_sum += sum; ! ! out->print_cr("%7d ms - %7d ms: " SIZE_FORMAT_W(12) SIZE_FORMAT_W(12) " ms", l, r, count, sum); } + out->print_cr("%23s: " SIZE_FORMAT_W(12) SIZE_FORMAT_W(12) " ms", "Total", total_count, total_sum); out->cr(); }
< prev index next >