[PATCH 7/8] memtx: rework background garbage collection procedure

Vladimir Davydov vdavydov.dev at gmail.com
Tue May 22 17:49:10 MSK 2018


On Tue, May 22, 2018 at 04:56:34PM +0300, Konstantin Osipov wrote:
> * Vladimir Davydov <vdavydov.dev at gmail.com> [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.



More information about the Tarantool-patches mailing list