From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Chris Mason <chris.mason@oracle.com>,
linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2] mutex: Apply adaptive spinning on mutex_trylock()
Date: Wed, 30 Mar 2011 13:29:38 +0200 [thread overview]
Message-ID: <1301484578.4859.178.camel@twins> (raw)
In-Reply-To: <20110330081716.GE17523@htj.dyndns.org>
On Wed, 2011-03-30 at 10:17 +0200, Tejun Heo wrote:
> Hey, Peter.
>
> On Tue, Mar 29, 2011 at 07:37:33PM +0200, Peter Zijlstra wrote:
> > On Tue, 2011-03-29 at 19:09 +0200, Tejun Heo wrote:
> > > Here's the combined patch I was planning on testing but didn't get to
> > > (yet). It implements two things - hard limit on spin duration and
> > > early break if the owner also is spinning on a mutex.
> >
> > This is going to give massive conflicts with
> >
> > https://lkml.org/lkml/2011/3/2/286
> > https://lkml.org/lkml/2011/3/2/282
> >
> > which I was planning to stuff into .40
>
> I see. Adapting shouldn't be hard. The patch is in proof-of-concept
> stage anyway.
>
> > > + * Forward progress is guaranteed regardless of locking ordering by never
> > > + * spinning longer than MAX_MUTEX_SPIN_NS. This is necessary because
> > > + * mutex_trylock(), which doesn't have to follow the usual locking
> > > + * ordering, also uses this function.
> >
> > While that puts a limit on things it'll still waste time. I'd much
> > rather pass an trylock argument to mutex_spin_on_owner() and then bail
> > on owner also spinning.
>
> Do we guarantee or enforce that the lock ownership can't be
> transferred to a different task? If we do, the recursive spinning
> detection is enough to guarantee forward progress.
The only way to switch owner is for the current owner to release and a
new owner to acquire the lock. Also we already bail the spin loop when
owner changes.
> > > + if (task_thread_info(rq->curr) != owner ||
> > > + rq->spinning_on_mutex || need_resched() ||
> > > + local_clock() > start + MAX_MUTEX_SPIN_NS) {
> >
> > While we did our best with making local_clock() cheap, I'm still fairly
> > uncomfortable with putting it in such a tight loop.
>
> That's one thing I didn't really understand. It seems the spinning
> code tried to be light on CPU cycle usage, but we're wasting CPU
> cycles there anyway. If the spinning can become smarter using some
> CPU cycles, isn't that a gain? Why is the spinning code optimizing
> for less CPU cycles?
Loop exit latency mostly, the lighter the loop, the faster you're
through the less time you waste once the condition is true, but yeah,
what you say is true too, its a balance game as always.
> Also, it would be great if you can share what you're using for locking
> performance measurements. My attempts with dbench didn't end too
> well. :-(
The thing I used for the initial implementation is mentioned in the
changelog (0d66bf6d3):
Testing with Ingo's test-mutex application (http://lkml.org/lkml/2006/1/8/50)
gave a 345% boost for VFS scalability on my testbox:
# ./test-mutex-shm V 16 10 | grep "^avg ops"
avg ops/sec: 296604
# ./test-mutex-shm V 16 10 | grep "^avg ops"
avg ops/sec: 85870
I've no idea how heavy that is on trylock though, you'd have to look at
that.
Chris did some improvements using dbench in ac6e60ee4 but clearly that
isn't working for you.
next prev parent reply other threads:[~2011-03-30 11:29 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-23 15:37 [RFC PATCH] mutex: Apply adaptive spinning on mutex_trylock() Tejun Heo
2011-03-23 15:40 ` Tejun Heo
2011-03-23 15:48 ` Linus Torvalds
2011-03-23 15:52 ` Tejun Heo
2011-03-23 19:46 ` Andrey Kuzmin
2011-03-24 8:18 ` Ingo Molnar
2011-03-25 3:24 ` Steven Rostedt
2011-03-25 10:29 ` Ingo Molnar
2011-03-24 9:41 ` [PATCH 1/2] Subject: mutex: Separate out mutex_spin() Tejun Heo
2011-03-24 9:41 ` [PATCH 2/2] mutex: Apply adaptive spinning on mutex_trylock() Tejun Heo
2011-03-25 3:39 ` Steven Rostedt
2011-03-25 4:38 ` Linus Torvalds
2011-03-25 6:53 ` Tejun Heo
2011-03-25 13:10 ` Steven Rostedt
2011-03-25 13:29 ` Steven Rostedt
2011-03-25 11:13 ` Andrey Kuzmin
2011-03-25 13:12 ` Steven Rostedt
2011-03-25 13:50 ` Andrey Kuzmin
2011-03-25 14:05 ` Steven Rostedt
2011-03-25 19:51 ` Ingo Molnar
2011-03-25 10:12 ` Tejun Heo
2011-03-25 10:31 ` Ingo Molnar
2011-03-29 16:37 ` Tejun Heo
2011-03-29 17:09 ` Tejun Heo
2011-03-29 17:37 ` Peter Zijlstra
2011-03-30 8:17 ` Tejun Heo
2011-03-30 11:29 ` Peter Zijlstra [this message]
2011-03-30 11:46 ` Chris Mason
2011-03-30 11:52 ` Peter Zijlstra
2011-03-30 11:59 ` Chris Mason
2011-03-24 9:42 ` [PATCH 1/2] Subject: mutex: Separate out mutex_spin() Tejun Heo
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=1301484578.4859.178.camel@twins \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=chris.mason@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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).