Go to the documentation of this file.
15 #ifndef GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
16 #define GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
29 #include "absl/base/thread_annotations.h"
30 #include "absl/strings/string_view.h"
31 #include "absl/types/optional.h"
45 class BasicMemoryQuota;
132 template <
typename F>
157 void MarkCancelled();
163 template <
typename F>
193 template <
typename F>
224 :
public std::enable_shared_from_this<BasicMemoryQuota> {
240 void Take(
size_t amount);
244 void Return(
size_t amount);
246 std::pair<double, size_t>
301 size_t prev_free =
free_bytes_.fetch_add(
n, std::memory_order_release);
306 if (prev_free != 0)
return;
311 template <
typename F>
323 return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize()
348 reclamation_handles_[pass] =
385 explicit MemoryOwner(std::shared_ptr<GrpcMemoryAllocatorImpl> allocator)
389 template <
typename F>
399 template <
typename T,
typename...
Args>
445 static constexpr
double kMemoryPressureHighThreshold = 0.9;
446 return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize()
447 .first > kMemoryPressureHighThreshold;
462 #endif // GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
std::atomic< intptr_t > free_bytes_
Sweep(std::shared_ptr< State > state)
MemoryOwner CreateMemoryOwner(absl::string_view name)
std::shared_ptr< State > state_
#define GPR_DEBUG_ASSERT(x)
double InstantaneousPressure() const
ActivityPtr reclaimer_activity_
MemoryOwner(std::shared_ptr< GrpcMemoryAllocatorImpl > allocator)
Handle & operator=(const Handle &)=delete
ReclaimerQueue reclaimers_[kNumReclamationPasses]
absl::string_view name() const
MemoryQuotaRefPtr MakeMemoryQuota(std::string name)
ReclaimerQueue & operator=(const ReclaimerQueue &)=delete
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_event_engine::experimental::internal::MemoryAllocatorImpl EventEngineMemoryAllocatorImpl
std::shared_ptr< BasicMemoryQuota > memory_quota_
void MaybeRegisterReclaimer() ABSL_LOCKS_EXCLUDED(reclaimer_mu_)
void PostReclaimer(ReclamationPass pass, F fn)
double InstantaneousPressure() const
void SetSize(size_t new_size)
void PostReclaimer(ReclamationPass pass, F fn)
void Release(size_t n) override
bool IsMemoryPressureHigh() const
bool IsSufficient() const
absl::string_view name() const
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
void Run(ReclamationSweep reclamation_sweep)
constexpr bool has_value() const noexcept
std::shared_ptr< BasicMemoryQuota > memory_quota_
size_t Reserve(MemoryRequest request) override
SweepFn(F &&f, std::shared_ptr< State > state)
GRPC_MUST_USE_RESULT NextPromise Next()
const std::shared_ptr< BasicMemoryQuota > memory_quota_
void FinishReclamation(uint64_t token, Waker waker)
RefCountedPtr< Handle > Ref() GRPC_MUST_USE_RESULT
Poll< RefCountedPtr< Handle > > operator()()
#define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...)
unsigned __int64 uint64_t
static constexpr intptr_t kInitialSize
GrpcMemoryAllocatorImpl(std::shared_ptr< BasicMemoryQuota > memory_quota, std::string name)
OrphanablePtr< Activity > ActivityPtr
std::pair< double, size_t > InstantaneousPressureAndMaxRecommendedAllocationSize() const
std::shared_ptr< MemoryQuota > MemoryQuotaRefPtr
internal::MemoryAllocatorImpl * get_internal_impl_ptr()
NextPromise(ReclaimerQueue *queue)
void SetSize(size_t new_size)
std::atomic< uint64_t > reclamation_counter_
std::atomic< size_t > free_bytes_
GRPC_MUST_USE_RESULT OrphanablePtr< Handle > Insert(F reclaimer)
OrphanablePtr< T > MakeOrphanable(Args &&... args)
Handle(F reclaimer, std::shared_ptr< State > state)
std::atomic< bool > registered_reclaimer_
std::atomic< size_t > taken_bytes_
void Enqueue(RefCountedPtr< Handle > handle)
ReclamationSweep()=default
absl::optional< size_t > TryReserve(MemoryRequest request) GRPC_MUST_USE_RESULT
#define ABSL_LOCKS_EXCLUDED(...)
GrpcMemoryAllocatorImpl * impl()
Poll< RefCountedPtr< Handle > > PollNext()
std::unique_ptr< T, Deleter > OrphanablePtr
ReclamationSweep(std::shared_ptr< BasicMemoryQuota > memory_quota, uint64_t sweep_token, Waker waker)
bool shutdown_ ABSL_GUARDED_BY(reclaimer_mu_)
void RunAndDelete(absl::optional< ReclamationSweep > sweep) override
std::atomic< size_t > quota_size_
BasicMemoryQuota(std::string name)
static constexpr size_t kNumReclamationPasses
bool Requeue(ReclaimerQueue *new_queue)
absl::string_view name() const
MemoryQuota & operator=(const MemoryQuota &)=delete
std::shared_ptr< State > state_
void InsertReclaimer(size_t pass, F fn) ABSL_EXCLUSIVE_LOCKS_REQUIRED(reclaimer_mu_)
MemoryQuota(std::string name)
ReclamationSweep & operator=(const ReclamationSweep &)=delete
~GrpcMemoryAllocatorImpl() override
std::atomic< Sweep * > sweep_
void Return(size_t amount)
Reservation request - how much memory do we want to allocate?
static constexpr size_t kMaxQuotaBufferSize
MemoryAllocator CreateMemoryAllocator(absl::string_view name) override
ReclaimerQueue * reclaimer_queue(size_t i)
const GrpcMemoryAllocatorImpl * impl() const
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:23