From: Will Deacon <will@kernel.org>
To: Sultan Alsawaf <sultan@kerneltoast.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] locking/mutex: Don't hog RCU read lock while optimistically spinning
Date: Mon, 7 Sep 2020 17:20:31 +0100 [thread overview]
Message-ID: <20200907162031.GA13172@willie-the-truck> (raw)
In-Reply-To: <20200807191636.75045-1-sultan@kerneltoast.com>
On Fri, Aug 07, 2020 at 12:16:35PM -0700, Sultan Alsawaf wrote:
> From: Sultan Alsawaf <sultan@kerneltoast.com>
>
> There's no reason to hold an RCU read lock the entire time while
> optimistically spinning for a mutex lock. This can needlessly lengthen
> RCU grace periods and slow down synchronize_rcu() when it doesn't brute
> force the RCU grace period via rcupdate.rcu_expedited=1.
Would be good to demonstrate this with numbers if you can.
> Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
> ---
> kernel/locking/mutex.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index 5352ce50a97e..cc5676712458 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -552,21 +552,31 @@ bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner,
> {
> bool ret = true;
>
> - rcu_read_lock();
> - while (__mutex_owner(lock) == owner) {
> + for (;;) {
> + unsigned int cpu;
> + bool same_owner;
> +
> /*
> - * Ensure we emit the owner->on_cpu, dereference _after_
> - * checking lock->owner still matches owner. If that fails,
> + * Ensure lock->owner still matches owner. If that fails,
> * owner might point to freed memory. If it still matches,
> * the rcu_read_lock() ensures the memory stays valid.
> */
> - barrier();
> + rcu_read_lock();
> + same_owner = __mutex_owner(lock) == owner;
> + if (same_owner) {
> + ret = owner->on_cpu;
> + if (ret)
> + cpu = task_cpu(owner);
> + }
> + rcu_read_unlock();
Are you sure this doesn't break the ww mutex spinning? That thing also goes
and looks at the owner, but now it's called outside of the read-side
critical section.
Will
next prev parent reply other threads:[~2020-09-07 16:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 19:16 Sultan Alsawaf
2020-08-07 19:16 ` [PATCH 2/2] locking/rwsem: " Sultan Alsawaf
2020-09-07 16:20 ` Will Deacon [this message]
2020-09-14 0:36 ` [PATCH 1/2] locking/mutex: " Sultan Alsawaf
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=20200907162031.GA13172@willie-the-truck \
--to=will@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sultan@kerneltoast.com \
/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
all inboxes | Powered by JetHome®