Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Nov 2007 01:55:46 +0100
From:      "Attilio Rao" <attilio@freebsd.org>
To:        dima <_pppp@mail.ru>
Cc:        arch@freebsd.org, Alfred Perlstein <alfred@freebsd.org>
Subject:   Re: rwlocks, correctness over speed.
Message-ID:  <3bbf2fe10711221655n33d4d0c7mbeece529a3d08642@mail.gmail.com>
In-Reply-To: <E1IvFAP-000BFB-00._pppp-mail-ru@f106.mail.ru>
References:  <20071121222319.GX44563@elvis.mu.org> <E1IvFAP-000BFB-00._pppp-mail-ru@f106.mail.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
2007/11/22, dima <_pppp@mail.ru>:
> > In summary, I am proposing (temporarily) making read-recursion
> > on rwlocks not supported in order to avoid livelock due to writer
> > starvation.
>
> It's not the matter of recursion, but the implementation itself.
> Comments from the code:
> <quote>
>          * Note that we don't make any attempt to try to block read
>          * locks once a writer has blocked on the lock.  The reason is
>          * that we currently allow for read locks to recurse and we
>          * don't keep track of all the holders of read locks.  Thus, if
>          * we were to block readers once a writer blocked and a reader
>          * tried to recurse on their reader lock after a writer had
>          * blocked we would end up in a deadlock since the reader would
>          * be blocked on the writer, and the writer would be blocked
>          * waiting for the reader to release its original read lock.
> </quote>
> Such a design would provide writer starvation regardless the presence of recursion. If a writer is waiting for the lock, no more readers should be allowed. It's a simple rule to avoid writer starvation in rw-locks. Recursion does need an accurate accounting of all the current readers.
> I've posted a reference implementation of rw-locks to this mailing list about a year ago. My proposal was to use an array to account the current readers (the array can be handled without any additional locking). It limits the maximum read contention, though.

The real problem with this is that currently we have a fast path which
is only an atomic add. What you propose will make the fast path too
slow (not mentioning the limitation), and this is somethign we should
avoid if possible.

Attilio


-- 
Peace can only be achieved by understanding - A. Einstein



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