locking/rwsem: Conditionally wake waiters in reader/writer slowpaths
authorWaiman Long <longman@redhat.com>
Tue, 22 Mar 2022 15:20:58 +0000 (11:20 -0400)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 5 Apr 2022 08:24:35 +0000 (10:24 +0200)
commit54c1ee4d614d52844cf24c46d8415bf1392021d0
tree3611f9ad3f48204ed7581fd53597afade07eb21f
parentf9e21aa9e6fb11355e54c8949a390d49ca21cde1
locking/rwsem: Conditionally wake waiters in reader/writer slowpaths

In an analysis of a recent vmcore, a reader-owned rwsem was found with
385 readers but no writer in the wait queue. That is kind of unusual
but it may be caused by some race conditions that we have not fully
understood yet. In such a case, all the readers in the wait queue should
join the other reader-owners and acquire the read lock.

In rwsem_down_write_slowpath(), an incoming writer will try to
wake up the front readers under such circumstance. That is not
the case for rwsem_down_read_slowpath(), add a new helper function
rwsem_cond_wake_waiter() to do wakeup and use it in both reader and
writer slowpaths to have a consistent and correct behavior.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220322152059.2182333-3-longman@redhat.com
kernel/locking/rwsem.c