From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965435AbcBBVTU (ORCPT ); Tue, 2 Feb 2016 16:19:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:41296 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964891AbcBBVTR (ORCPT ); Tue, 2 Feb 2016 16:19:17 -0500 Date: Tue, 2 Feb 2016 13:19:06 -0800 From: Davidlohr Bueso To: Peter Zijlstra Cc: Ding Tianhong , Waiman Long , Jason Low , Ingo Molnar , "linux-kernel@vger.kernel.org" , Linus Torvalds , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen , Waiman Long Subject: Re: [PATCH] locking/mutex: Avoid spinner vs waiter starvation Message-ID: <20160202211906.GD16147@linux-uzut.site> References: <20160122085422.GO6357@twins.programming.kicks-ass.net> <1453458019.9727.8.camel@j-VirtualBox> <20160122105312.GQ6357@twins.programming.kicks-ass.net> <20160122105652.GE6375@twins.programming.kicks-ass.net> <20160122110653.GF6375@twins.programming.kicks-ass.net> <56A235DC.2060900@hpe.com> <56A48566.9040206@huawei.com> <20160129095347.GA6356@twins.programming.kicks-ass.net> <56AC0F74.2040808@huawei.com> <20160201100824.GO6357@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20160201100824.GO6357@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 01 Feb 2016, Peter Zijlstra wrote: >Subject: locking/mutex: Avoid spinner vs waiter starvation >From: Peter Zijlstra >Date: Fri, 22 Jan 2016 12:06:53 +0100 > >Ding Tianhong reported that under his load the optimistic spinners >would totally starve a task that ended up on the wait list. > >Fix this by ensuring the top waiter also partakes in the optimistic >spin queue. > >There are a few subtle differences between the assumed state of >regular optimistic spinners and those already on the wait list, which >result in the @acquired complication of the acquire path. > >Most notable are: > > - waiters are on the wait list and need to be taken off > - mutex_optimistic_spin() sets the lock->count to 0 on acquire > even though there might be more tasks on the wait list. Right, the main impact I see with these complications are that the window of when a waiter takes the lock via spinning and then acquires the wait_lock to remove itself from the list, will allow an unlock thread to set the lock as available in the fastpath which could in turn allow a third thread the steal the lock. With high contention, this window will be come obviously larger as we contend for the wait_lock. CPU-0 CPU-1 CPU-3 __mutex_lock_common mutex_optimistic_spin (->count now 0) __mutex_fastpath_unlock (->count now 1) __mutex_fastpath_lock (stolen) spin_lock_mutex(&lock->wait_lock, flags); But we've always been bad when it comes to counter and waiters. Thanks, Davidlohr