From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757372AbcHWM4d (ORCPT ); Tue, 23 Aug 2016 08:56:33 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:34938 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbcHWM4b (ORCPT ); Tue, 23 Aug 2016 08:56:31 -0400 Date: Tue, 23 Aug 2016 14:56:19 +0200 From: Peter Zijlstra To: Linus Torvalds , Waiman Long , Jason Low , Ding Tianhong , Thomas Gleixner , Will Deacon , Ingo Molnar , Imre Deak , Linux Kernel Mailing List , Davidlohr Bueso , Tim Chen , Terry Rudd , "Paul E. McKenney" , Jason Low Subject: Re: [RFC][PATCH 3/3] locking/mutex: Add lock handoff to avoid starvation Message-ID: <20160823125619.GC10138@twins.programming.kicks-ass.net> References: <20160823124617.015645861@infradead.org> <20160823124856.898171453@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160823124856.898171453@infradead.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 23, 2016 at 02:46:20PM +0200, Peter Zijlstra wrote: > @@ -573,8 +600,14 @@ __mutex_lock_common(struct mutex *lock, > schedule_preempt_disabled(); > spin_lock_mutex(&lock->wait_lock, flags); > > + if (__mutex_owner(lock) == current) > + break; > + > if (__mutex_trylock(lock)) > break; > + > + if (__mutex_waiter_is_first(lock, &waiter)) > + __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); > } > __set_task_state(task, TASK_RUNNING); > And 'obviously' we can add a spin-on-owner loop in there as well, as Waiman's patches did, but I didn't bother pulling that in for now.