All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pstore: Revert pmsg_lock back to a normal mutex
@ 2023-03-02  6:27 John Stultz
  2023-03-02 13:24 ` Steven Rostedt
  2023-03-04  3:10 ` [PATCH v2] " John Stultz
  0 siblings, 2 replies; 33+ messages in thread
From: John Stultz @ 2023-03-02  6:27 UTC (permalink / raw)
  To: LKML
  Cc: John Stultz, Wei Wang, Midas Chien, Steven Rostedt, Kees Cook,
	Anton Vorontsov, Guilherme G. Piccoli, Tony Luck, kernel-team

This reverts commit 76d62f24db07f22ccf9bc18ca793c27d4ebef721.

So while priority inversion on the pmsg_lock is an occasional
problem that an rt_mutex would help with, in uses where logging
is writing to pmsg heavily from multiple threads, the pmsg_lock
can be heavily contended.

Normal mutexes can do adaptive spinning, which keeps the
contention overhead fairly low maybe adding on the order of 10s
of us delay waiting, but the slowpath w/ rt_mutexes makes the
blocked tasks sleep & wake. This makes matters worse when there
is heavy contentention, as it just allows additional threads to
run and line up to try to take the lock.

It devolves to a worse case senerio where the lock acquisition
and scheduling overhead dominates, and each thread is waiting on
the order of ~ms to do ~us of work.

Obviously, having tons of threads all contending on a single
lock for logging is non-optimal, so the proper fix is probably
reworking pstore pmsg to have per-cpu buffers so we don't have
contention.

But in the short term, lets revert the change to the rt_mutex
and go back to normal mutexes to avoid a potentially major
performance regression.

Cc: Wei Wang <wvw@google.com>
Cc: Midas Chien<midaschieh@google.com>
Cc: Chunhui Li (李春辉)" <chunhui.li@mediatek.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Anton Vorontsov <anton@enomsg.org>
Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: kernel-team@android.com
Fixes: 76d62f24db07 ("pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion")
Reported-by: Chunhui Li (李春辉)" <chunhui.li@mediatek.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
 fs/pstore/pmsg.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
index ab82e5f05346..b31c9c72d90b 100644
--- a/fs/pstore/pmsg.c
+++ b/fs/pstore/pmsg.c
@@ -7,10 +7,9 @@
 #include <linux/device.h>
 #include <linux/fs.h>
 #include <linux/uaccess.h>
-#include <linux/rtmutex.h>
 #include "internal.h"
 
-static DEFINE_RT_MUTEX(pmsg_lock);
+static DEFINE_MUTEX(pmsg_lock);
 
 static ssize_t write_pmsg(struct file *file, const char __user *buf,
 			  size_t count, loff_t *ppos)
@@ -29,9 +28,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
 	if (!access_ok(buf, count))
 		return -EFAULT;
 
-	rt_mutex_lock(&pmsg_lock);
+	mutex_lock(&pmsg_lock);
 	ret = psinfo->write_user(&record, buf);
-	rt_mutex_unlock(&pmsg_lock);
+	mutex_unlock(&pmsg_lock);
 	return ret ? ret : count;
 }
 
-- 
2.39.2.722.g9855ee24e9-goog


^ permalink raw reply related	[flat|nested] 33+ messages in thread
* Re: [PATCH] pstore: Revert pmsg_lock back to a normal mutex
@ 2023-03-03  7:06 Chunhui Li (李春辉)
  0 siblings, 0 replies; 33+ messages in thread
From: Chunhui Li (李春辉) @ 2023-03-03  7:06 UTC (permalink / raw)
  To: jstultz
  Cc: linux-kernel, keescook, rostedt, midaschieh, gpiccoli, anton,
	tony.luck, wvw, kernel-team

Tested-by: Chunhui Li <chunhui.li@mediatek.com>


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-03-08 20:41 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02  6:27 [PATCH] pstore: Revert pmsg_lock back to a normal mutex John Stultz
2023-03-02 13:24 ` Steven Rostedt
2023-03-02 19:39   ` John Stultz
2023-03-02 20:21     ` Steven Rostedt
2023-03-02 21:32       ` Steven Rostedt
2023-03-02 21:36         ` Steven Rostedt
2023-03-02 21:56           ` Steven Rostedt
2023-03-03  1:01             ` Steven Rostedt
2023-03-03 18:11               ` Joel Fernandes
2023-03-03 18:37                 ` Steven Rostedt
2023-03-03 19:25                   ` Joel Fernandes
2023-03-03 19:38                     ` Steven Rostedt
2023-03-03 20:36                       ` Qais Yousef
2023-03-04  3:21                         ` Joel Fernandes
2023-03-06 19:19                           ` Qais Yousef
2023-03-04  3:01                       ` Joel Fernandes
2023-03-04  3:23                         ` Joel Fernandes
2023-03-07 14:08                 ` Peter Zijlstra
2023-03-07 20:19                   ` Joel Fernandes
2023-03-06 18:30               ` John Stultz
2023-03-08  1:31               ` Steven Rostedt
2023-03-08 20:04                 ` John Stultz
2023-03-08 20:41                   ` Steven Rostedt
2023-03-02 22:41       ` David Laight
2023-03-02 22:53         ` Steven Rostedt
2023-03-04  3:10 ` [PATCH v2] " John Stultz
2023-03-05 16:36   ` Steven Rostedt
2023-03-06  1:03     ` Hillf Danton
2023-03-06 15:28       ` Steven Rostedt
2023-03-07  0:31         ` Hillf Danton
2023-03-07  1:58           ` Steven Rostedt
2023-03-06 18:27     ` John Stultz
2023-03-03  7:06 [PATCH] " Chunhui Li (李春辉)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.