From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v3 3/4] vinyl: don't consume quota if wait queue isn't empty Date: Tue, 12 Feb 2019 20:26:55 +0300 Message-Id: <1c59bdace186d95c6baeae5ba16cdfc2ec42cd31.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: vy_quota_use only checks if there's enough quota available for consumer to proceed, but that's not enough, because it may occur that there are fibers already waiting for the resource. Bypassing them may result in starvation, which manifests itself as "waited for vinyl memory quota for too long" warnings. To ensure fairness and avoid starvation, let's go to sleep if the wait queue is not empty. --- src/box/vy_quota.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c index 7d59e20d..075bfef1 100644 --- a/src/box/vy_quota.c +++ b/src/box/vy_quota.c @@ -287,7 +287,13 @@ vy_quota_use(struct vy_quota *q, enum vy_quota_consumer_type type, return -1; } - if (vy_quota_may_use(q, type, size)) { + /* + * Proceed only if there is enough quota available *and* + * the wait queue is empty. The latter is necessary to ensure + * fairness and avoid starvation among fibers queued earlier. + */ + if (rlist_empty(&q->wait_queue[type]) && + vy_quota_may_use(q, type, size)) { vy_quota_do_use(q, type, size); return 0; } -- 2.11.0