Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755253AbZALRN7 (ORCPT ); Mon, 12 Jan 2009 12:13:59 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752833AbZALRNr (ORCPT ); Mon, 12 Jan 2009 12:13:47 -0500 Received: from bombadil.infradead.org ([18.85.46.34]:44140 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752771AbZALRNq (ORCPT ); Mon, 12 Jan 2009 12:13:46 -0500 Subject: Re: [PATCH -v8][RFC] mutex: implement adaptive spinning From: Peter Zijlstra To: Avi Kivity Cc: Linus Torvalds , Ingo Molnar , "Paul E. McKenney" , Gregory Haskins , Matthew Wilcox , Andi Kleen , Chris Mason , Andrew Morton , Linux Kernel Mailing List , linux-fsdevel , linux-btrfs , Thomas Gleixner , Nick Piggin , Peter Morreale , Sven Dietrich , Dmitry Adamushko In-Reply-To: <496B6C23.8000808@redhat.com> References: <1231774622.4371.96.camel@laptop> <496B6C23.8000808@redhat.com> Content-Type: text/plain Date: Mon, 12 Jan 2009 18:13:08 +0100 Message-Id: <1231780388.4371.185.camel@laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1632 Lines: 40 On Mon, 2009-01-12 at 18:13 +0200, Avi Kivity wrote: > One thing that worries me here is that the spinners will spin on a > memory location in struct mutex, which means that the cacheline holding > the mutex (which is likely to be under write activity from the owner) > will be continuously shared by the spinners, slowing the owner down when > it needs to unshare it. One way out of this is to spin on a location in > struct mutex_waiter, and have the mutex owner touch it when it schedules > out. Yeah, that is what pure MCS locks do -- however I don't think its a feasible strategy for this spin/sleep hybrid. > So: > - each task_struct has an array of currently owned mutexes, appended to > by mutex_lock() That's not going to fly I think. Lockdep does this but its very expensive and has some issues. We're currently at 48 max owners, and still some code paths manage to exceed that. > - mutex waiters spin on mutex_waiter.wait, which they initialize to zero > - when switching out of a task, walk the mutex list, and for each mutex, > bump each waiter's wait variable, and clear the owner array Which is O(n). > - when unlocking a mutex, bump the nearest waiter's wait variable, and > remove from the owner array > > Something similar might be done to spinlocks to reduce cacheline > contention from spinners and the owner. Spinlocks can use 'pure' MCS locks. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/