pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion
RFC PATCH 1/1 pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion
Wei Wang reported seeing priority inversion caused latencies caused by contention on pmsg_lock, and suggested it be switched to a rt_mutex.
I was initially hesitant this would help, as the tasks in that trace all seemed to be SCHED_NORMAL, so the benefit would be limited to only nice boosting.
However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case.
Feedback would be appreciate!
--- fs/pstore/pmsg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/pstore/pmsg.c +4 -3
@@ -7,9 +7,10 @@#include <linux/device.h> #include <linux/fs.h> #include <linux/uaccess.h> +#include <linux/rtmutex.h> #include "internal.h" -static DEFINE_MUTEX (pmsg_lock); +static DEFINE_RT_MUTEX (pmsg_lock);static ssize_t write_pmsg (struct file *file,const char __user *buf,size_t count,loff_t *ppos)
@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,if (!access_ok (buf, count))return -EFAULT ; -mutex_lock (&pmsg_lock); +rt_mutex_lock (&pmsg_lock); ret = psinfo->write_user (&record, buf); -mutex_unlock (&pmsg_lock); +rt_mutex_unlock (&pmsg_lock);return ret ? ret : count; }
Signature · 1 line
2.39.0.rc0.267.gcb52ba06e7-goog
Quoted 8 lines · John Stultz
Wei Wang reported seeing priority inversion caused latencies caused by contention on
pmsg_lock, and suggested it be switched to art_mutex.I was initially hesitant this would help, as the tasks in that trace all seemed to be
SCHED_NORMAL, so the benefit would be limited to only nice boosting.
Quoted 5 lines
However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case.
Feedback would be appreciate!
This looks fine to me. Is there an appropriate "Fixes:" tag that could be used?
-Kees
Quoted 46 lines
Cc Wei Wang <[email protected]>Cc Midas Chien<[email protected]>Cc Connor O'Brien <[email protected]>Cc Kees Cook <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Reported-by Wei Wang <[email protected]>Signed-off-by John Stultz <[email protected]>--- fs/pstore/pmsg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/pstore/pmsg.c +4
-3@@ -7,9 +7,10 @@#include <linux/device.h> #include <linux/fs.h> #include <linux/uaccess.h> +#include <linux/rtmutex.h> #include "internal.h" -static DEFINE_MUTEX (pmsg_lock); +static DEFINE_RT_MUTEX (pmsg_lock);static ssize_t write_pmsg (struct file *file,const char __user *buf,size_t count,loff_t *ppos)@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,if (!access_ok (buf, count))return -EFAULT ; -mutex_lock (&pmsg_lock); +rt_mutex_lock (&pmsg_lock); ret = psinfo->write_user (&record, buf); -mutex_unlock (&pmsg_lock); +rt_mutex_unlock (&pmsg_lock);return ret ? ret : count; }Signature · 1 line
2.39.0.rc0.267.gcb52ba06e7-goog
Signature · 1 line
Kees Cook
Quoted 9 lines · Kees Cook
Quoted 8 lines · John Stultz
Wei Wang reported seeing priority inversion caused latencies caused by contention on
pmsg_lock, and suggested it be switched to art_mutex.I was initially hesitant this would help, as the tasks in that trace all seemed to be
SCHED_NORMAL, so the benefit would be limited to only nice boosting.
Quoted 8 lines
Quoted 5 lines
However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case.
Feedback would be appreciate!
This looks fine to me. Is there an appropriate "Fixes:" tag that could be used?
Not other than the ~3.19 era original introduction of the pmsg.c file where that mutex was introduced, I don't think.
But I'll respin with that.
thanks
-john