linux-stable/fs/pstore
John Stultz b4f1e0138d pstore: Revert pmsg_lock back to a normal mutex
[ Upstream commit 5239a89b06 ]

This reverts commit 76d62f24db.

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.

After this change landed, it was reported that cases where the
mutex locking overhead was commonly adding on the order of 10s
of usecs delay had suddenly jumped to ~msec delay with rtmutex.

It seems the slight differences in the locks under this level
of contention causes the normal mutexes to utilize the spinning
optimizations, while the rtmutexes end up in the sleeping
slowpath (which allows additional threads to pile on trying
to take the lock).

In this case, 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.

Additionally, Steven Rostedt has provided some furhter
optimizations for rtmutexes that improves the rtmutex spinning
path, but at least in my testing, I still see the test tripping
into the sleeping path on rtmutexes while utilizing the spinning
path with mutexes.

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. And we can work on optimizations to both
rtmutexes and finer-grained locking for pstore pmsg in the
future.

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: 76d62f24db ("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>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230308204043.2061631-1-jstultz@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-11 23:11:20 +09:00
..
Kconfig pstore: Make sure CONFIG_PSTORE_PMSG selects CONFIG_RT_MUTEXES 2022-12-23 10:33:27 -08:00
Makefile
blk.c pstore/blk: Use "%lu" to format unsigned long 2021-11-21 09:44:19 -08:00
ftrace.c pstore/ftrace: Allow immediate recording 2021-11-18 10:29:52 -08:00
inode.c pstore: Add priv field to pstore_record for backend specific use 2022-06-24 20:40:04 +02:00
internal.h
platform.c pstore: Alert on backend write error 2022-10-19 09:25:39 -07:00
pmsg.c pstore: Revert pmsg_lock back to a normal mutex 2023-05-11 23:11:20 +09:00
ram.c pstore: Properly assign mem_type property 2022-12-23 10:34:25 -08:00
ram_core.c pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP 2022-12-05 16:15:09 -08:00
ram_internal.h pstore/ram: Set freed addresses to NULL 2022-10-19 09:25:39 -07:00
zone.c pstore/zone: Use GFP_ATOMIC to allocate zone buffer 2022-10-17 13:14:10 -07:00