memory_quota.h
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
16 #define GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
17 
19 
20 #include <stdint.h>
21 
22 #include <atomic>
23 #include <cstddef>
24 #include <limits>
25 #include <memory>
26 #include <string>
27 #include <utility>
28 
29 #include "absl/base/thread_annotations.h"
30 #include "absl/strings/string_view.h"
31 #include "absl/types/optional.h"
32 
35 #include <grpc/support/log.h>
36 
42 
43 namespace grpc_core {
44 
45 class BasicMemoryQuota;
46 class MemoryQuota;
47 
49 
50 // Pull in impl under a different name to keep the gRPC/EventEngine separation
51 // clear.
55 template <typename T>
57 
58 // Reclamation passes.
59 // When memory is tight, we start trying to claim some back from memory
60 // reclaimers. We do this in multiple passes: if there is a less destructive
61 // operation available, we do that, otherwise we do something more destructive.
62 enum class ReclamationPass {
63  // Non-empty reclamation ought to take index 0, but to simplify API we don't
64  // expose that publicly (it's an internal detail), and hence index zero is
65  // here unnamed.
66 
67  // Benign reclamation is intended for reclamation steps that are not
68  // observable outside of gRPC (besides maybe causing an increase in CPU
69  // usage).
70  // Examples of such reclamation would be resizing buffers to fit the current
71  // load needs, rather than whatever was the peak usage requirement.
72  kBenign = 1,
73  // Idle reclamation is intended for reclamation steps that are observable
74  // outside of gRPC, but do not cause application work to be lost.
75  // Examples of such reclamation would be dropping channels that are not being
76  // used.
77  kIdle = 2,
78  // Destructive reclamation is our last resort, and is these reclamations are
79  // allowed to drop work - such as cancelling in flight requests.
80  kDestructive = 3,
81 };
82 static constexpr size_t kNumReclamationPasses = 4;
83 static constexpr size_t kMaxQuotaBufferSize = 1024 * 1024;
84 
85 // For each reclamation function run we construct a ReclamationSweep.
86 // When this object is finally destroyed (it may be moved several times first),
87 // then that reclamation is complete and we may continue the reclamation loop.
89  public:
90  ReclamationSweep() = default;
91  ReclamationSweep(std::shared_ptr<BasicMemoryQuota> memory_quota,
92  uint64_t sweep_token, Waker waker)
93  : memory_quota_(std::move(memory_quota)),
94  sweep_token_(sweep_token),
95  waker_(std::move(waker)) {}
97 
98  ReclamationSweep(const ReclamationSweep&) = delete;
100  ReclamationSweep(ReclamationSweep&&) = default;
102 
103  // Has enough work been done that we would not be called upon again
104  // immediately to do reclamation work if we stopped and requeued. Reclaimers
105  // with a variable amount of work to do can use this to ascertain when they
106  // can stop more efficiently than going through the reclaimer queue once per
107  // work item.
108  bool IsSufficient() const;
109 
110  // Explicit finish for users that wish to write it.
111  // Just destroying the object is enough, but sometimes the additional
112  // explicitness is warranted.
113  void Finish() {
114  [](ReclamationSweep) {}(std::move(*this));
115  }
116 
117  private:
118  std::shared_ptr<BasicMemoryQuota> memory_quota_;
121 };
122 
124  private:
125  struct QueuedNode;
126  struct State;
127 
128  public:
129  class Handle : public InternallyRefCounted<Handle> {
130  public:
131  Handle() = default;
132  template <typename F>
133  explicit Handle(F reclaimer, std::shared_ptr<State> state)
134  : sweep_(new SweepFn<F>(std::move(reclaimer), std::move(state))) {}
135  ~Handle() override {
136  GPR_DEBUG_ASSERT(sweep_.load(std::memory_order_relaxed) == nullptr);
137  }
138 
139  Handle(const Handle&) = delete;
140  Handle& operator=(const Handle&) = delete;
141 
142  void Orphan() final;
143  void Run(ReclamationSweep reclamation_sweep);
144  bool Requeue(ReclaimerQueue* new_queue);
145 
146  private:
147  friend class ReclaimerQueue;
149 
150  class Sweep {
151  public:
152  virtual void RunAndDelete(absl::optional<ReclamationSweep> sweep) = 0;
153 
154  protected:
155  explicit Sweep(std::shared_ptr<State> state) : state_(std::move(state)) {}
156  ~Sweep() = default;
157  void MarkCancelled();
158 
159  private:
160  std::shared_ptr<State> state_;
161  };
162 
163  template <typename F>
164  class SweepFn final : public Sweep {
165  public:
166  explicit SweepFn(F&& f, std::shared_ptr<State> state)
167  : Sweep(std::move(state)), f_(std::move(f)) {}
169  if (!sweep.has_value()) MarkCancelled();
170  f_(std::move(sweep));
171  delete this;
172  }
173 
174  private:
175  F f_;
176  };
177 
178  std::atomic<Sweep*> sweep_{nullptr};
179  };
180 
181  ReclaimerQueue();
182  ~ReclaimerQueue();
183 
184  ReclaimerQueue(const ReclaimerQueue&) = delete;
185  ReclaimerQueue& operator=(const ReclaimerQueue&) = delete;
186 
187  // Insert a new element at the back of the queue.
188  // If there is already an element from allocator at *index, then it is
189  // replaced with the new reclaimer and *index is unchanged. If there is not,
190  // then *index is set to the index of the newly queued entry.
191  // Associates the reclamation function with an allocator, and keeps that
192  // allocator alive, so that we can use the pointer as an ABA guard.
193  template <typename F>
195  auto p = MakeOrphanable<Handle>(std::move(reclaimer), state_);
196  Enqueue(p->Ref());
197  return p;
198  }
199 
200  // Poll to see if an entry is available: returns Pending if not, or the
201  // removed reclamation function if so.
203 
204  // This callable is the promise backing Next - it resolves when there is an
205  // entry available. This really just redirects to calling PollNext().
206  class NextPromise {
207  public:
210 
211  private:
212  // Borrowed ReclaimerQueue backing this promise.
214  };
216 
217  private:
219 
220  std::shared_ptr<State> state_;
221 };
222 
223 class BasicMemoryQuota final
224  : public std::enable_shared_from_this<BasicMemoryQuota> {
225  public:
227 
228  // Start the reclamation activity.
229  void Start();
230  // Stop the reclamation activity.
231  // Until reclamation is stopped, it's possible that circular references to the
232  // BasicMemoryQuota remain. i.e. to guarantee deletion, a singular owning
233  // object should call BasicMemoryQuota::Stop().
234  void Stop();
235 
236  // Resize the quota to new_size.
237  void SetSize(size_t new_size);
238  // Forcefully take some memory from the quota, potentially entering
239  // overcommit.
240  void Take(size_t amount);
241  // Finish reclamation pass.
242  void FinishReclamation(uint64_t token, Waker waker);
243  // Return some memory to the quota.
244  void Return(size_t amount);
245  // Instantaneous memory pressure approximation.
246  std::pair<double, size_t>
248  // Get a reclamation queue
249  ReclaimerQueue* reclaimer_queue(size_t i) { return &reclaimers_[i]; }
250 
251  // The name of this quota
252  absl::string_view name() const { return name_; }
253 
254  private:
255  friend class ReclamationSweep;
256  class WaitForSweepPromise;
257 
259 
260  // The amount of memory that's free in this quota.
261  // We use intptr_t as a reasonable proxy for ssize_t that's portable.
262  // We allow arbitrary overcommit and so this must allow negative values.
263  std::atomic<intptr_t> free_bytes_{kInitialSize};
264  // The total number of bytes in this quota.
265  std::atomic<size_t> quota_size_{kInitialSize};
266 
267  // Reclaimer queues.
269  // The reclaimer activity consumes reclaimers whenever we are in overcommit to
270  // try and get back under memory limits.
272  // Each time we do a reclamation sweep, we increment this counter and give it
273  // to the sweep in question. In this way, should we choose to cancel a sweep
274  // we can do so and not get confused when the sweep reports back that it's
275  // completed.
276  // We also increment this counter on completion of a sweep, as an indicator
277  // that the wait has ended.
278  std::atomic<uint64_t> reclamation_counter_{0};
279  // The name of this quota - used for debugging/tracing/etc..
281 };
282 
283 // MemoryAllocatorImpl grants the owner the ability to allocate memory from an
284 // underlying resource quota.
286  public:
287  explicit GrpcMemoryAllocatorImpl(
288  std::shared_ptr<BasicMemoryQuota> memory_quota, std::string name);
289  ~GrpcMemoryAllocatorImpl() override;
290 
291  // Reserve bytes from the quota.
292  // If we enter overcommit, reclamation will begin concurrently.
293  // Returns the number of bytes reserved.
294  size_t Reserve(MemoryRequest request) override;
295 
296  // Release some bytes that were previously reserved.
297  void Release(size_t n) override {
298  // Add the released memory to our free bytes counter... if this increases
299  // from 0 to non-zero, then we have more to do, otherwise, we're actually
300  // done.
301  size_t prev_free = free_bytes_.fetch_add(n, std::memory_order_release);
302  if (prev_free + n > kMaxQuotaBufferSize) {
303  // Try to immediately return some free'ed memory back to the total quota.
304  MaybeDonateBack();
305  }
306  if (prev_free != 0) return;
308  }
309 
310  // Post a reclamation function.
311  template <typename F>
313  MutexLock lock(&reclaimer_mu_);
315  InsertReclaimer(static_cast<size_t>(pass), std::move(fn));
316  }
317 
318  // Shutdown the allocator.
319  void Shutdown() override;
320 
321  // Read the instantaneous memory pressure
322  double InstantaneousPressure() const {
323  return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize()
324  .first;
325  }
326 
327  // Name of this allocator
328  absl::string_view name() const { return name_; }
329 
330  private:
331  // Primitive reservation function.
333  // This function may be invoked during a memory release operation. If the
334  // total free_bytes in this allocator/local cache exceeds
335  // kMaxQuotaBufferSize / 2, donate the excess free_bytes in this cache back
336  // to the total quota immediately. This helps prevent free bytes in any
337  // particular allocator from growing too large.
338  void MaybeDonateBack();
339  // Replenish bytes from the quota, without blocking, possibly entering
340  // overcommit.
341  void Replenish();
342  // If we have not already, register a reclamation function against the quota
343  // to sweep any free memory back to that quota.
345  template <typename F>
346  void InsertReclaimer(size_t pass, F fn)
348  reclamation_handles_[pass] =
349  memory_quota_->reclaimer_queue(pass)->Insert(std::move(fn));
350  }
351 
352  // Backing resource quota.
353  const std::shared_ptr<BasicMemoryQuota> memory_quota_;
354  // Amount of memory this allocator has cached for its own use: to avoid quota
355  // contention, each MemoryAllocator can keep some memory in addition to what
356  // it is immediately using, and the quota can pull it back under memory
357  // pressure.
358  std::atomic<size_t> free_bytes_{0};
359  // Amount of memory taken from the quota by this allocator.
360  std::atomic<size_t> taken_bytes_{sizeof(GrpcMemoryAllocatorImpl)};
361  std::atomic<bool> registered_reclaimer_{false};
364  // Indices into the various reclaimer queues, used so that we can cancel
365  // reclamation should we shutdown or get rebound.
367  reclamation_handles_[kNumReclamationPasses] ABSL_GUARDED_BY(
368  reclaimer_mu_);
369  // Name of this allocator.
371 };
372 
373 // MemoryOwner is an enhanced MemoryAllocator that can also reclaim memory, and
374 // be rebound to a different memory quota.
375 // Different modules should not share a MemoryOwner between themselves, instead
376 // each module that requires a MemoryOwner should create one from a resource
377 // quota. This is because the MemoryOwner reclaimers are tied to the
378 // MemoryOwner's lifetime, and are not queryable, so passing a MemoryOwner to a
379 // new owning module means that module cannot reason about which reclaimers are
380 // active, nor what they might do.
381 class MemoryOwner final : public MemoryAllocator {
382  public:
383  MemoryOwner() = default;
384 
385  explicit MemoryOwner(std::shared_ptr<GrpcMemoryAllocatorImpl> allocator)
386  : MemoryAllocator(std::move(allocator)) {}
387 
388  // Post a reclaimer for some reclamation pass.
389  template <typename F>
391  impl()->PostReclaimer(pass, std::move(fn));
392  }
393 
394  // Instantaneous memory pressure in the underlying quota.
395  double InstantaneousPressure() const {
396  return impl()->InstantaneousPressure();
397  }
398 
399  template <typename T, typename... Args>
401  return OrphanablePtr<T>(New<T>(std::forward<Args>(args)...));
402  }
403 
404  // Name of this object
405  absl::string_view name() const { return impl()->name(); }
406 
407  // Is this object valid (ie has not been moved out of or reset)
408  bool is_valid() const { return impl() != nullptr; }
409 
410  private:
411  const GrpcMemoryAllocatorImpl* impl() const {
412  return static_cast<const GrpcMemoryAllocatorImpl*>(get_internal_impl_ptr());
413  }
414 
416  return static_cast<GrpcMemoryAllocatorImpl*>(get_internal_impl_ptr());
417  }
418 };
419 
420 // MemoryQuota tracks the amount of memory available as part of a ResourceQuota.
421 class MemoryQuota final
423  public:
425  : memory_quota_(std::make_shared<BasicMemoryQuota>(std::move(name))) {
426  memory_quota_->Start();
427  }
428  ~MemoryQuota() override {
429  if (memory_quota_ != nullptr) memory_quota_->Stop();
430  }
431 
432  MemoryQuota(const MemoryQuota&) = delete;
433  MemoryQuota& operator=(const MemoryQuota&) = delete;
434  MemoryQuota(MemoryQuota&&) = default;
435  MemoryQuota& operator=(MemoryQuota&&) = default;
436 
439 
440  // Resize the quota to new_size.
441  void SetSize(size_t new_size) { memory_quota_->SetSize(new_size); }
442 
443  // Return true if the instantaneous memory pressure is high.
444  bool IsMemoryPressureHigh() const {
445  static constexpr double kMemoryPressureHighThreshold = 0.9;
446  return memory_quota_->InstantaneousPressureAndMaxRecommendedAllocationSize()
447  .first > kMemoryPressureHighThreshold;
448  }
449 
450  private:
451  friend class MemoryOwner;
452  std::shared_ptr<BasicMemoryQuota> memory_quota_;
453 };
454 
455 using MemoryQuotaRefPtr = std::shared_ptr<MemoryQuota>;
457  return std::make_shared<MemoryQuota>(std::move(name));
458 }
459 
460 } // namespace grpc_core
461 
462 #endif // GRPC_CORE_LIB_RESOURCE_QUOTA_MEMORY_QUOTA_H
grpc_core::BasicMemoryQuota::free_bytes_
std::atomic< intptr_t > free_bytes_
Definition: memory_quota.h:263
grpc_core::MemoryOwner
Definition: memory_quota.h:381
grpc_core::BasicMemoryQuota::Start
void Start()
Definition: memory_quota.cc:337
orphanable.h
log.h
grpc_core::BasicMemoryQuota::Stop
void Stop()
Definition: memory_quota.cc:402
grpc_core::ReclaimerQueue::Handle::Sweep::Sweep
Sweep(std::shared_ptr< State > state)
Definition: memory_quota.h:155
grpc_core::ReclaimerQueue::Handle::Handle
Handle()=default
grpc_core::MemoryQuota::CreateMemoryOwner
MemoryOwner CreateMemoryOwner(absl::string_view name)
Definition: memory_quota.cc:472
grpc_core::ReclaimerQueue::state_
std::shared_ptr< State > state_
Definition: memory_quota.h:220
grpc_core::ReclaimerQueue::Handle::Sweep
Definition: memory_quota.h:150
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:35
GPR_DEBUG_ASSERT
#define GPR_DEBUG_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:103
grpc_core::ReclamationPass::kIdle
@ kIdle
grpc_core::GrpcMemoryAllocatorImpl::InstantaneousPressure
double InstantaneousPressure() const
Definition: memory_quota.h:322
grpc_core::BasicMemoryQuota::reclaimer_activity_
ActivityPtr reclaimer_activity_
Definition: memory_quota.h:271
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
benchmark.request
request
Definition: benchmark.py:77
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::MemoryOwner::is_valid
bool is_valid() const
Definition: memory_quota.h:408
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::GrpcMemoryAllocatorImpl::MaybeDonateBack
void MaybeDonateBack()
Definition: memory_quota.cc:250
binary_size.new_size
def new_size
Definition: binary_size.py:124
grpc_core::MemoryOwner::MemoryOwner
MemoryOwner(std::shared_ptr< GrpcMemoryAllocatorImpl > allocator)
Definition: memory_quota.h:385
grpc_core::GrpcMemoryAllocatorImpl
Definition: memory_quota.h:285
grpc_core::ReclaimerQueue::Handle::SweepFn::f_
F f_
Definition: memory_quota.h:175
grpc_core::ReclaimerQueue::Handle::operator=
Handle & operator=(const Handle &)=delete
grpc_core::BasicMemoryQuota::reclaimers_
ReclaimerQueue reclaimers_[kNumReclamationPasses]
Definition: memory_quota.h:268
setup.name
name
Definition: setup.py:542
grpc_core::GrpcMemoryAllocatorImpl::name
absl::string_view name() const
Definition: memory_quota.h:328
grpc_core::ReclamationSweep::~ReclamationSweep
~ReclamationSweep()
Definition: memory_quota.cc:53
grpc_core::MakeMemoryQuota
MemoryQuotaRefPtr MakeMemoryQuota(std::string name)
Definition: memory_quota.h:456
env.new
def new
Definition: env.py:51
grpc_core::ReclaimerQueue::operator=
ReclaimerQueue & operator=(const ReclaimerQueue &)=delete
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_core::ReclamationSweep::waker_
Waker waker_
Definition: memory_quota.h:120
grpc_core::ReclaimerQueue::State
Definition: memory_quota.cc:70
grpc_core::EventEngineMemoryAllocatorImpl
grpc_event_engine::experimental::internal::MemoryAllocatorImpl EventEngineMemoryAllocatorImpl
Definition: memory_quota.h:53
grpc_core::MemoryQuota::memory_quota_
std::shared_ptr< BasicMemoryQuota > memory_quota_
Definition: memory_quota.h:452
grpc_core::GrpcMemoryAllocatorImpl::MaybeRegisterReclaimer
void MaybeRegisterReclaimer() ABSL_LOCKS_EXCLUDED(reclaimer_mu_)
Definition: memory_quota.cc:285
grpc_core::GrpcMemoryAllocatorImpl::PostReclaimer
void PostReclaimer(ReclamationPass pass, F fn)
Definition: memory_quota.h:312
grpc_core::MemoryOwner::InstantaneousPressure
double InstantaneousPressure() const
Definition: memory_quota.h:395
grpc_core::BasicMemoryQuota::SetSize
void SetSize(size_t new_size)
Definition: memory_quota.cc:404
grpc_core::GrpcMemoryAllocatorImpl::reclaimer_mu_
Mutex reclaimer_mu_
Definition: memory_quota.h:362
grpc_core::MemoryOwner::PostReclaimer
void PostReclaimer(ReclamationPass pass, F fn)
Definition: memory_quota.h:390
grpc_core::ReclaimerQueue::NextPromise::queue_
ReclaimerQueue * queue_
Definition: memory_quota.h:213
grpc_core::GrpcMemoryAllocatorImpl::Release
void Release(size_t n) override
Definition: memory_quota.h:297
grpc_core::ReclaimerQueue::Handle::SweepFn
Definition: memory_quota.h:164
grpc_core::MemoryQuota::IsMemoryPressureHigh
bool IsMemoryPressureHigh() const
Definition: memory_quota.h:444
grpc_core::ReclamationSweep::IsSufficient
bool IsSufficient() const
grpc_core::ReclaimerQueue::QueuedNode
Definition: memory_quota.cc:63
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::MemoryOwner::name
absl::string_view name() const
Definition: memory_quota.h:405
grpc_core::ReclaimerQueue::Handle::~Handle
~Handle() override
Definition: memory_quota.h:135
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::GrpcMemoryAllocatorImpl::Shutdown
void Shutdown() override
Definition: memory_quota.cc:172
hpack_encoder_fixtures::Args
Args({0, 16384})
queue
Definition: sync_test.cc:39
grpc_core::ReclaimerQueue::Handle::Run
void Run(ReclamationSweep reclamation_sweep)
Definition: memory_quota.cc:90
generate-asm-lcov.fn
fn
Definition: generate-asm-lcov.py:146
absl::optional::has_value
constexpr bool has_value() const noexcept
Definition: abseil-cpp/absl/types/optional.h:461
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
grpc_core::ReclamationSweep::memory_quota_
std::shared_ptr< BasicMemoryQuota > memory_quota_
Definition: memory_quota.h:118
grpc_core::GrpcMemoryAllocatorImpl::Reserve
size_t Reserve(MemoryRequest request) override
Definition: memory_quota.cc:187
grpc_core::ReclaimerQueue::Handle::SweepFn::SweepFn
SweepFn(F &&f, std::shared_ptr< State > state)
Definition: memory_quota.h:166
grpc_core::ReclaimerQueue::Next
GRPC_MUST_USE_RESULT NextPromise Next()
Definition: memory_quota.h:215
grpc_core::GrpcMemoryAllocatorImpl::memory_quota_
const std::shared_ptr< BasicMemoryQuota > memory_quota_
Definition: memory_quota.h:353
grpc_core::BasicMemoryQuota::FinishReclamation
void FinishReclamation(uint64_t token, Waker waker)
Definition: memory_quota.cc:427
grpc_core::ReclaimerQueue
Definition: memory_quota.h:123
grpc_core::InternallyRefCounted< Handle >::Ref
RefCountedPtr< Handle > Ref() GRPC_MUST_USE_RESULT
Definition: orphanable.h:90
grpc_core::ReclaimerQueue::NextPromise::operator()
Poll< RefCountedPtr< Handle > > operator()()
Definition: memory_quota.h:209
ABSL_EXCLUSIVE_LOCKS_REQUIRED
#define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:145
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
grpc_core::BasicMemoryQuota::kInitialSize
static constexpr intptr_t kInitialSize
Definition: memory_quota.h:258
absl::optional
Definition: abseil-cpp/absl/types/internal/optional.h:61
grpc_core::ReclaimerQueue::NextPromise
Definition: memory_quota.h:206
grpc_core::BasicMemoryQuota
Definition: memory_quota.h:223
grpc_core::ReclaimerQueue::~ReclaimerQueue
~ReclaimerQueue()
grpc_core::GrpcMemoryAllocatorImpl::GrpcMemoryAllocatorImpl
GrpcMemoryAllocatorImpl(std::shared_ptr< BasicMemoryQuota > memory_quota, std::string name)
Definition: memory_quota.cc:159
grpc_core::ActivityPtr
OrphanablePtr< Activity > ActivityPtr
Definition: activity.h:163
grpc_core::BasicMemoryQuota::InstantaneousPressureAndMaxRecommendedAllocationSize
std::pair< double, size_t > InstantaneousPressureAndMaxRecommendedAllocationSize() const
Definition: memory_quota.cc:450
grpc_core::MemoryQuotaRefPtr
std::shared_ptr< MemoryQuota > MemoryQuotaRefPtr
Definition: memory_quota.h:455
grpc_event_engine::experimental::MemoryAllocator::get_internal_impl_ptr
internal::MemoryAllocatorImpl * get_internal_impl_ptr()
Definition: memory_allocator.h:174
grpc_core::ReclamationSweep::Finish
void Finish()
Definition: memory_quota.h:113
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
memory_request.h
grpc_core::InternallyRefCounted
Definition: orphanable.h:73
grpc_core::MemoryOwner::MemoryOwner
MemoryOwner()=default
grpc_core::ReclaimerQueue::ReclaimerQueue
ReclaimerQueue()
Definition: memory_quota.cc:125
grpc_core::MemoryQuota::~MemoryQuota
~MemoryQuota() override
Definition: memory_quota.h:428
F
#define F(b, c, d)
Definition: md4.c:112
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
stdint.h
grpc_core::ReclaimerQueue::NextPromise::NextPromise
NextPromise(ReclaimerQueue *queue)
Definition: memory_quota.h:208
grpc_core::GrpcMemoryAllocatorImpl::Replenish
void Replenish()
Definition: memory_quota.cc:270
grpc_core::ReclamationSweep
Definition: memory_quota.h:88
grpc_core::MemoryQuota::SetSize
void SetSize(size_t new_size)
Definition: memory_quota.h:441
grpc_core::ReclamationSweep::sweep_token_
uint64_t sweep_token_
Definition: memory_quota.h:119
grpc_event_engine::experimental::Vector
Definition: memory_allocator.h:189
grpc_core::BasicMemoryQuota::reclamation_counter_
std::atomic< uint64_t > reclamation_counter_
Definition: memory_quota.h:278
grpc_core::GrpcMemoryAllocatorImpl::free_bytes_
std::atomic< size_t > free_bytes_
Definition: memory_quota.h:358
grpc_core::ReclaimerQueue::Insert
GRPC_MUST_USE_RESULT OrphanablePtr< Handle > Insert(F reclaimer)
Definition: memory_quota.h:194
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_core::MemoryOwner::MakeOrphanable
OrphanablePtr< T > MakeOrphanable(Args &&... args)
Definition: memory_quota.h:400
shutdown_
bool shutdown_
Definition: pick_first.cc:173
grpc_core::ReclaimerQueue::Handle::Handle
Handle(F reclaimer, std::shared_ptr< State > state)
Definition: memory_quota.h:133
grpc_core::GrpcMemoryAllocatorImpl::registered_reclaimer_
std::atomic< bool > registered_reclaimer_
Definition: memory_quota.h:361
grpc_core::ReclamationPass::kBenign
@ kBenign
GRPC_MUST_USE_RESULT
#define GRPC_MUST_USE_RESULT
Definition: impl/codegen/port_platform.h:584
grpc_core::GrpcMemoryAllocatorImpl::taken_bytes_
std::atomic< size_t > taken_bytes_
Definition: memory_quota.h:360
grpc_core::ReclaimerQueue::Enqueue
void Enqueue(RefCountedPtr< Handle > handle)
Definition: memory_quota.cc:129
grpc_core::BasicMemoryQuota::name_
std::string name_
Definition: memory_quota.h:280
grpc_core::Waker
Definition: activity.h:61
grpc_core::ReclamationSweep::ReclamationSweep
ReclamationSweep()=default
grpc_core::GrpcMemoryAllocatorImpl::TryReserve
absl::optional< size_t > TryReserve(MemoryRequest request) GRPC_MUST_USE_RESULT
Definition: memory_quota.cc:203
ABSL_LOCKS_EXCLUDED
#define ABSL_LOCKS_EXCLUDED(...)
Definition: abseil-cpp/absl/base/thread_annotations.h:163
grpc_core::MemoryOwner::impl
GrpcMemoryAllocatorImpl * impl()
Definition: memory_quota.h:415
poll.h
grpc_core::ReclaimerQueue::PollNext
Poll< RefCountedPtr< Handle > > PollNext()
Definition: memory_quota.cc:136
grpc_core::OrphanablePtr
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:64
grpc_core::ReclaimerQueue::Handle::Sweep::MarkCancelled
void MarkCancelled()
Definition: memory_quota.cc:105
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::ReclamationSweep::ReclamationSweep
ReclamationSweep(std::shared_ptr< BasicMemoryQuota > memory_quota, uint64_t sweep_token, Waker waker)
Definition: memory_quota.h:91
grpc_core::BasicMemoryQuota::WaitForSweepPromise
Definition: memory_quota.cc:316
grpc_core::GrpcMemoryAllocatorImpl::ABSL_GUARDED_BY
bool shutdown_ ABSL_GUARDED_BY(reclaimer_mu_)
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc_event_engine::experimental::MemoryAllocatorFactory
Definition: memory_allocator.h:196
grpc_core::ReclaimerQueue::Handle::SweepFn::RunAndDelete
void RunAndDelete(absl::optional< ReclamationSweep > sweep) override
Definition: memory_quota.h:168
ref_counted_ptr.h
grpc_core::BasicMemoryQuota::quota_size_
std::atomic< size_t > quota_size_
Definition: memory_quota.h:265
grpc_core::BasicMemoryQuota::BasicMemoryQuota
BasicMemoryQuota(std::string name)
Definition: memory_quota.h:226
grpc_core::ReclamationPass
ReclamationPass
Definition: memory_quota.h:62
grpc_core::kNumReclamationPasses
static constexpr size_t kNumReclamationPasses
Definition: memory_quota.h:82
grpc_core::ReclaimerQueue::Handle::Orphan
void Orphan() final
Definition: memory_quota.cc:83
grpc_core::ReclaimerQueue::Handle::Requeue
bool Requeue(ReclaimerQueue *new_queue)
Definition: memory_quota.cc:96
handle
static csh handle
Definition: test_arm_regression.c:16
memory_allocator.h
grpc_core::BasicMemoryQuota::name
absl::string_view name() const
Definition: memory_quota.h:252
grpc_core::MemoryQuota::operator=
MemoryQuota & operator=(const MemoryQuota &)=delete
grpc_core::ReclaimerQueue::Handle::Sweep::state_
std::shared_ptr< State > state_
Definition: memory_quota.h:160
grpc_core::GrpcMemoryAllocatorImpl::InsertReclaimer
void InsertReclaimer(size_t pass, F fn) ABSL_EXCLUSIVE_LOCKS_REQUIRED(reclaimer_mu_)
Definition: memory_quota.h:346
grpc_core::GrpcMemoryAllocatorImpl::name_
std::string name_
Definition: memory_quota.h:370
setup.template
template
Definition: setup.py:47
grpc_event_engine::experimental::internal::MemoryAllocatorImpl
Definition: memory_allocator_impl.h:35
grpc_core::BasicMemoryQuota::Take
void Take(size_t amount)
Definition: memory_quota.cc:415
grpc_core::MemoryQuota::MemoryQuota
MemoryQuota(std::string name)
Definition: memory_quota.h:424
grpc_core::MemoryQuota
Definition: memory_quota.h:421
grpc_core::ReclamationSweep::operator=
ReclamationSweep & operator=(const ReclamationSweep &)=delete
grpc_core::ReclaimerQueue::Handle
Definition: memory_quota.h:129
activity.h
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
grpc_core::GrpcMemoryAllocatorImpl::~GrpcMemoryAllocatorImpl
~GrpcMemoryAllocatorImpl() override
Definition: memory_quota.cc:165
grpc_core::ReclaimerQueue::Handle::sweep_
std::atomic< Sweep * > sweep_
Definition: memory_quota.h:178
grpc_core::BasicMemoryQuota::Return
void Return(size_t amount)
Definition: memory_quota.cc:445
grpc_event_engine::experimental::MemoryRequest
Reservation request - how much memory do we want to allocate?
Definition: memory_request.h:27
grpc_core::kMaxQuotaBufferSize
static constexpr size_t kMaxQuotaBufferSize
Definition: memory_quota.h:83
sync.h
grpc_core::ReclamationPass::kDestructive
@ kDestructive
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
grpc_core::MemoryQuota::CreateMemoryAllocator
MemoryAllocator CreateMemoryAllocator(absl::string_view name) override
Definition: memory_quota.cc:466
grpc_core::BasicMemoryQuota::reclaimer_queue
ReclaimerQueue * reclaimer_queue(size_t i)
Definition: memory_quota.h:249
port_platform.h
grpc_core::MemoryOwner::impl
const GrpcMemoryAllocatorImpl * impl() const
Definition: memory_quota.h:411


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:23