Re: [PATCH v2 5/5] locking/rwsem: Remove reader optimistic spinning

From: Waiman Long
Date: Tue Dec 08 2020 - 10:31:28 EST


On 12/8/20 5:07 AM, Peter Zijlstra wrote:
On Fri, Nov 20, 2020 at 11:14:16PM -0500, Waiman Long wrote:


@@ -1032,40 +901,16 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, int state, long count)
*
* We can take the read lock directly without doing
* rwsem_optimistic_spin() if the conditions are right.
This comment no longer makes sense..

You are right. I forgot to take that out.


- * Also wake up other readers if it is the first reader.
*/
- if (!(count & (RWSEM_WRITER_LOCKED | RWSEM_FLAG_HANDOFF)) &&
- rwsem_no_spinners(sem)) {
+ if (!(count & (RWSEM_WRITER_LOCKED | RWSEM_FLAG_HANDOFF))) {
rwsem_set_reader_owned(sem);
lockevent_inc(rwsem_rlock_steal);
- if (rcnt == 1)
- goto wake_readers;
- return sem;
- }
- /*
- * Save the current read-owner of rwsem, if available, and the
- * reader nonspinnable bit.
- */
- waiter.last_rowner = owner;
- if (!(waiter.last_rowner & RWSEM_READER_OWNED))
- waiter.last_rowner &= RWSEM_RD_NONSPINNABLE;
-
- if (!rwsem_can_spin_on_owner(sem, RWSEM_RD_NONSPINNABLE))
- goto queue;
-
- /*
- * Undo read bias from down_read() and do optimistic spinning.
- */
- atomic_long_add(-RWSEM_READER_BIAS, &sem->count);
- adjustment = 0;
- if (rwsem_optimistic_spin(sem, false)) {
since we're removing the optimistic spinning entirely on the read side.

Also, I was looking at skipping patch #4, which mucks with the reader
wakeup logic, and afaict this removal doesn't really depend on it.

Or am I missing something?

That is true. Patch 4 isn't essential for this series. So if you are general OK with the current patchset, I can send out v3 that remove patch 4 and make the your suggested change above.

Cheers,
Longman