aboutsummaryrefslogtreecommitdiff
path: root/lib/mpi
diff options
context:
space:
mode:
authorWaiman Long <longman@redhat.com>2020-11-20 23:14:13 -0500
committerPeter Zijlstra <peterz@infradead.org>2020-12-09 17:08:48 +0100
commit2f06f702925b512a95b95dca3855549c047eef58 (patch)
tree9632b4c7b8d4f3c4eb90df9b8ab6020f32b9e6fc /lib/mpi
parentc8fe8b0564388f41147326f31e4587171aacccd4 (diff)
locking/rwsem: Prevent potential lock starvation
The lock handoff bit is added in commit 4f23dbc1e657 ("locking/rwsem: Implement lock handoff to prevent lock starvation") to avoid lock starvation. However, allowing readers to do optimistic spinning does introduce an unlikely scenario where lock starvation can happen. The lock handoff bit may only be set when a waiter is being woken up. In the case of reader unlock, wakeup happens only when the reader count reaches 0. If there is a continuous stream of incoming readers acquiring read lock via optimistic spinning, it is possible that the reader count may never reach 0 and so the handoff bit will never be asserted. One way to prevent this scenario from happening is to disallow optimistic spinning if the rwsem is currently owned by readers. If the previous or current owner is a writer, optimistic spinning will be allowed. If the previous owner is a reader but the reader count has reached 0 before, a wakeup should have been issued. So the handoff mechanism will be kicked in to prevent lock starvation. As a result, it should be OK to do optimistic spinning in this case. This patch may have some impact on reader performance as it reduces reader optimistic spinning especially if the lock critical sections are short the number of contending readers are small. Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Davidlohr Bueso <dbueso@suse.de> Link: https://lkml.kernel.org/r/20201121041416.12285-3-longman@redhat.com
Diffstat (limited to 'lib/mpi')
0 files changed, 0 insertions, 0 deletions