Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jan 2008 19:12:12 -1000 (HST)
From:      Jeff Roberson <jroberson@chesapeake.net>
To:        arch@freebsd.org
Cc:        attilio@freebsd.org, ups@freebsd.org, rwatson@freebsd.org
Subject:   rwlock patch to prefer writers and improve spinning.
Message-ID:  <20080128190244.R957@desktop>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~jeff/rwlock.diff

Attilio and I have come up with a rwlock patch that prevents writer 
starvation by blocking readers whenever there are writers waiting on the 
turnstile.

To avoid deadlocks caused by recursive readers a new per-thread count of 
outstanding rw read locks is maintained.  When a thread is known to own 
read locks it will bypass the pending writers checks.  This could lead to 
writer starvation in pathological cases but will not deadlock.

In addition, I have added code to optimistically spin in the write lock 
path when there are readers.  The spin is limited by two counters.  One 
controls the number of spins while waiting for the lock state to change 
and another controls the number of lock state changes we'll observe before 
we give up.

To add these two features new flags were required.  I removed the 
recursion flag and instead there is an extra branch in the inlined code to 
check the recursion count before the atomic.  Another option would be to 
further increase the alignment of struct thread, however, I don't really 
think that is necessary.

This has been thoroughly tested with nokia's stack but it had to be 
forward ported to current.  Any rwlock users are encouraged to test before 
I commit.

Feedback is welcome.

Thanks,
Jeff



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