[EventEngine] fix boundary conditions in memory allocation (#34047)

Ports https://github.com/grpc/grpc/pull/34003
pull/34050/head
Vignesh Babu 2 years ago committed by GitHub
parent 912cb59be5
commit 4e41ec6f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/core/lib/event_engine/posix_engine/posix_endpoint.cc

@ -521,7 +521,7 @@ void PosixEndpointImpl::UpdateRcvLowat() {
void PosixEndpointImpl::MaybeMakeReadSlices() { void PosixEndpointImpl::MaybeMakeReadSlices() {
static const int kBigAlloc = 64 * 1024; static const int kBigAlloc = 64 * 1024;
static const int kSmallAlloc = 8 * 1024; static const int kSmallAlloc = 8 * 1024;
if (incoming_buffer_->Length() < static_cast<size_t>(min_progress_size_)) { if (incoming_buffer_->Length() < std::max<size_t>(min_progress_size_, 1)) {
size_t allocate_length = min_progress_size_; size_t allocate_length = min_progress_size_;
const size_t target_length = static_cast<size_t>(target_length_); const size_t target_length = static_cast<size_t>(target_length_);
// If memory pressure is low and we think there will be more than // If memory pressure is low and we think there will be more than
@ -531,8 +531,8 @@ void PosixEndpointImpl::MaybeMakeReadSlices() {
if (low_memory_pressure && target_length > allocate_length) { if (low_memory_pressure && target_length > allocate_length) {
allocate_length = target_length; allocate_length = target_length;
} }
int extra_wanted = int extra_wanted = std::max<int>(
allocate_length - static_cast<int>(incoming_buffer_->Length()); 1, allocate_length - static_cast<int>(incoming_buffer_->Length()));
if (extra_wanted >= if (extra_wanted >=
(low_memory_pressure ? kSmallAlloc * 3 / 2 : kBigAlloc)) { (low_memory_pressure ? kSmallAlloc * 3 / 2 : kBigAlloc)) {
while (extra_wanted > 0) { while (extra_wanted > 0) {

Loading…
Cancel
Save