Skip to contentSkip to conversation

locking/rwsem: Handle handoff bit inheritance

PATCH New Waiman Long 1 participant 1 message Nov 7, 2021 Locking primitives

lore
Share & tools
lore

Waiman Long

author reviewer
#0 lore raw

PATCH 1/1 locking/rwsem: Handle handoff bit inheritance

When a queue head writer set the handoff bit, it will clear it when the writer is being killed on its way out without acquiring the lock. That is not the case for a queue head reader. The easy thing to do is to let the next waiter inherit the handoff bit especially if the next one is also a reader.

In the case of a writer inheriting the handoff bit, we need to make sure that writer sets its state correctly to avoid leaving the handoff bit dangling if it is killed or interrupted before getting the lock. We also need to make sure that the handoff bit is always cleared when the wait queue is empty to avoid having the handoff bit set with no waiter.

A new lock event is added to keep track of this writer handoff bit inheritance.

Fixes 4f23dbc1e657 ("locking/rwsem: Implement lock handoff to prevent lock starvation")
---
 kernel/locking/lock_events_list.h |  1 +
 kernel/locking/rwsem.c            | 50 +++++++++++++++++++++++--------
 2 files changed, 38 insertions(+), 13 deletions(-)
kernel/locking/lock_events_list.h +1 -0
index 97fb6f3f840a..0eddfb2e6e74 100644
@@ -67,3 +67,4 @@ LOCK_EVENT(rwsem_rlock_handoff)	/* # of read lock handoffs		*/
 LOCK_EVENT(rwsem_wlock)		/* # of write locks acquired		*/
 LOCK_EVENT(rwsem_wlock_fail)	/* # of failed write lock acquisitions	*/
 LOCK_EVENT(rwsem_wlock_handoff)	/* # of write lock handoffs		*/
+LOCK_EVENT(rwsem_inherit_handoff) /* # of handoff inheritance		*/
kernel/locking/rwsem.c +37 -13

102 lines not on this page · raw message

Signature · 1 line
2.27.0