Subject: Re: newlock
To: Charles M. Hannum <mycroft@MIT.EDU>
From: Andrew Doran <ad@NetBSD.org>
Date: 09/02/2006 20:59:39
On Sat, Sep 02, 2006 at 02:30:05PM -0400, Charles M. Hannum wrote:
> > If we loop on a normal memory read then normally the cache line will stay
> > valid in both (all) of the cpus' cache.
> And this is where you go wrong.
> Any time the current lock holder writes to that cache line, it has to
> transition to exclusive (which forces an invalidation on the other
> CPU(s)) and then immediately back to shared (which causes a writeback).
> This is very expensive, and it happens all the time.
The current implementation does exponential back-off on the read attempts.
That's not ideal, but bear in mind the common case with mutexes at least
should be an uncontested acquire, where having the data in the same line as
the lock makes sense. If the mutex is heavily contended, then the locking
strategy is broken and we have a bigger problem. Don't you agree?