[channel] Move arena creation into Channels (#35765)

Gives a slightly cleaner API for Arena sizing

Built on #35732

Closes #35765

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35765 from ctiller:chan2 e67e174060
PiperOrigin-RevId: 602935918
pull/35664/head
Craig Tiller 10 months ago committed by Copybara-Service
parent 72f06eb7d5
commit 10b47f1b12
  1. 19
      src/core/lib/surface/call.cc
  2. 11
      src/core/lib/surface/channel.cc
  3. 7
      src/core/lib/surface/channel.h
  4. 6
      src/core/lib/surface/server.cc

@ -412,8 +412,7 @@ void Call::DeleteThis() {
RefCountedPtr<Channel> channel = std::move(channel_);
Arena* arena = arena_;
this->~Call();
channel->UpdateCallSizeEstimate(arena->TotalUsedBytes());
arena->Destroy();
channel->DestroyArena(arena);
}
void Call::PrepareOutgoingInitialMetadata(const grpc_op& op,
@ -814,20 +813,15 @@ grpc_error_handle FilterStackCall::Create(grpc_call_create_args* args,
*composite = grpc_error_add_child(*composite, new_err);
};
Arena* arena;
FilterStackCall* call;
grpc_error_handle error;
grpc_channel_stack* channel_stack = channel->channel_stack();
size_t initial_size = channel->CallSizeEstimate();
global_stats().IncrementCallInitialSize(initial_size);
size_t call_alloc_size =
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(FilterStackCall)) +
channel_stack->call_stack_size;
std::pair<Arena*, void*> arena_with_call = Arena::CreateWithAlloc(
initial_size, call_alloc_size, channel->allocator());
arena = arena_with_call.first;
call = new (arena_with_call.second) FilterStackCall(arena, *args);
Arena* arena = channel->CreateArena();
call = new (arena->Alloc(call_alloc_size)) FilterStackCall(arena, *args);
GPR_DEBUG_ASSERT(FromC(call->c_ptr()) == call);
GPR_DEBUG_ASSERT(FromCallStack(call->call_stack()) == call);
*out_call = call->c_ptr();
@ -2488,11 +2482,8 @@ grpc_error_handle MakePromiseBasedCall(grpc_call_create_args* args,
grpc_call** out_call) {
Channel* channel = args->channel.get();
const auto initial_size = channel->CallSizeEstimate();
global_stats().IncrementCallInitialSize(initial_size);
auto alloc =
Arena::CreateWithAlloc(initial_size, sizeof(T), channel->allocator());
PromiseBasedCall* call = new (alloc.second) T(alloc.first, args);
auto* arena = channel->CreateArena();
PromiseBasedCall* call = arena->New<T>(arena, args);
*out_call = call->c_ptr();
GPR_DEBUG_ASSERT(Call::FromC(*out_call) == call);
return absl::OkStatus();

@ -107,6 +107,17 @@ Channel::Channel(bool is_client, bool is_promising, std::string target,
};
}
Arena* Channel::CreateArena() {
const size_t initial_size = call_size_estimator_.CallSizeEstimate();
global_stats().IncrementCallInitialSize(initial_size);
return Arena::Create(initial_size, &allocator_);
}
void Channel::DestroyArena(Arena* arena) {
call_size_estimator_.UpdateCallSizeEstimate(arena->TotalUsedBytes());
arena->Destroy();
}
absl::StatusOr<RefCountedPtr<Channel>> Channel::CreateWithBuilder(
ChannelStackBuilder* builder) {
auto channel_args = builder->channel_args();

@ -122,13 +122,10 @@ class Channel : public RefCounted<Channel>,
channelz::ChannelNode* channelz_node() const { return channelz_node_.get(); }
size_t CallSizeEstimate() { return call_size_estimator_.CallSizeEstimate(); }
void UpdateCallSizeEstimate(size_t size) {
call_size_estimator_.UpdateCallSizeEstimate(size);
}
Arena* CreateArena();
void DestroyArena(Arena* arena);
absl::string_view target() const { return target_; }
MemoryAllocator* allocator() { return &allocator_; }
bool is_client() const { return is_client_; }
bool is_promising() const { return is_promising_; }
RegisteredCall* RegisterCall(const char* method, const char* host);

@ -1298,11 +1298,7 @@ Server::ChannelData::~ChannelData() {
}
}
Arena* Server::ChannelData::CreateArena() {
const auto initial_size = channel_->CallSizeEstimate();
global_stats().IncrementCallInitialSize(initial_size);
return Arena::Create(initial_size, channel_->allocator());
}
Arena* Server::ChannelData::CreateArena() { return channel_->CreateArena(); }
absl::StatusOr<CallInitiator> Server::ChannelData::CreateCall(
ClientMetadata& client_initial_metadata, Arena* arena) {

Loading…
Cancel
Save