From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 20 Aug 2018 14:07:21 +0300 From: Konstantin Osipov Subject: Re: [PATCH 01/18] vinyl: rework internal quota API Message-ID: <20180820110721.GD8716@chai> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: Vladimir Davydov Cc: tarantool-patches@freelists.org List-ID: * Vladimir Davydov [18/08/16 23:03]: > + * > + * Usage pattern: > + * > + * size_t reserved = ; > + * if (vy_quota_try_use(q, reserved, timeout) != 0) > + * return -1; > + * > + * size_t used = ; > + * vy_quota_commit_use(q, reserved, used); How is this different from vy_quota_use(); followed by vy_quota_release( - )? If vy_quota_commit_use() is actually release *or* force-use, depending on the sign of the result ( - ) then the new api is actually less clear than the old one. If you would like to introduce a new call which would either release quota or force-use it, then this call should be called vy_quota_adjust() or something like that, and the old call (vy_quota_use()) should be left intact. The new names are imho less clear. > + * because we may not yield after we start inserting statements > + * into a space so we estimate the allocation size and wait for > + * quota before committing statements. At the same time, we > + * cannot precisely estimate the size of memory we are going to > + * consume so we adjust the quota after the allocation. > + * > + * The size of memory allocated while committing a transaction > + * may be greater than an estimate, because insertion of a > + * statement into an in-memory index can trigger allocation > + * of a new index extent. This should not normally result in a > + * noticeable breach in the memory limit, because most memory > + * is occupied by statements, but we need to adjust the quota > + * accordingly after the allocation in this case. > + * > + * The actual memory allocation size may also be less than an > + * estimate if the space has multiple indexes, because statements > + * are stored in the common memory level, which isn't taken into > + * account while estimating the size of a memory allocation. > */ > static inline int > -vy_quota_use(struct vy_quota *q, size_t size, double timeout) > +vy_quota_try_use(struct vy_quota *q, size_t size, double timeout) > { > double start_time = ev_monotonic_now(loop()); try_use() suggests that the call quickly fails if it can't succeed (e.g. trylock()). > double deadline = start_time + timeout; > @@ -178,6 +208,27 @@ vy_quota_use(struct vy_quota *q, size_t size, double timeout) > } > > /** > + * Adjust quota after allocating memory. interestingly you use the verb adjust in the comment yourself. > + * > + * @reserved: size of quota reserved by vy_quota_try_use(). > + * @used: size of memory actually allocated. > + * > + * See also vy_quota_try_use(). > + */ > +static inline void > +vy_quota_commit_use(struct vy_quota *q, size_t reserved, size_t used) > +{ > + if (reserved > used) { > + size_t excess = reserved - used; > + assert(q->used >= excess); > + q->used -= excess; > + fiber_cond_broadcast(&q->cond); > + } > + if (reserved < used) > + vy_quota_force_use(q, used - reserved); > +} -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov