[PATCH v3 3/4] vinyl: don't consume quota if wait queue isn't empty

Vladimir Davydov vdavydov.dev at gmail.com
Tue Feb 12 20:26:55 MSK 2019


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




More information about the Tarantool-patches mailing list