Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Apr 2007 15:47:52 +0100 (BST)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Craig Boston <craig@xfoil.gank.org>
Cc:        freebsd-fs@freebsd.org, Dag-Erling Sm?rgrav <des@des.no>, "Rick C. Petty" <rick-freebsd@kiwi-computer.com>, freebsd-current@freebsd.org
Subject:   Re: ZFS committed to the FreeBSD base.
Message-ID:  <20070413154418.M65660@fledge.watson.org>
In-Reply-To: <20070413143550.GA19881@nowhere>
References:  <86k5wo55s0.fsf@dwp.des.no> <20070407203411.GJ8831@cicely12.cicely.de> <86wt0n3mxv.fsf@dwp.des.no> <20070411214911.GA38351@VARK.MIT.EDU> <20070412073605.GB834@turion.vk2pj.dyndns.org> <86ps6aht1i.fsf@dwp.des.no> <20070412160603.GB92079@keira.kiwi-computer.com> <20070412185159.GB95302@nowhere> <86slb5e33a.fsf@dwp.des.no> <20070413164840.V31079@besplex.bde.org> <20070413143550.GA19881@nowhere>

next in thread | previous in thread | raw e-mail | index | archive | help

On Fri, 13 Apr 2007, Craig Boston wrote:

> On Fri, Apr 13, 2007 at 05:34:56PM +1000, Bruce Evans wrote:
>
>> Doesn't everyone who uses atomic operations knows that they are expensive? 
>> :)
>
> Yes, though hopefully they should at least be faster than using a mutex, 
> though for cmpxchg8b it sounds like that may not necessarily be the case...

A common example of this not being the case is statistics updates: it doesn't 
take too many statistics being updated at once before it makes more sense to 
use a mutex than individual atomic instructions, as mutex lock and unlock, in 
the uncontended case, involve an atomic instruction each (with memory 
barriers).  Then it becomes more semantic: is using non-blocking primitives 
preferable, or are there consistency requirements between "atomically" updated 
fields?  If contention never happens, then maybe you get consistency for free 
by using a mutex.

As a general rule, unless it's a very clear-cut case (a simple counter), I 
would encourage people to program with mutexes rather than directly with 
atomic instructions.  It prevents them from having to deal with really weird 
stuff that happens with weaker memory consistency.

Robert N M Watson
Computer Laboratory
University of Cambridge



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070413154418.M65660>