public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Chris Mason <chris.mason@oracle.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Gregory Haskins <ghaskins@novell.com>,
	Matthew Wilcox <matthew@wil.cx>, Andi Kleen <andi@firstfloor.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-btrfs <linux-btrfs@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Nick Piggin <npiggin@suse.de>,
	Peter Morreale <pmorreale@novell.com>,
	Sven Dietrich <SDietrich@novell.com>,
	Dmitry Adamushko <dmitry.adamushko@gmail.com>
Subject: [PATCH -v11 delta] mutex: implement adaptive spinning
Date: Wed, 14 Jan 2009 18:06:51 +0100	[thread overview]
Message-ID: <20090114170651.GA25904@elte.hu> (raw)
In-Reply-To: <alpine.LFD.2.00.0901140739110.6528@localhost.localdomain>


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> > > If I take out:
> > > 	/*
> > > 	 * If there are pending waiters, join them.
> > > 	 */
> > > 	if (!list_empty(&lock->wait_list))
> > > 		break;
> > > 
> > > 
> > > v10 pops dbench 50 up to 1800MB/s.  The other tests soundly beat my 
> > > spinning and aren't less fair.  But clearly this isn't a good solution.
> > 
> > i think since we already decided that it's ok to be somewhat unfair (_all_ 
> > batching constructs introduce unfairness, so the question is never 'should 
> > we?' but 'by how much?'), we should just take this out and enjoy the speed 
> 
> Yeah, let's just do it. It's going to be unfair, but let's see if the 
> unfairness is going to actually be noticeable in real life. I suspect it 
> isn't, and if it is, we can look at it again and see if there are other 
> approaches.
> 
> If it makes _that_ much of a difference on dbench, it's worth being 
> unfair even if it's just for some dubious benchmark.

Below is the final v10->v11 delta, for review. Beyond the tweak from 
Chris, there's small cleanups and the debug simplification from Johannes 
Weiner. We think this is the final version and are doing final tests now.

	Ingo

diff --git a/kernel/mutex.c b/kernel/mutex.c
index 0d5336d..703dec2 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -148,7 +148,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 
 	preempt_disable();
 	mutex_acquire(&lock->dep_map, subclass, 0, ip);
-#if defined(CONFIG_SMP) && !defined(CONFIG_DEBUG_MUTEXES)
+#ifdef CONFIG_SMP
 	/*
 	 * Optimistic spinning.
 	 *
@@ -162,21 +162,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 	 * Since this needs the lock owner, and this mutex implementation
 	 * doesn't track the owner atomically in the lock field, we need to
 	 * track it non-atomically.
-	 *
-	 * We can't do this for DEBUG_MUTEXES because that relies on wait_lock
-	 * to serialize everything.
 	 */
 
 	for (;;) {
 		struct thread_info *owner;
 
 		/*
-		 * If there are pending waiters, join them.
-		 */
-		if (!list_empty(&lock->wait_list))
-			break;
-
-		/*
 		 * If there's an owner, wait for it to either
 		 * release the lock or go to sleep.
 		 */
@@ -184,6 +175,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		if (owner && !mutex_spin_on_owner(lock, owner))
 			break;
 
+		if (atomic_cmpxchg(&lock->count, 1, 0) == 1) {
+			lock_acquired(&lock->dep_map, ip);
+			preempt_enable();
+			return 0;
+		}
+
 		/*
 		 * When there's no owner, we might have preempted between the
 		 * owner acquiring the lock and setting the owner field. If
@@ -193,13 +190,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		if (!owner && (need_resched() || rt_task(task)))
 			break;
 
-		if (atomic_cmpxchg(&lock->count, 1, 0) == 1) {
-			lock_acquired(&lock->dep_map, ip);
-			mutex_set_owner(lock);
-			preempt_enable();
-			return 0;
-		}
-
 		/*
 		 * The cpu_relax() call is a compiler barrier which forces
 		 * everything in this loop to be re-loaded. We don't need
@@ -209,7 +199,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		cpu_relax();
 	}
 #endif
-
 	spin_lock_mutex(&lock->wait_lock, flags);
 
 	debug_mutex_lock_common(lock, &waiter);
@@ -263,7 +252,6 @@ done:
 	lock_acquired(&lock->dep_map, ip);
 	/* got the lock - rejoice! */
 	mutex_remove_waiter(lock, &waiter, current_thread_info());
-	mutex_set_owner(lock);
 
 	/* set it to 0 if there are no waiters left: */
 	if (likely(list_empty(&lock->wait_list)))
@@ -439,10 +427,8 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count)
 	spin_lock_mutex(&lock->wait_lock, flags);
 
 	prev = atomic_xchg(&lock->count, -1);
