From: Oleg Nesterov <oleg@redhat.com>
To: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in __wait_on_bit_lock()
Date: Mon, 29 Aug 2016 15:48:58 +0200 [thread overview]
Message-ID: <20160829134857.GA28568@redhat.com> (raw)
In-Reply-To: <00e601d201d1$2fbb1c70$8f315550$@alibaba-inc.com>
On 08/29, Hillf Danton wrote:
>
> > > On 08/26, Oleg Nesterov wrote:
> > __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
> > wait_bit_action_f *action, unsigned mode)
> > {
> > int ret = 0;
> >
> > for (;;) {
> > prepare_to_wait_exclusive(wq, &q->wait, mode);
> > if (test_bit(q->key.bit_nr, q->key.flags)) {
> > ret = action(&q->key, mode);
> > /*
> > * Ensure that clear_bit() + wake_up() right after
> > * test_and_set_bit() below can't see us; it should
> > * wake up another exclusive waiter if we fail.
> > */
> > if (ret)
> > finish_wait(wq, &q->wait);
> > }
> > if (!test_and_set_bit(q->key.bit_nr, q->key.flags)) {
> > if (!ret)
> > finish_wait(wq, &q->wait);
> > return 0;
> > } else if (ret) {
> > return ret;
> > }
> > }
> > }
> >
> Can we fold two bit operations into one?
Yes, we can, but I am not sure we want. I guess the first test_bit()
is optimization to avoid the locked test_and_set_bit() which should
likely fail.
> __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
> wait_bit_action_f *action, unsigned mode)
> {
> - do {
> - int ret;
> + int ret = 0;
>
> - prepare_to_wait_exclusive(wq, &q->wait, mode);
> - if (!test_bit(q->key.bit_nr, q->key.flags))
> - continue;
> + prepare_to_wait_exclusive(wq, &q->wait, mode);
> + do {
> + if (!test_and_set_bit(q->key.bit_nr, q->key.flags))
> + break;
> ret = action(&q->key, mode);
> - if (!ret)
> - continue;
> - abort_exclusive_wait(wq, &q->wait, mode, &q->key);
> - return ret;
> - } while (test_and_set_bit(q->key.bit_nr, q->key.flags));
> + } while (!ret);
> +
No, no, this is wrong.
We can't simply remove abort_exclusive_wait(), please read the comment
above this function and the comment added by this patch.
And we can't move prepare_to_wait_exclusive() outside of the main loop.
Oleg.
> finish_wait(wq, &q->wait);
> - return 0;
> + return ret;
> }
> EXPORT_SYMBOL(__wait_on_bit_lock);
>
> --
>
next prev parent reply other threads:[~2016-08-29 13:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <00e501d201cf$7bfecd40$73fc67c0$@alibaba-inc.com>
2016-08-29 8:41 ` [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in __wait_on_bit_lock() Hillf Danton
2016-08-29 13:48 ` Oleg Nesterov [this message]
2016-08-26 12:44 [PATCH 0/2] sched/wait: abort_exclusive_wait() should pass TASK_NORMAL to wake_up() Oleg Nesterov
2016-08-26 12:45 ` [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in __wait_on_bit_lock() Oleg Nesterov
2016-08-26 12:47 ` Oleg Nesterov
2016-09-01 19:01 ` Peter Zijlstra
2016-09-01 19:08 ` Peter Zijlstra
2016-09-02 12:06 ` Oleg Nesterov
2016-09-01 22:17 ` Peter Zijlstra
2016-09-02 12:06 ` Oleg Nesterov
2016-09-02 13:20 ` Peter Zijlstra
2016-09-02 12:06 ` 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=20160829134857.GA28568@redhat.com \
--to=oleg@redhat.com \
--cc=hillf.zj@alibaba-inc.com \
--cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).