ANDROID: fs/proc: Perform priority inheritance around access_remote_vm()

It holds mmap_sem lock which is a hot path. Some debug daemons can end
up holding this lock to get the cmdline of a process, which can result
in slowing down this process.

Add hooks around the calls to allow vendors to implement a simple prio
inheritance scheme to deal with this.

Bug: 289412815
Signed-off-by: Qais Yousef <qyousef@google.com>
Change-Id: I160637b30e5bd58d5978b25be8a21ce025175ec3
This commit is contained in:
Qais Yousef 2023-07-11 22:37:40 +00:00 committed by Treehugger Robot
parent 37c1a91404
commit b821a3c8fc
3 changed files with 22 additions and 0 deletions

View File

@ -98,6 +98,7 @@
#include <linux/cn_proc.h>
#include <linux/cpufreq_times.h>
#include <trace/events/oom.h>
#include <trace/hooks/sched.h>
#include "internal.h"
#include "fd.h"
@ -344,13 +345,24 @@ static ssize_t get_task_cmdline(struct task_struct *tsk, char __user *buf,
size_t count, loff_t *pos)
{
struct mm_struct *mm;
bool prio_inherited = false;
int saved_prio;
ssize_t ret;
mm = get_task_mm(tsk);
if (!mm)
return 0;
/*
* access_remote_vm() holds the hot mmap_sem lock which can cause the
* task for which we read cmdline etc for by some debug deamon to slow
* down and suffer a performance hit. Especially if the reader task has
* a low nice value.
*/
trace_android_vh_prio_inheritance(tsk, &saved_prio, &prio_inherited);
ret = get_mm_cmdline(mm, buf, count, pos);
if (prio_inherited)
trace_android_vh_prio_restore(saved_prio);
mmput(mm);
return ret;
}

View File

@ -426,6 +426,14 @@ DECLARE_RESTRICTED_HOOK(android_rvh_update_rt_rq_load_avg,
TP_PROTO(u64 now, struct rq *rq, struct task_struct *tsk, int running),
TP_ARGS(now, rq, tsk, running), 1);
DECLARE_HOOK(android_vh_prio_inheritance,
TP_PROTO(struct task_struct *p, int *saved_prio, bool *prio_inherited),
TP_ARGS(p, saved_prio, prio_inherited));
DECLARE_HOOK(android_vh_prio_restore,
TP_PROTO(int saved_prio),
TP_ARGS(saved_prio));
#endif /* _TRACE_HOOK_SCHED_H */
/* This part must be outside protection */
#include <trace/define_trace.h>

View File

@ -108,3 +108,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_load_avg);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_remove_entity_load_avg);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_blocked_fair);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_rt_rq_load_avg);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_prio_inheritance);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_prio_restore);