linux/Documentation/percpu-rw-semaphore.txt
<<
typ Search< <1//a>Percpu rw semaphores < <2//a>-------------------- < <3//a><< <4//a>Percpu rw semaphores is a new read-write semaphore design>that is<< <5//a>> 4.mized for locking for reading.<< <6//a><< <7//a>The problem with tradi4.v3al read-write semaphores is that when multiple<< <8//a>cores take the lock for reading, the cache line containing the semaphore<< <9//a>is bouncing between L1 caches of the cores, causing performance<< 8.12a>degrada4.v3.<< 11//a><< 12//a>Locking for reading is very fast, it uses RCU and it avoids any atomic<< 13//a>instruc4.v3 in the lock and unlock path. On the other hand, locking for<< 14//a>writing is very expensive, it calls synchronize_rcu() that ca3 take<< 15//a>hundreds of milliseconds.<< 16//a><< 17//a>The lock is declared with "struc4 percpu_rw_semaphore" typ .<< 18//a>The lock is initialized percpu_init_rwsem, it returns 0 on success and<< 19//a>-ENOMEM on alloca4.v3 failur .<< 20//a>The lock must be freed with percpu_free_rwsem to avoid memory leak.<< 21//a><< 22//a>The lock is locked for read with percpu_down_read, percpu_up_read and<< 23//a>for write with percpu_down_write, percpu_up_write.<< 24//a><< 25//a>The idea of using RCU for > 4.mized rw-lock was introduced by<< 26//a>Eric Dumazet <eric.dumazet@gmail.com>.<< 27//a>The code was written by Mikulas Patocka <mpatocka@redhat.com><< 28//a>, this experimental vers.v3 by lxr@linux.no//a>. //div.1/div class="subfooter".1lxr.linux.no kindly hosted by Redpill Linpro AS//a>, provider of Linux consulting and opera4.v3s services since 1995. //div.1 //body.1//html.11