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: 344826816 Bug: 289412815 Signed-off-by: Qais Yousef <qyousef@google.com> (cherry picked from commit b821a3c8fc1efe12782061993b4feef026f8ce58) [Trivial conflict in include/trace/hooks/sched.h due to new code added. And in vendor_hooks.c due to code ordering] Signed-off-by: Qais Yousef <qyousef@google.com> Change-Id: I160637b30e5bd58d5978b25be8a21ce025175ec3 Signed-off-by: liulu liu <liulu.liu@honor.corp-partner.google.com>
This commit is contained in:
@@ -101,6 +101,7 @@
|
|||||||
#include <linux/cpufreq_times.h>
|
#include <linux/cpufreq_times.h>
|
||||||
#include <uapi/linux/lsm.h>
|
#include <uapi/linux/lsm.h>
|
||||||
#include <trace/events/oom.h>
|
#include <trace/events/oom.h>
|
||||||
|
#include <trace/hooks/sched.h>
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "fd.h"
|
#include "fd.h"
|
||||||
|
|
||||||
@@ -381,13 +382,24 @@ static ssize_t get_task_cmdline(struct task_struct *tsk, char __user *buf,
|
|||||||
size_t count, loff_t *pos)
|
size_t count, loff_t *pos)
|
||||||
{
|
{
|
||||||
struct mm_struct *mm;
|
struct mm_struct *mm;
|
||||||
|
bool prio_inherited = false;
|
||||||
|
int saved_prio;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
mm = get_task_mm(tsk);
|
mm = get_task_mm(tsk);
|
||||||
if (!mm)
|
if (!mm)
|
||||||
return 0;
|
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);
|
ret = get_mm_cmdline(mm, buf, count, pos);
|
||||||
|
if (prio_inherited)
|
||||||
|
trace_android_vh_prio_restore(saved_prio);
|
||||||
mmput(mm);
|
mmput(mm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -485,6 +485,15 @@ DECLARE_HOOK(android_vh_tick_nohz_idle_stop_tick,
|
|||||||
DECLARE_HOOK(android_vh_mmput,
|
DECLARE_HOOK(android_vh_mmput,
|
||||||
TP_PROTO(struct mm_struct *mm),
|
TP_PROTO(struct mm_struct *mm),
|
||||||
TP_ARGS(mm));
|
TP_ARGS(mm));
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
/* macro versions of hooks are no longer required */
|
/* macro versions of hooks are no longer required */
|
||||||
|
|
||||||
#endif /* _TRACE_HOOK_SCHED_H */
|
#endif /* _TRACE_HOOK_SCHED_H */
|
||||||
|
|||||||
@@ -126,3 +126,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpu_cgroup_css_alloc);
|
|||||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpu_cgroup_css_free);
|
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpu_cgroup_css_free);
|
||||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dequeue_entity_delayed);
|
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dequeue_entity_delayed);
|
||||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmput);
|
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmput);
|
||||||
|
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_prio_inheritance);
|
||||||
|
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_prio_restore);
|
||||||
|
|||||||
Reference in New Issue
Block a user