From owner-freebsd-hackers@FreeBSD.ORG Wed May 2 08:35:29 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 451FD16A400 for ; Wed, 2 May 2007 08:35:29 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by mx1.freebsd.org (Postfix) with ESMTP id A43B413C44C for ; Wed, 2 May 2007 08:35:28 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: by ug-out-1314.google.com with SMTP id 71so161834ugh for ; Wed, 02 May 2007 01:35:26 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=A2UnbKn+OrjuCCsjrEMFsWoXTJkfq6h4oE3U/u274eFnEZYGgkpBguwbdPO8Vt2B67Tr4ObG6go3V4PLxJsqCagqjkg7pX4Y/e9FZkbiEXDsbMQ6qW2aLb2nYuZ0EDSLwGkdgVDUZzLh7kSPb+P4o6hFOP0lZqqn9SlLGrUuMKE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=tZS/N7D5phDx992/qtpuX2KGlWILGyuppotRId97esCZQT7R/yYD1ZD63sEdCiJM0HX+ORNlxeJKm19WCc0yhYDwL2104nC7+y05dhNKa2OBX29nW9zAfzUpR/W7Agtxbi26VhaEICa2jwBaH9213I9/J0npjuS9OGd6x2F8634= Received: by 10.82.173.19 with SMTP id v19mr876502bue.1178094926360; Wed, 02 May 2007 01:35:26 -0700 (PDT) Received: from ?172.31.5.21? ( [89.97.252.178]) by mx.google.com with ESMTP id b33sm1855224ika.2007.05.02.01.35.17; Wed, 02 May 2007 01:35:23 -0700 (PDT) Message-ID: <4638BE95.8070009@FreeBSD.org> Date: Wed, 02 May 2007 18:38:45 +0200 From: Attilio Rao User-Agent: Thunderbird 1.5 (X11/20060526) MIME-Version: 1.0 To: Matthew Dillon References: <200704262136.33196.hselasky@c2i.net> <46311708.5030002@elischer.org> <200704270753.05438.hselasky@c2i.net> <200704271739.l3RHdG7a009988@apollo.backplane.com> In-Reply-To: <200704271739.l3RHdG7a009988@apollo.backplane.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: Attilio Rao Cc: freebsd-hackers@freebsd.org, Julian Elischer , Hans Petter Selasky Subject: Re: msleep() on recursivly locked mutexes X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: attilio@FreeBSD.org List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2007 08:35:29 -0000 Matthew Dillon wrote: > The real culprit here is passing held mutexes to unrelated procedures > in the first place because those procedures might have to block, in > order so those procedures can release and reacquire the mutex. > That's just bad coding in my view. The unrelated procedure has no > clue as to what the mutex is or why it is being held and really has no > business messing with it. > > What I did was implement spinlocks with VERY restricted capabilities, > far more restricted then the capabilities of your mutexes. Our > spinlocks are meant only to be used to lock up tiny pieces of code > (like for ref counting or structural or flag-changing operations). > Plus the kernel automatically acts as if it were in a critical section > if it takes an interrupt while the current thread is holding a spinlock. > That way mainline code can just use a spinlock to deal with small bits > of interlocked information without it costing much in the way of > overhead. Well, this is currently what our spinmutexes do too. The couplet mtx_lock_spin()/mtx_unlock_spin() simply starts/exits a critical section (disabling interrupts in the while and avoiding preemption). They are intended to be used for very small pieces of code too. > I made the decision that ANYTHING more complex then that would have to > use a real lock, like a lockmgr lock or a token, depending on the > characteristics desired. To make it even more desireable I also > stripped down the lockmgr() lock implementation, removing numerous > bits that were inherited from very old code methodologies that have no > business being in a modern operating system, like LK_DRAIN. And I > removed the passing of an interlocking spinlock to the lockmgr code, > because that methodology was being massively abused in existing code > (and I do mean massively). Well, if you add a more smart interface, you have *exactly* our sx locks implementation. Basically, sx and lockmgr in FreeBSD just differs beacause of the lockmgr's stupid API, beacause of draining and beacause of interlock. But they are basically very very similar*. > I'm not quite sure what the best way to go is for FreeBSD, because > you guys have made your mutexes just as or even more sophisticated > then your normal locks in many respects, and you have like 50 different > types of locks now (I can't keep track of them all). Not sure what you mean with 'more sophisticated'... anyways... The only one problem I currently see with our locking primitives is that they are not very well documented (or part of the documentation is stale) and this can be a problem when there are a couple of locking primitives as we have but this doesn't mean that they are complex. Really, any primitive is very simple and is thought to be used in its particular context. The restriction we have on locks just are a sort of warning for people developing wrong locking strategies. For example, there are not tecnological difficulties in allowing holding mutexes when sleeping but if this really happen, probabilly there is a problem in your locking scheme. > If I were to offer advise it would be: Just stop trying to mix water > and hot wax. Stop holding mutexes across potentially blocking procedure > calls. Stop passing mutexes into unrelated bits of code in order for > them to be released and reacquired somewhere deep in that code. Just > doing that will probably solve all of the problems being reported. I cannot understand what part of the codes you are referring with this... Thanks, Attilio * Another difference is about upgrading, but I consider FreeBSD's lockmgr upgrading a really bad choice of design, and world could be a very better place without it