Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
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	[thread overview]
Message-ID: <1c59bdace186d95c6baeae5ba16cdfc2ec42cd31.1549990576.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1549990576.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1549990576.git.vdavydov.dev@gmail.com>

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

  parent reply	other threads:[~2019-02-12 17:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 17:26 [PATCH v3 0/4] vinyl: compaction randomization and throttling Vladimir Davydov
2019-02-12 17:26 ` [PATCH v3 1/4] vinyl: introduce quota consumer types Vladimir Davydov
2019-02-12 18:14   ` Konstantin Osipov
2019-02-12 17:26 ` [PATCH v3 2/4] vinyl: remove extra quota check from vy_quota_use Vladimir Davydov
2019-02-12 18:15   ` Konstantin Osipov
2019-02-12 17:26 ` Vladimir Davydov [this message]
2019-02-12 18:15   ` [PATCH v3 3/4] vinyl: don't consume quota if wait queue isn't empty Konstantin Osipov
2019-02-12 17:26 ` [PATCH v3 4/4] vinyl: throttle tx to ensure compaction keeps up with dumps Vladimir Davydov
2019-02-12 18:20   ` Konstantin Osipov
2019-02-13 10:56 ` [PATCH v3 0/4] vinyl: compaction randomization and throttling Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c59bdace186d95c6baeae5ba16cdfc2ec42cd31.1549990576.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v3 3/4] vinyl: don'\''t consume quota if wait queue isn'\''t empty' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox