Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757329AbcC2Pjx (ORCPT ); Tue, 29 Mar 2016 11:39:53 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:34977 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbcC2Pjw (ORCPT ); Tue, 29 Mar 2016 11:39:52 -0400 Date: Tue, 29 Mar 2016 17:39:35 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Linus Torvalds , Ding Tianhong , Jason Low , Davidlohr Bueso , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen Subject: Re: [PATCH v3 2/3] locking/mutex: Enable optimistic spinning of woken task in wait queue Message-ID: <20160329153935.GL3408@twins.programming.kicks-ass.net> References: <1458668804-10138-1-git-send-email-Waiman.Long@hpe.com> <1458668804-10138-3-git-send-email-Waiman.Long@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1458668804-10138-3-git-send-email-Waiman.Long@hpe.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1455 Lines: 34 On Tue, Mar 22, 2016 at 01:46:43PM -0400, Waiman Long wrote: > Ding Tianhong reported a live-lock situation where a constant stream > of incoming optimistic spinners blocked a task in the wait list from > getting the mutex. > > This patch attempts to fix this live-lock condition by enabling the > woken task in the wait queue to enter into an optimistic spinning > loop itself in parallel with the regular spinners in the OSQ. This > should prevent the live-lock condition from happening. I would very much like a few words on how fairness is preserved. Because while the waiter remains on the wait_list while it spins, and therefore unlock()s will only wake it, and we'll only contend with the one waiter, the fact that we have two spinners is not fair or starvation proof at all. By adding the waiter to the OSQ we get only a single spinner and force 'fairness' by queuing. I say 'fairness' because the OSQ (need_resched) cancellation can still take the waiter out again and let even more new spinners in. > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c > index 5dd6171..5c0acee 100644 > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -538,6 +538,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, > struct task_struct *task = current; > struct mutex_waiter waiter; > unsigned long flags; > + bool acquired = false; /* True if the lock is acquired */ Superfluous space there.