From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D236F469719 for ; Fri, 14 Feb 2020 22:32:03 +0300 (MSK) From: Ilya Kosarev Date: Fri, 14 Feb 2020 22:31:56 +0300 Message-Id: <20200214193156.1279-1-i.kosarev@tarantool.org> Subject: [Tarantool-patches] [PATCH] quota: add is_enabled field List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org By default the quota is enabled. If it is set to false, quota_use will allow to overuse the total available memory limit. Part of tarantool/tarantool#3807 --- Branch: https://github.com/tarantool/small/tree/i.kosarev/gh-3807-safe-alloc-on-truncation Issue: https://github.com/tarantool/tarantool/issues/3807 small/quota.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/small/quota.h b/small/quota.h index 3d3b4f0..fbb039e 100644 --- a/small/quota.h +++ b/small/quota.h @@ -57,6 +57,12 @@ struct quota { * QUOTA_UNIT_SIZE. */ uint64_t value; + /** + * By default the quota is enabled. If it is set to + * false, quota_use will allow to overuse the total + * available memory limit. + */ + bool is_enabled; }; /** @@ -68,6 +74,7 @@ quota_init(struct quota *quota, size_t total) uint64_t new_total = (total + (QUOTA_UNIT_SIZE - 1)) / QUOTA_UNIT_SIZE; quota->value = new_total << 32; + quota->is_enabled = true; } /** @@ -122,6 +129,12 @@ quota_set(struct quota *quota, size_t new_total) return new_total_in_units * QUOTA_UNIT_SIZE; } +static inline void +quota_on_off(struct quota *quota, bool is_enabled) +{ + quota->is_enabled = is_enabled; +} + /** * Use up a quota * @retval > 0 aligned value on success @@ -143,7 +156,7 @@ quota_use(struct quota *quota, size_t size) uint32_t new_used_in_units = used_in_units + size_in_units; assert(new_used_in_units > used_in_units); - if (new_used_in_units > total_in_units) + if (new_used_in_units > total_in_units && quota->is_enabled) return -1; uint64_t new_value = -- 2.17.1