!1733 GEN GC throughput fix

Merge pull request !1733 from Malinin Andrey/gengc_test
This commit is contained in:
openharmony_ci 2024-07-03 12:49:26 +00:00 committed by Gitee
commit e97b60a51e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 14 additions and 52 deletions

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef LIBPANDABASE_UTILS_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H
#define LIBPANDABASE_UTILS_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H
#ifndef LIBPANDABASE_MEM_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H
#define LIBPANDABASE_MEM_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H
#include <algorithm>
#include "libpandabase/macros.h"
@ -35,39 +35,24 @@ public:
ASSERT(maxGrowRatio_ > 1.0);
}
void StoreNewSampleAndIncreaseIfNeeded(size_t occupiedSize, size_t maxSize)
void StoreNewSample(size_t occupiedSize, size_t maxSize)
{
// Supposed that this method is called only in case of slow path
ASSERT(occupiedSize <= maxSize);
samples_.emplace_back(std::make_pair(occupiedSize, maxSize));
if (slowAllocationCount_ > SLOW_ALLOCATION_THRESHOLD) {
// There are too many slow paths taken by compiler
// It is better to increase lastCountedSum_ immediately
static constexpr float INCREASE_RATE = 2.0;
lastCountedSum_ = std::clamp(lastCountedSum_ * INCREASE_RATE, lowerSumBorder_, upperSumBorder_);
}
}
/**
* @brief Estimates new TLAB size using saved TLABs' information
*
* 1) First of all it checks if we have allocated too many (>= THRESHOLD_COUNT) TLABs
* In that case we increase size by (samples_.size() / THRESHOLD_COUNT)
* In other case go to ----> 2)
* 2) If vector with samples is not empty, we start estimating TLABs' average fill fraction
* If average fill fraction is less than desiredFillFraction_, then we increase TLABs' size
* Else, we reduce TLABs' size
* If vector with samples is not empty, we start estimating TLABs' average fill fraction
* If average fill fraction is less than desiredFillFraction_, then we increase TLABs' size
* Else, we reduce TLABs' size
*/
void ComputeNewSumAndResetSamples()
{
float newCountedSum = lastCountedSum_;
if (samples_.size() >= THRESHOLD_COUNT) {
// In this case we have a lot of allocated TLABs
// So, we should consider increasing lastCountedSum_
// Also need to mind grow ratio (for softer increase/decrease of the sum)
newCountedSum = std::clamp(lastCountedSum_ * (static_cast<float>(samples_.size()) / THRESHOLD_COUNT),
lastCountedSum_ / maxGrowRatio_, lastCountedSum_ * maxGrowRatio_);
} else if (!samples_.empty()) {
if (!samples_.empty()) {
float averageFillFraction = -1.0;
// Average fill fraction estimation
for (auto &sample : samples_) {
@ -97,20 +82,9 @@ public:
// Mind lower and upper borders
lastCountedSum_ =
std::clamp(newCountedSum * weight_ + lastCountedSum_ * (1.0F - weight_), lowerSumBorder_, upperSumBorder_);
slowAllocationCount_ = 0;
samples_.clear();
}
void IncreaseSlowAllocationCount()
{
++slowAllocationCount_;
}
size_t GetSlowAllocationCount() const
{
return slowAllocationCount_;
}
float GetLastCountedSum() const
{
return lastCountedSum_;
@ -122,11 +96,7 @@ public:
return static_cast<size_t>(lastCountedSum_);
}
static constexpr size_t SLOW_ALLOCATION_THRESHOLD = 3; // Value used for force increase of lastCountedSum_
private:
static constexpr size_t THRESHOLD_COUNT = 4; // Threshold value showing that we have allocated
// a lot of TLABs between GC pauses
static constexpr float REDUCTION_RATE = 0.75; // Value used for size reduction
float maxGrowRatio_; // Max change ratio when new average is estimated
// (means that (newAverage / average) < maxGrowRatio_)
@ -139,10 +109,8 @@ private:
float desiredFillFraction_; // From 0 to 1
// If (occupiedSize / maxSize) < desiredFillFraction_ then
// lastCountedSum_ should grow
size_t slowAllocationCount_ = 0; // Used for force increase of lastCountedSum_
// if slowAllocationCount_ > SLOW_ALLOCATION_THRESHOLD
PandaVector<std::pair<size_t, size_t>> samples_; // Saved samples. Used for estimation of a new sum
};
} // namespace ark
#endif // LIBPANDABASE_UTILS_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H
#endif // LIBPANDABASE_MEM_WEIGHTED_ADAPTIVE_TLAB_AVERAGE_H

View File

@ -24,12 +24,12 @@
#include "libpandabase/mem/gc_barrier.h"
#include "libpandabase/mem/ringbuf/lock_free_ring_buffer.h"
#include "libpandabase/mem/weighted_adaptive_tlab_average.h"
#include "libpandabase/os/mutex.h"
#include "libpandabase/os/thread.h"
#include "libpandabase/utils/arch.h"
#include "libpandabase/utils/list.h"
#include "libpandabase/utils/tsan_interface.h"
#include "libpandabase/utils/weighted_adaptive_tlab_average.h"
#include "runtime/include/mem/panda_containers.h"
#include "runtime/include/mem/panda_smart_pointers.h"
#include "runtime/include/object_header-inl.h"

View File

@ -173,17 +173,12 @@ void *HeapManager::AllocateMemoryForObject(size_t size, Alignment align, Managed
if (UseTLABForAllocations() && size <= GetTLABMaxAllocSize() && !pinned) {
ASSERT(thread != nullptr);
ASSERT(GetGC()->IsTLABsSupported());
if (isAdaptiveTlabSize_) {
thread->GetWeightedTlabAverage()->IncreaseSlowAllocationCount();
}
// Try to allocate an object via TLAB
TLAB *currentTlab = thread->GetTLAB();
ASSERT(currentTlab != nullptr); // A thread's TLAB must be initialized at least via some ZERO tlab values.
mem = currentTlab->Alloc(size);
bool shouldAllocNewTlab = !isAdaptiveTlabSize_ ||
currentTlab->GetFillFraction() >= TLAB::MIN_DESIRED_FILL_FRACTION ||
thread->GetWeightedTlabAverage()->GetSlowAllocationCount() >=
WeightedAdaptiveTlabAverage::SLOW_ALLOCATION_THRESHOLD;
bool shouldAllocNewTlab =
!isAdaptiveTlabSize_ || currentTlab->GetFillFraction() >= TLAB::MIN_DESIRED_FILL_FRACTION;
if (mem == nullptr && shouldAllocNewTlab) {
// We couldn't allocate an object via current TLAB,
// Therefore, create a new one and allocate in it.
@ -284,8 +279,7 @@ bool HeapManager::CreateNewTLAB(ManagedThread *thread)
// Using initial tlab size
newTlabSize = Runtime::GetOptions().GetInitTlabSize();
} else {
thread->GetWeightedTlabAverage()->StoreNewSampleAndIncreaseIfNeeded(oldTlab->GetOccupiedSize(),
oldTlab->GetSize());
thread->GetWeightedTlabAverage()->StoreNewSample(oldTlab->GetOccupiedSize(), oldTlab->GetSize());
newTlabSize = AlignUp(thread->GetWeightedTlabAverage()->GetLastCountedSumInSizeT(), DEFAULT_ALIGNMENT_IN_BYTES);
}
LOG(DEBUG, ALLOC) << "Allocating new tlab with size: " << newTlabSize;

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -88,7 +88,7 @@ void TLAB::IterateOverObjectsInRange(const std::function<void(ObjectHeader *obje
const MemRange &memRange)
{
LOG_TLAB_ALLOCATOR(DEBUG) << "IterateOverObjectsInRange started";
if (!GetMemRangeForOccupiedMemory().IsIntersect(memRange)) {
if (GetOccupiedSize() == 0 || !GetMemRangeForOccupiedMemory().IsIntersect(memRange)) {
return;
}
void *currentPtr = memoryStartAddr_;