-	if (likely(prev == 1)) {
-		mutex_set_owner(lock);
+	if (likely(prev == 1))
 		mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
-	}
 
 	/* Set it back to 0 if there are no waiters: */
 	if (likely(list_empty(&lock->wait_list)))

  parent reply	other threads:[~2009-01-14 17:06 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-12 15:37 [PATCH -v8][RFC] mutex: implement adaptive spinning Peter Zijlstra
2009-01-12 16:04 ` Linus Torvalds
2009-01-12 16:20   ` Linus Torvalds
2009-01-12 16:45     ` Chris Mason
2009-01-12 16:50       ` Peter Zijlstra
2009-01-12 17:14         ` Chris Mason
2009-01-12 17:24           ` Peter Zijlstra
2009-01-12 17:30             ` Chris Mason
2009-01-12 17:16     ` Peter Zijlstra
2009-01-12 17:33       ` Boaz Harrosh
2009-01-12 18:07         ` Peter Zijlstra
2009-01-12 16:13 ` Avi Kivity
2009-01-12 17:13   ` Peter Zijlstra
2009-01-12 17:23     ` Avi Kivity
2009-01-12 17:32     ` Avi Kivity
2009-01-14 16:46       ` Peter Zijlstra
2009-01-14 17:04         ` Nick Piggin
2009-01-14 17:23           ` Avi Kivity
2009-01-15  0:50             ` Nick Piggin
2009-01-13 15:15 ` [PATCH -v9][RFC] " Peter Zijlstra
2009-01-13 16:16   ` Linus Torvalds
2009-01-13 16:21     ` Peter Zijlstra
2009-01-13 16:39       ` Ingo Molnar
2009-01-13 16:40       ` Peter Zijlstra
2009-01-13 16:49         ` Linus Torvalds
2009-01-13 17:21           ` Peter Zijlstra
2009-01-13 18:33             ` Ingo Molnar
2009-01-13 18:40               ` Linus Torvalds
2009-01-13 19:01                 ` Ingo Molnar
2009-01-14  2:58             ` Chris Mason
2009-01-14 11:18               ` Dmitry Adamushko
2009-01-14 16:47                 ` Chris Mason
2009-01-14 17:32                   ` Dmitry Adamushko
2009-01-14 11:21               ` Ingo Molnar
2009-01-14 15:43                 ` Linus Torvalds
2009-01-14 16:23                   ` Chris Mason
2009-01-14 17:06                   ` Ingo Molnar [this message]
2009-01-14 17:00             ` [PATCH -v11][RFC] " Peter Zijlstra
2009-01-14 17:18               ` Nick Piggin
2009-01-14 17:22                 ` Peter Zijlstra
2009-01-15  0:46                   ` Nick Piggin
2009-01-15  7:44                     ` Peter Zijlstra
2009-01-15  7:52                       ` Nick Piggin
2009-01-14 18:33               ` [GIT PULL] adaptive spinning mutexes Ingo Molnar
2009-01-14 18:40                 ` Chris Mason
2009-01-15  9:53                   ` Ingo Molnar
2009-01-14 18:47                 ` Ingo Molnar
2009-01-14 19:28                   ` Ingo Molnar
2009-01-15 17:44                     ` Matthew Wilcox
2009-01-15 18:05                       ` Linus Torvalds
2009-01-15 18:08                         ` Ingo Molnar
2009-01-15 18:16                           ` Linus Torvalds
2009-01-15 19:26                             ` Chris Mason
2009-01-15 20:13                               ` Linus Torvalds
2009-01-15 21:04                                 ` Chris Mason
2009-01-15 22:03                                   ` Ingo Molnar
2009-01-16 13:32                               ` Folkert van Heusden
2009-01-16 13:57                                 ` Folkert van Heusden
2009-01-16 18:37                               ` Bill Davidsen
2009-01-16  0:53                             ` Paul E. McKenney
2009-01-16  1:01                               ` Linus Torvalds
2009-01-16  1:34                                 ` Paul E. McKenney
2009-01-16 14:07                                 ` Folkert van Heusden
2009-01-16  3:03                             ` Nick Piggin
2009-01-15 18:06                       ` Ingo Molnar
2009-01-14 18:53                 ` Andrew Morton
2009-01-14 19:00                   ` Ingo Molnar
2009-01-14 19:36                     ` Andrew Morton
2009-01-14 19:50                       ` Peter Zijlstra
2009-01-14 20:21                         ` Andrew Morton
2009-01-14 20:27                         ` Ingo Molnar
2009-01-14 20:44                           ` Andrew Morton
2009-01-14 20:14                       ` Ingo Molnar
2009-01-14 20:30                         ` Andrew Morton
2009-01-14 20:51                           ` Ingo Molnar
2009-01-14 21:06                             ` Andrew Morton
2009-01-14 21:14                               ` Ingo Molnar
2009-01-14 21:35                                 ` Andrew Morton
2009-01-14 23:23                                   ` Ingo Molnar
2009-01-15  0:55                                   ` Nick Piggin
2009-01-14 21:41                                 ` Ingo Molnar
2009-01-14 21:50                                   ` Kay Sievers
2009-01-14 22:34                                     ` Ingo Molnar
2009-01-15 11:45                                       ` Folkert van Heusden
2009-01-15 12:53                                       ` Chris Samuel
2009-01-14 19:23                   ` Peter Zijlstra
2009-01-14 19:33                     ` Ingo Molnar
2009-01-15  8:41             ` [PATCH] mutex: set owner only once on acquisition Johannes Weiner
2009-01-15  8:56               ` Johannes Weiner
2009-01-13 18:12           ` [PATCH -v9][RFC] mutex: implement adaptive spinning Ingo Molnar
2009-01-13 18:21             ` Linus Torvalds
2009-01-13 18:24               ` Ingo Molnar

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=20090114170651.GA25904@elte.hu \
    --to=mingo@elte.hu \
    --cc=SDietrich@novell.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=chris.mason@oracle.com \
    --cc=dmitry.adamushko@gmail.com \
    --cc=ghaskins@novell.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=npiggin@suse.de \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pmorreale@novell.com \
    --cc=tglx@linutronix.de \
    --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