chromium/third_party/grpc/src/src/core/lib/resource_quota/memory_quota.cc

// Copyright 2021 gRPC authors.
//
// 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
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <grpc/support/port_platform.h>

#include "src/core/lib/resource_quota/memory_quota.h"

#include <inttypes.h>

#include <algorithm>
#include <atomic>
#include <tuple>

#include "absl/status/status.h"
#include "absl/strings/str_cat.h"

#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/mpscq.h"
#include "src/core/lib/promise/detail/basic_seq.h"
#include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h"
#include "src/core/lib/promise/loop.h"
#include "src/core/lib/promise/map.h"
#include "src/core/lib/promise/race.h"
#include "src/core/lib/promise/seq.h"
#include "src/core/lib/resource_quota/trace.h"

namespace grpc_core {

// Maximum number of bytes an allocator will request from a quota in one step.
// Larger allocations than this will require multiple allocation requests.
static constexpr size_t kMaxReplenishBytes =;

// Minimum number of bytes an allocator will request from a quota in one step.
static constexpr size_t kMinReplenishBytes =;

//
// Reclaimer
//

ReclamationSweep::~ReclamationSweep() {}

//
// ReclaimerQueue
//

struct ReclaimerQueue::QueuedNode
    : public MultiProducerSingleConsumerQueue::Node {};

struct ReclaimerQueue::State {};

void ReclaimerQueue::Handle::Orphan() {}

void ReclaimerQueue::Handle::Run(ReclamationSweep reclamation_sweep) {}

bool ReclaimerQueue::Handle::Requeue(ReclaimerQueue* new_queue) {}

void ReclaimerQueue::Handle::Sweep::MarkCancelled() {}

ReclaimerQueue::ReclaimerQueue() :{}

ReclaimerQueue::~ReclaimerQueue() = default;

void ReclaimerQueue::Enqueue(RefCountedPtr<Handle> handle) {}

Poll<RefCountedPtr<ReclaimerQueue::Handle>> ReclaimerQueue::PollNext() {}

//
// GrpcMemoryAllocatorImpl
//

GrpcMemoryAllocatorImpl::GrpcMemoryAllocatorImpl(
    std::shared_ptr<BasicMemoryQuota> memory_quota, std::string name)
    :{}

GrpcMemoryAllocatorImpl::~GrpcMemoryAllocatorImpl() {}

void GrpcMemoryAllocatorImpl::Shutdown() {}

size_t GrpcMemoryAllocatorImpl::Reserve(MemoryRequest request) {}

absl::optional<size_t> GrpcMemoryAllocatorImpl::TryReserve(
    MemoryRequest request) {}

void GrpcMemoryAllocatorImpl::MaybeDonateBack() {}

void GrpcMemoryAllocatorImpl::Replenish() {}

//
// BasicMemoryQuota
//

class BasicMemoryQuota::WaitForSweepPromise {};

void BasicMemoryQuota::Start() {}

void BasicMemoryQuota::Stop() {}

void BasicMemoryQuota::SetSize(size_t new_size) {}

void BasicMemoryQuota::Take(GrpcMemoryAllocatorImpl* allocator, size_t amount) {}

void BasicMemoryQuota::FinishReclamation(uint64_t token, Waker waker) {}

void BasicMemoryQuota::Return(size_t amount) {}

void BasicMemoryQuota::AddNewAllocator(GrpcMemoryAllocatorImpl* allocator) {}

void BasicMemoryQuota::RemoveAllocator(GrpcMemoryAllocatorImpl* allocator) {}

void BasicMemoryQuota::MaybeMoveAllocator(GrpcMemoryAllocatorImpl* allocator,
                                          size_t old_free_bytes,
                                          size_t new_free_bytes) {}

void BasicMemoryQuota::MaybeMoveAllocatorBigToSmall(
    GrpcMemoryAllocatorImpl* allocator) {}

void BasicMemoryQuota::MaybeMoveAllocatorSmallToBig(
    GrpcMemoryAllocatorImpl* allocator) {}

BasicMemoryQuota::PressureInfo BasicMemoryQuota::GetPressureInfo() {}

//
// PressureTracker
//

namespace memory_quota_detail {

double PressureController::Update(double error) {}

std::string PressureController::DebugString() const {}

double PressureTracker::AddSampleAndGetControlValue(double sample) {}

}  // namespace memory_quota_detail

//
// MemoryQuota
//

MemoryAllocator MemoryQuota::CreateMemoryAllocator(absl::string_view name) {}

MemoryOwner MemoryQuota::CreateMemoryOwner(absl::string_view name) {}

}  // namespace grpc_core