Blob Blame History Raw
From dc02db32c1549120c1dc8ce80c20a9091a92d8cf Mon Sep 17 00:00:00 2001
From: Davidlohr Bueso <dbueso@suse.de>
Date: Thu, 1 Oct 2020 09:01:42 -0700
Subject: [PATCH] locking/rwsem: Disable reader optimistic spinning

References: bnc#1176588
Patch-mainline: Never, obsoleted in 5.11-rc1 by 617f3ef95177840c77f59c2aec1029d27d5547d6 (jeffm)

Reader spinning can cause performance issues in workloads that
could otherwise benefit if the rwsem waiter would immediately
block instead of busy waiting upon a contended lock. In addition
there can be architectural differences in the spinning that can
further augment such problems such as pause latencies and the
overall cost of cacheline bouncing when trying to take the rwsem.

This patch restores behavior closer to SLE15-SP1 where only
writers can spin, alleviating a lot of the contention (and length)
of the MCS queue. Writers can still spin on a reader-owned lock
until timedout.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Mel Gorman <mgorman@suse.de>
---
 kernel/locking/rwsem.c | 6 ++++++
 1 file changed, 6 insertions(+)

--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -659,6 +659,12 @@ static inline bool rwsem_can_spin_on_own
 	unsigned long flags;
 	bool ret = true;
 
+	/*
+	 * Force readers down the slowpath.
+	 */
+	if (nonspinnable == RWSEM_RD_NONSPINNABLE)
+		return false;
+
 	if (need_resched()) {
 		lockevent_inc(rwsem_opt_fail);
 		return false;