From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
linux-kernel@vger.kernel.org, john.p.donnelly@oracle.com,
"Hillf Danton" <hdanton@sina.com>,
"Mukesh Ojha" <quic_mojha@quicinc.com>,
"Ting11 Wang 王婷" <wangting11@xiaomi.com>
Subject: Re: [PATCH v6 5/6] locking/rwsem: Enable direct rwsem lock handoff
Date: Mon, 23 Jan 2023 17:07:08 -0500 [thread overview]
Message-ID: <284b7d75-42cd-ddab-8431-dfbde8bea2b2@redhat.com> (raw)
In-Reply-To: <9fb531a9-0951-f7c0-316d-749d2c59ade8@redhat.com>
On 1/23/23 12:30, Waiman Long wrote:
> I will update the patch description to highlight the points that I
> discussed in this email.
I am planning to update the patch description to as follows:
The lock handoff provided in rwsem isn't a true handoff like that in
the mutex. Instead, it is more like a quiescent state where optimistic
spinning and lock stealing are disabled to make it easier for the first
waiter to acquire the lock.
For mutex, lock handoff is done at unlock time as the owner value and
the handoff bit is in the same lock word and can be updated atomically.
That is the not case for rwsem which has a separate count value for
locking and an owner value. The only way to update them in a
quasi-atomic
way is to use the wait_lock for synchronization as the handoff bit can
only be updated while holding the wait_lock. So for rwsem, the new
lock handoff mechanism is done mostly at rwsem_wake() time when the
wait_lock has to be acquired anyway to minimize additional overhead.
Passing the count value at unlock time down to rwsem_wake() to
determine
if handoff should be done is not safe as the waiter that set the
RWSEM_FLAG_HANDOFF bit may have been interrupted out or killed in the
interim. So we need to recheck the count value again after taking the
wait_lock. If there is an active lock, we can't perform the handoff
even if the handoff bit is set at both the unlock and rwsem_wake()
times. It is because there is a slight possibility that the original
waiter that set the handoff bit may have bailed out followed by a read
lock and then the handoff bit is set by another waiter.
It is also likely that the active lock in this case may be a transient
RWSEM_READER_BIAS that will be removed soon. So we have a secondary
handoff done at reader slow path to handle this particular case.
For reader-owned rwsem, the owner value other than the
RWSEM_READER_OWNED
bit is mostly for debugging purpose only. So it is not safe to use
the owner value to confirm a handoff to a reader has happened. On the
other hand, we can do that when handing off to a writer. However, it
is simpler to use the same mechanism to notify a handoff has happened
for both readers and writers. So a new HANDOFF_GRANTED state is added
to enum rwsem_handoff_state to signify that. This new value will be
written to the handoff_state value of the first waiter.
With true lock handoff, there is no need to do a NULL owner spinning
anymore as wakeup will be performed if handoff is successful. So it
is likely that the first waiter won't actually go to sleep even when
schedule() is called in this case.
Please let me know what you think.
Cheers,
Longman
next prev parent reply other threads:[~2023-01-23 22:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 2:20 [PATCH v6 0/6] lockinig/rwsem: Fix rwsem bugs & enable true " Waiman Long
2022-11-18 2:20 ` [PATCH v6 1/6] locking/rwsem: Prevent non-first waiter from spinning in down_write() slowpath Waiman Long
2022-12-16 15:02 ` Jiri Wiesner
2023-01-20 22:58 ` Waiman Long
2022-11-18 2:20 ` [PATCH v6 2/6] locking/rwsem: Disable preemption at all down_read*() and up_read() code paths Waiman Long
2022-12-16 15:03 ` Jiri Wiesner
2022-11-18 2:20 ` [PATCH v6 3/6] locking/rwsem: Disable preemption at all down_write*() and up_write() " Waiman Long
2022-12-16 15:03 ` Jiri Wiesner
2022-11-18 2:20 ` [PATCH v6 4/6] locking/rwsem: Change waiter->hanodff_set to a handoff_state enum Waiman Long
2022-11-18 2:20 ` [PATCH v6 5/6] locking/rwsem: Enable direct rwsem lock handoff Waiman Long
2023-01-23 14:59 ` Peter Zijlstra
2023-01-23 17:30 ` Waiman Long
2023-01-23 22:07 ` Waiman Long [this message]
2023-01-24 12:58 ` Peter Zijlstra
2023-01-24 12:29 ` Peter Zijlstra
2023-01-25 1:53 ` Waiman Long
2022-11-18 2:20 ` [PATCH v6 6/6] locking/rwsem: Update handoff lock events tracking Waiman Long
2023-01-17 20:53 ` [PATCH v6 0/6] lockinig/rwsem: Fix rwsem bugs & enable true lock handoff Waiman Long
2023-01-22 13:46 ` Peter Zijlstra
2023-01-23 3:40 ` Waiman Long
2023-01-23 21:10 ` Waiman Long
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=284b7d75-42cd-ddab-8431-dfbde8bea2b2@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=hdanton@sina.com \
--cc=john.p.donnelly@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=quic_mojha@quicinc.com \
--cc=wangting11@xiaomi.com \
--cc=will@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
Powered by JetHome