From: Frederic Weisbecker <fweisbec@gmail.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@elte.hu>, Oleg Nesterov <oleg@tv-sign.ru>,
Andrew Morton <akpm@linux-foundation.org>,
Eric Dumazet <dada1@cosmosbay.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/3] workqueue: not allow recursion run_workqueue
Date: Thu, 5 Feb 2009 14:47:18 +0100 [thread overview]
Message-ID: <20090205134716.GB5853@nowhere> (raw)
In-Reply-To: <498AA0F1.2030003@cn.fujitsu.com>
Hi Lai,
On Thu, Feb 05, 2009 at 04:18:57PM +0800, Lai Jiangshan wrote:
> Peter Zijlstra wrote:
> > On Thu, 2009-01-22 at 12:06 +0100, Frédéric Weisbecker wrote:
> >
> >> Actually I don't understand when Lai says that it will actually not flush.
> >
> > Yeah, his changelog is an utter mistery to many..
> >
> >
>
> ----
> Suppose what I wanted to say is A, but sometimes I wrote B for my poor
> English, and people got C when they read it. Thank you, Peter.
> ----
Me too! My poor english takes me double time to explain something :-)
> "if (cwq->thread == current)" is a narrowed checking. lockdep can perform
> the proper checking. I think we could hardly write some code which can
> perform the proper checking when lockdep is off.
>
> Why "if (cwq->thread == current)" is a narrowed checking,
> It hasn't tested "if (brother_cwq->thread == current)". (*brother* cwq)
>
> DEADLOCK EXAMPLE for explain my above option:
>
> (work_func0() and work_func1() are work callback, and they
> calls flush_workqueue())
>
> CPU#0 CPU#1
> run_workqueue() run_workqueue()
> work_func0() work_func1()
> flush_workqueue() flush_workqueue()
> flush_cpu_workqueue(0) .
> flush_cpu_workqueue(cpu#1) flush_cpu_workqueue(cpu#0)
> waiting work_func1() in cpu#1 waiting work_func0 in cpu#0
Heh you're right, I did not imagine this one.
But this race condition should be rare, and still, lockdep should have
warned before concerning the recursion flushing, hopefully assuming the developer
built lockdep.
> DEADLOCK!
> So we do not allow recursion.
> And "BUG_ON(cwq->thread == current)" is not enough(but it's better
> than we don't have this line, I think). we should use lockdep to detect
> recursion when we develop.
>
> Answer other email-thread:
>
> Peter Zijlstra wrote:
> > On Thu, 2009-01-22 at 14:03 +0800, Lai Jiangshan wrote:
> >> void do_some_cleanup(void)
> >> {
> >> find_all_queued_work_struct_and_mark_it_old();
> >> flush_workqueue(workqueue);
> >> /* we can destroy old work_struct for we have flushed them */
> >> destroy_old_work_structs();
> >> }
> >>
> >> if work->func() called do_some_cleanup(), it's very probably a bug.
> >
> > Of course it is, if only because calling flush on the same workqueue is
> > pretty dumb.
>
> flush_workqueue() should ensure works are finished, but this example shows
> the work hasn't finished, so flush_workqueue()'s code is not right.
>
> See also flush_workqueue()'s doc:
> * We sleep until all works which were queued on entry have been handled,
> * but we are not livelocked by new incoming ones.
>
> And this example show a bug(destroy the work which still be used)
> for recursion. So in my changlog:
>
> I said it hide deadlock:
> "We use recursion run_workqueue to hidden deadlock when
> keventd trying to flush its own queue."
>
> I said it will be bug(for flush_workqueue() and it's doc is inconsistent):
> "It's bug. When flush_workqueue()(nested in a work callback)returns,
> the workqueue is not really flushed, the sequence statement of
> this work callback will do some thing bad."
>
> And I concluded:
> "So we should not allow workqueue trying to flush its own queue."
>
> If it still mistery, I will explain more.
> I will change my changlog too, I sincerely hope you help me more.
>
> Thanks, Lai
>
> >
> > But I'm still not getting it, flush_workqueue() provides the guarantee
> > that all work enqueued previous to the call will be finished thereafter.
>
> In my example, flush_workqueue() can't guarantee.
>
> >
> > The self-flush stuff you propose to rip out doesn't violate that
> > guarantee afaict.
> >
> > Suppose we have a workqueue Q, with pending work W1..Wn.
> >
> > Suppose W5 will have the nested flush, it will then recursively complete
> > W6..Wn+i, where i accounts for any concurrent worklet additions.
> >
> > Therefore it will have completed (at least) those worklets that were
> > enqueued at the time flush got called.
> >
> > So, to get back at your changelog.
> >
> > 1) yes lockdep will complain -- for good reasons, and I'm all for
> > getting rid of this mis-feature.
> >
> > 2) I've no clue what you're on about
> >
> > 3) more mystery.
>
next prev parent reply other threads:[~2009-02-05 13:47 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-22 9:14 [PATCH 2/3] workqueue: not allow recursion run_workqueue Lai Jiangshan
2009-01-22 9:30 ` Frederic Weisbecker
2009-01-22 9:36 ` Ingo Molnar
2009-01-22 11:06 ` Frédéric Weisbecker
2009-01-22 11:10 ` Peter Zijlstra
2009-02-05 8:18 ` Lai Jiangshan
2009-02-05 13:47 ` Frederic Weisbecker [this message]
2009-02-05 17:01 ` Oleg Nesterov
2009-02-05 17:24 ` Frederic Weisbecker
2009-02-05 18:00 ` Oleg Nesterov
2009-02-06 1:20 ` Lai Jiangshan
2009-02-06 16:46 ` Oleg Nesterov
2009-02-09 7:20 ` Lai Jiangshan
2009-02-06 1:46 ` Lai Jiangshan
2009-02-09 19:14 ` Oleg Nesterov
2009-02-10 20:53 ` Andrew Morton
2009-01-22 9:39 ` Frederic Weisbecker
2009-01-22 17:23 ` Oleg Nesterov
2009-01-22 17:47 ` Frédéric Weisbecker
2009-01-22 18:22 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090205134716.GB5853@nowhere \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dada1@cosmosbay.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox