This is a new implementation. After ~20 hours effort I couldn't get the current x86 rwsem code to work. This patch breaks all architechtures, but it's a good break and trivial to fix. It removes the `RW_LOCK_BIAS' arg in include/linux/sched.h:INIT_MM(). This code is architecture-independent. It is intended (by me) that all architectures dump their existing rwsem implementation and use this one. It creates include/linux/rw_semaphore.h and lib/rw_semaphore.c. If other architectures are to use this implementation of rwsems then the following must be done: 1: delete the existing rwsem code 2: in include/asm/semaphore.h, add: #define ARCH_USES_GENERIC_RWSEM #include It would be better to split rw_semaphore.h away from semaphore.h altogether, but that's a lot of mangling. There are several ways of designing rwsems. This patch takes a simple approach: - If a writer wants the lock and it's free, grant. - If a reader wants the lock and it's not held by a writer and there are no writers waiting for it, grant. - when the lock is being released, and there are both readers and writers waiting on it, we grant it to writers. So writers-starved-by-readers cannot occur. This is because new readers block when they see a writer is requesting the rwsem. Writers *can* starve readers. If a task is hammering away on down_write()/up_write() then readers never manage to get a hold of the semaphore. Hopefully this won't be a problem. It's fixable by introducing more state into the rwsem. It is not legal to do an up_read() or up_write() from interrupt context. See the comments in rw_semaphore.c It is not legal for one task to do more than one concurrent down_read() on an rwsem. You can't do: down_read(sem); ... down_read(sem); because an intervening down_write() by another task will cause deadlock. See comments in rw_semaphore.c Patches against 2.4.3-ac2 and 2.4.3 are attached. There's some rwsem testing code at http://www.uow.edu.au/~andrewm/linux/rwsem.tar.gz which may be used to verify this patch. rwsem-4.c is the most useful. -