From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v3 2/4] vinyl: remove extra quota check from vy_quota_use Date: Tue, 12 Feb 2019 20:26:54 +0300 Message-Id: <1762d22b6826352d5dc1a3e8bb3a2b3e6026f5d7.1549990576.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Before waking up a fiber that is waiting for quota, we always first check if it can actually consume it, see vy_quota_signal. Hence the extra check in vy_quota_use is needed only to prevent spurious wakeups. It doesn't seem to be wise to add such a check to a hot path as a counter-mesaure to such an unlikely scenario. Let's remove it - after all it isn't critical if a spuriously woken up fiber exceeds the limit. --- src/box/vy_quota.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c index dc452adb..7d59e20d 100644 --- a/src/box/vy_quota.c +++ b/src/box/vy_quota.c @@ -294,27 +294,20 @@ vy_quota_use(struct vy_quota *q, enum vy_quota_consumer_type type, /* Wait for quota. */ double wait_start = ev_monotonic_now(loop()); - double deadline = wait_start + timeout; - struct vy_quota_wait_node wait_node = { .fiber = fiber(), .size = size, .ticket = ++q->wait_ticket, }; rlist_add_tail_entry(&q->wait_queue[type], &wait_node, in_wait_queue); - - do { - double now = ev_monotonic_now(loop()); - fiber_yield_timeout(deadline - now); - if (now >= deadline) { - rlist_del_entry(&wait_node, in_wait_queue); - diag_set(ClientError, ER_VY_QUOTA_TIMEOUT); - return -1; - } - } while (!vy_quota_may_use(q, type, size)); - + bool timed_out = fiber_yield_timeout(timeout); rlist_del_entry(&wait_node, in_wait_queue); + if (timed_out) { + diag_set(ClientError, ER_VY_QUOTA_TIMEOUT); + return -1; + } + double wait_time = ev_monotonic_now(loop()) - wait_start; if (wait_time > q->too_long_threshold) { say_warn_ratelimited("waited for %zu bytes of vinyl memory " -- 2.11.0