From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754464AbcHSEWc (ORCPT ); Fri, 19 Aug 2016 00:22:32 -0400 Received: from g2t4625.austin.hp.com ([15.73.212.76]:46529 "EHLO g2t4625.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750850AbcHSEWa (ORCPT ); Fri, 19 Aug 2016 00:22:30 -0400 Message-ID: <1471579876.4991.51.camel@j-VirtualBox> Subject: Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled From: Jason Low To: Peter Zijlstra Cc: jason.low2@hpe.com, Linus Torvalds , Ding Tianhong , Thomas Gleixner , Will Deacon , Ingo Molnar , imre.deak@intel.com, linux-kernel@vger.kernel.org, Waiman Long , Davidlohr Bueso , Tim Chen , terry.rudd@hpe.com, "Paul E. McKenney" , jason.low2@hp.com Date: Thu, 18 Aug 2016 21:11:16 -0700 In-Reply-To: <1471567197.4991.41.camel@j-VirtualBox> References: <1471567197.4991.41.camel@j-VirtualBox> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2016-08-18 at 17:39 -0700, Jason Low wrote: > Imre reported an issue where threads are getting starved when trying > to acquire a mutex. Threads acquiring a mutex can get arbitrarily delayed > sleeping on a mutex because other threads can continually steal the lock > in the fastpath and/or through optimistic spinning. > > Waiman has developed patches that allow waiters to return to optimistic > spinning, thus reducing the probability that starvation occurs. However, > Imre still sees this starvation problem in the workloads when optimistic > spinning is disabled. > > This patch adds an additional boolean to the mutex that gets used in > the CONFIG_SMP && !CONFIG_MUTEX_SPIN_ON_OWNER cases. The flag signifies > whether or not other threads need to yield to a waiter and gets set > when a waiter spends too much time waiting for the mutex. The threshold > is currently set to 16 wakeups, and once the wakeup threshold is exceeded, > other threads must yield to the top waiter. The flag gets cleared > immediately after the top waiter acquires the mutex. > > This prevents waiters from getting starved without sacrificing much > much performance, as lock stealing is still allowed and only > temporarily disabled when it is detected that a waiter has been waiting > for too long. Changes from v3 (in peterz locking/core) -> v4: 1. Fixed patch title. It should be "Prevent lock starvation when spinning is disabled" instead of "when spinning is enabled". 2. Call clear_yield_to_waiter() when a top waiter exits in the 'err' case. 3. Only clear yield_to_waiter if the thread is the top waiter and not if it is a non-top waiter that received a signal.