aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/resource_quota.c
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2017-03-28 09:49:54 -0700
committerGravatar yang-g <yangg@google.com>2017-03-28 11:45:17 -0700
commitfdd908b01a35346cf252c43a1281a42b8d7c241c (patch)
tree2a3db21254578a55b52687fd41929ee70b10669a /src/core/lib/iomgr/resource_quota.c
parent739cecb0bc1f1ba3b2e0b390795cbaf429ec81c2 (diff)
Clamp memory usage estimate
Diffstat (limited to 'src/core/lib/iomgr/resource_quota.c')
-rw-r--r--src/core/lib/iomgr/resource_quota.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c
index 511ffdcdf1..8dcd80d001 100644
--- a/src/core/lib/iomgr/resource_quota.c
+++ b/src/core/lib/iomgr/resource_quota.c
@@ -279,11 +279,17 @@ static void rq_step_sched(grpc_exec_ctx *exec_ctx,
/* update the atomically available resource estimate - use no barriers since
timeliness of delivery really doesn't matter much */
static void rq_update_estimate(grpc_resource_quota *resource_quota) {
+ gpr_atm memory_usage_estimation = MEMORY_USAGE_ESTIMATION_MAX;
+ if (resource_quota->size != 0) {
+ memory_usage_estimation =
+ GPR_CLAMP((gpr_atm)((1.0 -
+ ((double)resource_quota->free_pool) /
+ ((double)resource_quota->size)) *
+ MEMORY_USAGE_ESTIMATION_MAX),
+ 0, MEMORY_USAGE_ESTIMATION_MAX);
+ }
gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation,
- (gpr_atm)((1.0 -
- ((double)resource_quota->free_pool) /
- ((double)resource_quota->size)) *
- MEMORY_USAGE_ESTIMATION_MAX));
+ memory_usage_estimation);
}
/* returns true if all allocations are completed */