From 878a7c2a09d01baec4df8eb99ba9cbe1dc9af7e3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 23 Mar 2017 15:14:48 -0700 Subject: Memory usage tweaks - Improve estimation to give a more reliable slop space in the arena - Improve measurement by issuing sufficient throw-away calls on a channel to allow call size estimation to settle --- src/core/lib/surface/channel.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/core/lib') diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index d6c7aee40d..a80f24e740 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -194,13 +194,22 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, size_t grpc_channel_get_call_size_estimate(grpc_channel *channel) { #define ROUND_UP_SIZE 256 - return ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + - ROUND_UP_SIZE) & - ~(size_t)(ROUND_UP_SIZE - 1); + /* We round up our current estimate to the NEXT value of ROUND_UP_SIZE. + This ensures: + 1. a consistent size allocation when our estimate is drifting slowly + (which is common) - which tends to help most allocators reuse memory + 2. a small amount of allowed growth over the estimate without hitting + the arena size doubling case, reducing overall memory usage */ + size_t est = ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + + 2 * ROUND_UP_SIZE) & + ~(size_t)(ROUND_UP_SIZE - 1); + gpr_log(GPR_DEBUG, "est: %d", (int)est); + return est; } void grpc_channel_update_call_size_estimate(grpc_channel *channel, size_t size) { + gpr_log(GPR_DEBUG, "used: %d", (int)size); size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate); if (cur < size) { /* size grew: update estimate */ -- cgit v1.2.3 From b64d652703e998525291eef36c416874894d5749 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 23 Mar 2017 15:17:18 -0700 Subject: Spam cleanup --- src/core/lib/surface/channel.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/core/lib') diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index a80f24e740..b4bfb92042 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -200,16 +200,13 @@ size_t grpc_channel_get_call_size_estimate(grpc_channel *channel) { (which is common) - which tends to help most allocators reuse memory 2. a small amount of allowed growth over the estimate without hitting the arena size doubling case, reducing overall memory usage */ - size_t est = ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + - 2 * ROUND_UP_SIZE) & - ~(size_t)(ROUND_UP_SIZE - 1); - gpr_log(GPR_DEBUG, "est: %d", (int)est); - return est; + return ((size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate) + + 2 * ROUND_UP_SIZE) & + ~(size_t)(ROUND_UP_SIZE - 1); } void grpc_channel_update_call_size_estimate(grpc_channel *channel, size_t size) { - gpr_log(GPR_DEBUG, "used: %d", (int)size); size_t cur = (size_t)gpr_atm_no_barrier_load(&channel->call_size_estimate); if (cur < size) { /* size grew: update estimate */ -- cgit v1.2.3