[Devel] [PATCH vz9 v1 40/63] dm-ploop: process pios via runners

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri Feb 7 12:24:01 MSK 2025



On 1/24/25 23:36, Alexander Atanasov wrote:
> @@ -2013,33 +1964,55 @@ void do_ploop_run_work(struct ploop *ploop)
>   	llcow_pios = llist_del_all(&ploop->pios[PLOOP_LIST_COW]);
>   
>   	/* add old deferred back to the list */
> -	if (lldeferred_pios) {
> -		struct llist_node *pos, *t;
> -		/* Add one by one we need last for batch add */
> -		llist_for_each_safe(pos, t, lldeferred_pios) {
> -			llist_add(pos, &deferred_pios);
> -		}
> -	}
> +	if (lldeferred_pios)
> +		ploop_runners_add_work_list(ploop, lldeferred_pios);
>   
> -	ploop_prepare_embedded_pios(ploop, llembedded_pios, &deferred_pios);
> +	if (llembedded_pios)
> +		ploop_prepare_embedded_pios(ploop, llist_reverse_order(llembedded_pios),
> +					    &deferred_pios);
>   
>   	llflush_pios = llist_del_all(&ploop->pios[PLOOP_LIST_FLUSH]);
>   
>   	if (llresubmit)
> -		ploop_process_resubmit_pios(ploop, llist_reverse_order(llresubmit));
> +		ploop_runners_add_work_list(ploop, llresubmit);
>   
> -	ploop_process_deferred_pios(ploop, &deferred_pios);
> +	ploop_runners_add_work_list(ploop, deferred_pios.first);
>   
>   	if (lldiscard_pios)
> -		ploop_process_discard_pios(ploop, llist_reverse_order(lldiscard_pios));
> +		ploop_runners_add_work_list(ploop, lldiscard_pios);
>   
>   	if (llcow_pios)
> -		ploop_process_delta_cow(ploop, llist_reverse_order(llcow_pios));
> +		ploop_runners_add_work_list(ploop, llcow_pios);
>   
> -	ploop_submit_metadata_writeback(ploop);
> +	/* wait for all pios to be executed before metadata updates */
> +	current->flags = old_flags;
> +	wait_event_interruptible(ploop->dispatcher_wq_data, (!ploop_runners_have_pending(ploop)));
> +	current->flags |= PF_IO_THREAD|PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO;
> +
> +	/* if we have a flush we must sync md data too */
> +	npios = ploop_submit_metadata_writeback(ploop, !!llflush_pios | ploop->force_md_writeback);

Using bit-wise OR operator "|" is kinda ok, though maybe code would 
become more readable if we switch to logical OR here instead, as we have 
logical NOT here already and both operands are of bool type.

>   
> -	if (llflush_pios)
> -		process_ploop_fsync_work(ploop, llist_reverse_order(llflush_pios));
> +	if (llflush_pios) {
> +		if (npios) {
> +			/* wait for metadata writeback to complete */
> +			current->flags = old_flags;
> +			/* First wait all pios to be processed */
> +			wait_event_interruptible(ploop->dispatcher_wq_data,
> +						 (!ploop_runners_have_pending(ploop)));
> +			current->flags |= PF_IO_THREAD|PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO;
> +		}
> +		/* Now process fsync pios after we have done all other */
> +		npios = process_ploop_fsync_work(ploop, llflush_pios);
> +		/* Since dispatcher is single thread no other work can be queued */
> +#ifdef USE_RUNNERS__NOT_READY
> +		if (npios) {
> +			current->flags = old_flags;
> +			wait_event_interruptible(ploop->dispatcher_wq_fsync,
> +						 atomic_read(&wrkr->fsync_pios) != 0);
> +			current->flags |= PF_IO_THREAD|PF_LOCAL_THROTTLE|PF_MEMALLOC_NOIO;
> +		}
> +#endif
> +	}
>   
>   	current->flags = old_flags;
>   }

-- 
Best regards, Tikhomirov Pavel
Senior Software Developer, Virtuozzo.



More information about the Devel mailing list