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

Konstantin Osipov kostja at tarantool.org
Tue May 22 16:56:34 MSK 2018


* 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.

Using boolean for task completion status makes the code hard to
follow. I would use an out parameter.

>  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.


Otherwise OK to push.

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov



More information about the Tarantool-patches mailing list