From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 22 May 2018 17:49:10 +0300 From: Vladimir Davydov Subject: Re: [PATCH 7/8] memtx: rework background garbage collection procedure Message-ID: <20180522144910.h65mzowfouavcgil@esperanza> References: <20180522135634.GG11201@atlas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180522135634.GG11201@atlas> To: Konstantin Osipov Cc: tarantool-patches@freelists.org List-ID: On Tue, May 22, 2018 at 04:56:34PM +0300, Konstantin Osipov wrote: > * Vladimir Davydov [18/05/22 15:10]: > > +/** > > + * Run one iteration of garbage collection. Return true if > > + * there still may be objects to collect, false otherwise. > > + */ > > +static bool > > +memtx_engine_run_gc(struct memtx_engine *memtx) > > +{ > > + if (stailq_empty(&memtx->gc_queue)) > > + return false; > > + > > + struct memtx_gc_task *task = stailq_shift_entry(&memtx->gc_queue, > > + struct memtx_gc_task, link); > > + if (task->func(task)) { > > + /* > > + * The task still has objects to collect, > > + * put it back. > > + */ > > + stailq_add_entry(&memtx->gc_queue, task, link); > > + } > > + return true; > > +} > > Please rework this to avoid adding back tasks to the queue. > > Peek the task in the queue and pop it if it's complete. Can't do that, unfortunately: in this implementation a garbage collection callback is supposed to free the task on the last iteration (as a task embedded in an index) so I can't remove a task from the queue after its callback reported there was no more objects to free. I can add a comment explaining this. If you have a better idea, please share. > > Using boolean for task completion status makes the code hard to > follow. I would use an out parameter. OK. > > > memtx_engine_gc_f(va_list va) > > { > > struct memtx_engine *memtx = va_arg(va, struct memtx_engine *); > > while (!fiber_is_cancelled()) { > > - if (stailq_empty(&memtx->gc_queue)) { > > + if (!memtx_engine_run_gc(memtx)) { > > This is also counter to our typical use of return values.