<br><br>On Thursday, December 17, 2015, Mike Snitzer <<a href="mailto:snitzer@redhat.com">snitzer@redhat.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Dec 17 2015 at 10:50am -0500,<br>
Tejun Heo <<a href="javascript:;" onclick="_e(event, 'cvml', 'tj@kernel.org')">tj@kernel.org</a>> wrote:<br>
<br>
> Hello, Nikolay.<br>
><br>
> On Thu, Dec 17, 2015 at 05:43:12PM +0200, Nikolay Borisov wrote:<br>
> > Right, but my initial understanding was that when canceling the delayed<br>
> > work and then issuing flush_workqueue would act the same way as if<br>
> > cancel_delayed_work_sync is called wrt to this particular delayed item, no?<br>
><br>
> Not necessarily.  cancel_delayed_work() cancels whatever is currently<br>
> pending.  flush_workqueue() flushes whatever is pending and in flight<br>
> at the time of invocation.  Imagine the following scenario.<br>
><br>
> 1. Work item is running but hasn't requeued itself yet.<br>
><br>
> 2. cancel_delayed_work_sync() doesn't do anything as it's not pending.<br>
<br>
Did you mean cancel_delayed_work()?<br>
<br>
> 3. flush_workqueue() starts and waits for the running instance.<br>
><br>
> 4. The running instance requeues itself but this isn't included in the<br>
>    scope of the above flush_workqueue().<br>
><br>
> 5. flush_workqueue() returns when the work item is finished (but it's<br>
>    still queued).<br>
<br>
Hmm, the comment above cancel_delayed_work() is pretty misleading then:<br>
<br>
 * Note:<br>
 * The work callback function may still be running on return, unless<br>
 * it returns %true and the work doesn't re-arm itself.  Explicitly flush or<br>
 * use cancel_delayed_work_sync() to wait on it.<br>
<br>
Given dm-thin.c:pool_postsuspend() does:<br>
<br>
        cancel_delayed_work(&pool->waker);<br>
        cancel_delayed_work(&pool->no_space_timeout);<br>
        flush_workqueue(pool->wq);<br>
<br>
I wouldn't have thought cancel_delayed_work_sync() was needed.<br>
</blockquote><div><br></div><div>Ping as Tejun might have missed this email. I'm also interested in knowing the logic behind the comment.</div>