locking/rwsem: Disable preemption while trying for rwsem lock
authorGokul krishna Krishnakumar <quic_gokukris@quicinc.com>
Thu, 8 Sep 2022 18:24:27 +0000 (23:54 +0530)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 15 Sep 2022 14:14:02 +0000 (16:14 +0200)
commit48dfb5d2560d36fb16c7d430c229d1604ea7d185
tree7c89454425f4b80076458a967928c7f224ae4281
parent2747b93ebbede2af2d7bb088b9ddae3193ceede8
locking/rwsem: Disable preemption while trying for rwsem lock

Make the region inside the rwsem_write_trylock non preemptible.

We observe RT task is hogging CPU when trying to acquire rwsem lock
which was acquired by a kworker task but before the rwsem owner was set.

Here is the scenario:
1. CFS task (affined to a particular CPU) takes rwsem lock.

2. CFS task gets preempted by a RT task before setting owner.

3. RT task (FIFO) is trying to acquire the lock, but spinning until
RT throttling happens for the lock as the lock was taken by CFS task.

This patch attempts to fix the above issue by disabling preemption
until owner is set for the lock. While at it also fix the issues
at the places where rwsem_{set,clear}_owner() are called.

This also adds lockdep annotation of preemption disable in
rwsem_{set,clear}_owner() on Peter Z. suggestion.

Signed-off-by: Gokul krishna Krishnakumar <quic_gokukris@quicinc.com>
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/r/1662661467-24203-1-git-send-email-quic_mojha@quicinc.com
kernel/locking/rwsem.c