]> git.karo-electronics.de Git - karo-tx-linux.git/commit
percpu_rw_semaphore: reimplement to not block the readers unnecessarily
authorOleg Nesterov <oleg@redhat.com>
Fri, 9 Nov 2012 03:04:52 +0000 (14:04 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 9 Nov 2012 03:08:59 +0000 (14:08 +1100)
commitd4db3700dce923db8cc473f364e82072186f050c
tree64eb8a3a5ab2b00110f7ac089114c2ea86ec417d
parentdb0bf236c6c4f6b87b37b7ea74faf6f0caab17a6
percpu_rw_semaphore: reimplement to not block the readers unnecessarily

Currently the writer does msleep() plus synchronize_sched() 3 times to
acquire/release the semaphore, and during this time the readers are
blocked completely.  Even if the "write" section was not actually started
or if it was already finished.

With this patch down_write/up_write does synchronize_sched() twice and
down_read/up_read are still possible during this time, just they use the
slow path.

percpu_down_write() first forces the readers to use rw_semaphore and
increment the "slow" counter to take the lock for reading, then it
takes that rw_semaphore for writing and blocks the readers.

Also.  With this patch the code relies on the documented behaviour of
synchronize_sched(), it doesn't try to pair synchronize_sched() with
barrier.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anton Arapov <anton@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/percpu-rwsem.h
lib/Makefile
lib/percpu-rwsem.c [new file with mode: 0644]