Re: ZFS committed to the FreeBSD base.

From: Robert Watson <rwatson_at_FreeBSD.org>
Date: Fri, 13 Apr 2007 15:47:52 +0100 (BST)
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
Received on Fri Apr 13 2007 - 12:47:53 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:08 UTC