|
|
|
@ -234,7 +234,7 @@ namespace memory_quota_detail { |
|
|
|
|
// be) but to be eventually accurate.
|
|
|
|
|
class PressureTracker { |
|
|
|
|
public: |
|
|
|
|
double AddSampleAndGetEstimate(double sample); |
|
|
|
|
double AddSampleAndGetControlValue(double sample); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
std::atomic<double> max_this_round_{0.0}; |
|
|
|
@ -252,6 +252,17 @@ class PressureTracker { |
|
|
|
|
class BasicMemoryQuota final |
|
|
|
|
: public std::enable_shared_from_this<BasicMemoryQuota> { |
|
|
|
|
public: |
|
|
|
|
// Data about current memory pressure.
|
|
|
|
|
struct PressureInfo { |
|
|
|
|
// The current instantaneously measured memory pressure.
|
|
|
|
|
double instantaneous_pressure; |
|
|
|
|
// A control value that can be used to scale buffer sizes up or down to
|
|
|
|
|
// adjust memory pressure to our target set point.
|
|
|
|
|
double pressure_control_value; |
|
|
|
|
// Maximum recommended individual allocation size.
|
|
|
|
|
size_t max_recommended_allocation_size; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
explicit BasicMemoryQuota(std::string name) : name_(std::move(name)) {} |
|
|
|
|
|
|
|
|
|
// Start the reclamation activity.
|
|
|
|
@ -272,8 +283,7 @@ class BasicMemoryQuota final |
|
|
|
|
// Return some memory to the quota.
|
|
|
|
|
void Return(size_t amount); |
|
|
|
|
// Instantaneous memory pressure approximation.
|
|
|
|
|
std::pair<double, size_t> |
|
|
|
|
InstantaneousPressureAndMaxRecommendedAllocationSize(); |
|
|
|
|
PressureInfo GetPressureInfo(); |
|
|
|
|
// Get a reclamation queue
|
|
|
|
|
ReclaimerQueue* reclaimer_queue(size_t i) { return &reclaimers_[i]; } |
|
|
|
|
|
|
|
|
@ -352,9 +362,8 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl { |
|
|
|
|
void Shutdown() override; |
|
|
|
|
|
|
|
|
|
// Read the instantaneous memory pressure
|
|
|
|
|
double InstantaneousPressure() const { |
|
|
|
|
return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize() |
|
|
|
|
.first; |
|
|
|
|
BasicMemoryQuota::PressureInfo GetPressureInfo() const { |
|
|
|
|
return memory_quota_->GetPressureInfo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Name of this allocator
|
|
|
|
@ -434,8 +443,8 @@ class MemoryOwner final : public MemoryAllocator { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Instantaneous memory pressure in the underlying quota.
|
|
|
|
|
double InstantaneousPressure() const { |
|
|
|
|
return impl()->InstantaneousPressure(); |
|
|
|
|
BasicMemoryQuota::PressureInfo GetPressureInfo() const { |
|
|
|
|
return impl()->GetPressureInfo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T, typename... Args> |
|
|
|
@ -485,8 +494,8 @@ class MemoryQuota final |
|
|
|
|
// Return true if the instantaneous memory pressure is high.
|
|
|
|
|
bool IsMemoryPressureHigh() const { |
|
|
|
|
static constexpr double kMemoryPressureHighThreshold = 0.9; |
|
|
|
|
return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize() |
|
|
|
|
.first > kMemoryPressureHighThreshold; |
|
|
|
|
return memory_quota_->GetPressureInfo().pressure_control_value > |
|
|
|
|
kMemoryPressureHighThreshold; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|