From: "Aiqun Yu (Maria)" <quic_aiquny@quicinc.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Hillf Danton <hdanton@sina.com>, <kernel@quicinc.com>,
<quic_pkondeti@quicinc.com>, <keescook@chromium.org>,
<viro@zeniv.linux.org.uk>, <brauner@kernel.org>,
<oleg@redhat.com>, <dhowells@redhat.com>, <jarkko@kernel.org>,
<paul@paul-moore.com>, <jmorris@namei.org>, <serge@hallyn.com>,
<linux-mm@kvack.org>, <linux-fsdevel@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <keyrings@vger.kernel.org>,
<linux-security-module@vger.kernel.org>,
<linux-arm-msm@vger.kernel.org>
Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock
Date: Thu, 4 Jan 2024 08:46:30 +0800 [thread overview]
Message-ID: <02e09c99-3431-4ba1-86bb-c4c68ebdc6b0@quicinc.com> (raw)
In-Reply-To: <ZZWk368hZpOc25X0@casper.infradead.org>
On 1/4/2024 2:18 AM, Matthew Wilcox wrote:
> On Wed, Jan 03, 2024 at 10:58:33AM +0800, Aiqun Yu (Maria) wrote:
>> On 1/2/2024 5:14 PM, Matthew Wilcox wrote:
>>>>> -void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock)
>>>>> +void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock, bool irq)
>>>>> {
>>>>> int cnts;
>>>>> @@ -82,7 +83,11 @@ void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock)
>>>> Also a new state showed up after the current design:
>>>> 1. locked flag with _QW_WAITING, while irq enabled.
>>>> 2. And this state will be only in interrupt context.
>>>> 3. lock->wait_lock is hold by the write waiter.
>>>> So per my understanding, a different behavior also needed to be done in
>>>> queued_write_lock_slowpath:
>>>> when (unlikely(in_interrupt())) , get the lock directly.
>>>
>>> I don't think so. Remember that write_lock_irq() can only be called in
>>> process context, and when interrupts are enabled.
>> In current kernel drivers, I can see same lock called with write_lock_irq
>> and write_lock_irqsave in different drivers.
>>
>> And this is the scenario I am talking about:
>> 1. cpu0 have task run and called write_lock_irq.(Not in interrupt context)
>> 2. cpu0 hold the lock->wait_lock and re-enabled the interrupt.
>
> Oh, I missed that it was holding the wait_lock. Yes, we also need to
> release the wait_lock before spinning with interrupts disabled.
>
>> I was thinking to support both write_lock_irq and write_lock_irqsave with
>> interrupt enabled together in queued_write_lock_slowpath.
>>
>> That's why I am suggesting in write_lock_irqsave when (in_interrupt()),
>> instead spin for the lock->wait_lock, spin to get the lock->cnts directly.
>
> Mmm, but the interrupt could come in on a different CPU and that would
> lead to it stealing the wait_lock from the CPU which is merely waiting
> for the readers to go away.
That's right.
The fairness(or queue mechanism) wouldn't be ensured (only in interrupt
context) if we have the special design when (in_interrupt()) spin to get
the lock->cnts directly. When in interrupt context, the later
write_lock_irqsave may get the lock earlier than the write_lock_irq()
which is not in interrupt context.
This is a side effect of the design, while similar unfairness design in
read lock as well. I think it is reasonable to have in_interrupt()
waiters get lock earlier from the whole system's performance of view.
>
--
Thx and BRs,
Aiqun(Maria) Yu
next prev parent reply other threads:[~2024-01-04 0:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 10:17 [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Maria Yu
2023-12-13 16:22 ` Matthew Wilcox
2023-12-13 18:27 ` Eric W. Biederman
2023-12-15 5:52 ` Aiqun Yu (Maria)
2023-12-28 22:20 ` Matthew Wilcox
2023-12-29 11:35 ` kernel test robot
2024-01-02 2:19 ` Aiqun Yu (Maria)
2024-01-02 9:14 ` Matthew Wilcox
2024-01-03 2:58 ` Aiqun Yu (Maria)
2024-01-03 18:18 ` Matthew Wilcox
2024-01-04 0:46 ` Aiqun Yu (Maria) [this message]
2024-01-03 6:03 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2023-12-25 8:19 Maria Yu
2023-12-25 8:26 ` Aiqun Yu (Maria)
2024-01-03 14:04 ` Jarkko Sakkinen
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=02e09c99-3431-4ba1-86bb-c4c68ebdc6b0@quicinc.com \
--to=quic_aiquny@quicinc.com \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=hdanton@sina.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=keescook@chromium.org \
--cc=kernel@quicinc.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=paul@paul-moore.com \
--cc=quic_pkondeti@quicinc.com \
--cc=serge@hallyn.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@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;
as well as URLs for NNTP newsgroup(s).