From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: psodagud@codeaurora.org, Kees Cook <keescook@chromium.org>,
Andy Lutomirski <luto@amacapital.net>,
Will Drewry <wad@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
Rik van Riel <riel@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Eric Biggers <ebiggers@google.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
sherryy@android.com, Vegard Nossum <vegard.nossum@oracle.com>,
Christoph Lameter <cl@linux.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Sasha Levin <alexander.levin@verizon.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: write_lock_irq(&tasklist_lock)
Date: Tue, 22 May 2018 23:17:24 +0200 [thread overview]
Message-ID: <20180522211724.GR12217@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CA+55aFyGHhPvbqGaA0+tx7fbH+Uc6sbGKk2PLoFYCt-agCOgOw@mail.gmail.com>
On Tue, May 22, 2018 at 01:27:17PM -0700, Linus Torvalds wrote:
> It's usually not a huge problem because there are so few writers, but what
> you're seeing is the writer starvation issue because readers can be
> plentiful.
qrwlock is a fair lock and should not exhibit writer starvation. Write
acquire time is of course proportional to the number of CPUs in the
system because each can be holding a reader, but once there is a pending
writer there should not be new readers.
> > Do we need write_lock_irq(&tasklist_lock) in below portion of code ? Can
> > I use write_unlock instead of write_lock_irq in portion of code?
>
> You absolutely need write_lock_irq(), because taking the tasklist_lock
> without disabling interrupts will deadlock very quickly due to an interrupt
> taking the tasklist_lock for reading.
>
> That said, the write_lock_irq(&tasklist_lock) could possibly be replaced
> with something like
>
> static void tasklist_write_lock(void)
> {
> unsigned long flags;
> local_irq_save(flags);
> while (!write_trylock(&tasklist_lock)) {
> local_irq_restore(flags);
> do { cpu_relax(); } while (write_islocked(&tasklist_lock));
> local_irq_disable();
> }
> }
>
> but we don't have that "write_islocked()" function.
You basically want to spin-wait with interrupts enabled, right? I think
there were problems with that, but I can't remember, my brain is
entirely shot for the day. But given how qrwlock is constructed, you'd
have to look at the arch spinlock implementation for that (qspinlock for
x86).
The obvious problem of course is:
spin_lock_irq(&L)
// contended
local_irq_enable();
while(...)
cpu_relax();
<IRQ>
spin_lock(&L);
Which because the spinlock is fair, is an instant deadlock.
You can do the IRQ enabled spin-wait for unfair locks, but by now all
our locks are fair (because we kept hitting starvation).
next prev parent reply other threads:[~2018-05-22 21:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 19:40 write_lock_irq(&tasklist_lock) Sodagudi Prasad
2018-05-22 20:27 ` write_lock_irq(&tasklist_lock) Linus Torvalds
2018-05-22 21:17 ` Peter Zijlstra [this message]
2018-05-22 21:31 ` write_lock_irq(&tasklist_lock) Linus Torvalds
2018-05-23 8:19 ` write_lock_irq(&tasklist_lock) Peter Zijlstra
2018-05-23 13:05 ` write_lock_irq(&tasklist_lock) Will Deacon
2018-05-23 15:25 ` write_lock_irq(&tasklist_lock) Linus Torvalds
2018-05-23 15:36 ` write_lock_irq(&tasklist_lock) Will Deacon
2018-05-23 16:26 ` write_lock_irq(&tasklist_lock) Linus Torvalds
2018-05-24 12:49 ` write_lock_irq(&tasklist_lock) Will Deacon
2018-05-24 13:51 ` write_lock_irq(&tasklist_lock) Boqun Feng
2018-05-24 17:37 ` write_lock_irq(&tasklist_lock) Sodagudi Prasad
2018-05-24 18:28 ` write_lock_irq(&tasklist_lock) Peter Zijlstra
2018-05-24 21:14 ` write_lock_irq(&tasklist_lock) Andrea Parri
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=20180522211724.GR12217@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.levin@verizon.com \
--cc=cl@linux.com \
--cc=ebiggers@google.com \
--cc=fweisbec@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=psodagud@codeaurora.org \
--cc=riel@redhat.com \
--cc=sherryy@android.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vegard.nossum@oracle.com \
--cc=wad@chromium.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