From: Matthew Wilcox <willy@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Waiman Long <longman@redhat.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
linux-kernel@vger.kernel.org
Subject: Re: Wait for mutex to become unlocked
Date: Thu, 5 May 2022 01:38:14 +0100 [thread overview]
Message-ID: <YnMcdmx9ZwHcxTYe@casper.infradead.org> (raw)
In-Reply-To: <87pmksj0ah.ffs@tglx>
On Thu, May 05, 2022 at 02:22:30AM +0200, Thomas Gleixner wrote:
> > So this is Good. For the vast majority of cases, we avoid taking the
> > mmap read lock and the problem will appear much less often. But we can
> > do Better with a new API. You see, for this case, we don't actually
> > want to acquire the mmap_sem; we're happy to spin a bit, but there's no
> > point in spinning waiting for the writer to finish when we can sleep.
> > I'd like to write this code:
> >
> > again:
> > rcu_read_lock();
> > vma = vma_lookup();
> > if (down_read_trylock(&vma->sem)) {
> > rcu_read_unlock();
> > } else {
> > rcu_read_unlock();
> > rwsem_wait_read(&mm->mmap_sem);
> > goto again;
> > }
> >
> > That is, rwsem_wait_read() puts the thread on the rwsem's wait queue,
> > and wakes it up without giving it the lock. Now this thread will never
> > be able to block any thread that tries to acquire mmap_sem for write.
>
> Never?
>
> if (down_read_trylock(&vma->sem)) {
>
> ---> preemption by writer
Ah! This is a different semaphore. Yes, it can be preempted while
holding the VMA rwsem and block a thread which is trying to modify the
VMA which will then block all threads from faulting _on that VMA_,
but it won't affect page faults on any other VMA. It's only Better,
not Best (the Best approach was proposed on Monday afternoon, and
the other MM developers asked us to only go as far as Better and
see if that was good enough).
> The information gathered from /proc/pid/smaps is unreliable at the point
> where the lock is dropped already today. So it does not make a
> difference whether the VMAs have a 'read me if you really think it's
> useful' sideband information which gets updated when the VMA changes and
> allows to do:
Mmm. I'm not sure that we want to maintain the smaps information on
the off chance that somebody wants to query it.
> But looking at the stuff which gets recomputed and reevaluated in that
> proc/smaps code this makes a lot of sense, because most if not all of
> this information is already known at the point where the VMA is modified
> while holding mmap_sem for useful reasons, no?
I suspect the only way to know is to try to implement it, and then
benchmark it.
next prev parent reply other threads:[~2022-05-05 0:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 21:44 Matthew Wilcox
2022-05-05 0:22 ` Thomas Gleixner
2022-05-05 0:38 ` Matthew Wilcox [this message]
2022-05-05 1:14 ` Thomas Gleixner
2022-05-05 5:04 ` Paul E. McKenney
2022-05-05 5:21 ` Paul E. McKenney
2022-05-05 1:11 ` Waiman Long
[not found] ` <20220505015223.5132-1-hdanton@sina.com>
2022-05-05 4:12 ` Matthew Wilcox
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=YnMcdmx9ZwHcxTYe@casper.infradead.org \
--to=willy@infradead.org \
--cc=Liam.Howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®