From 90ec8176a8300d75b9b0142facbe655888df7422 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Fri, 18 Oct 2019 17:34:17 -0700 Subject: [PATCH] mm/oom-kill: Add option to panic when killing foreground app This setting is useful to debug memory intensive test scenarios, which are close to the limit of what the device supports. Change-Id: Id09f43736bd3c9586b4dac4fae570e78089f5bb3 Signed-off-by: Patrick Daly [cgoldswo@codeaurora.org: Add macro introduced in obsolete patch] Signed-off-by: Chris Goldsworthy --- include/linux/oom.h | 2 ++ kernel/signal.c | 1 + mm/oom_kill.c | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/linux/oom.h b/include/linux/oom.h index 40862dd4f223..c880273c6199 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -130,4 +130,6 @@ extern int sysctl_reap_mem_on_sigkill; /* calls for LMK reaper */ extern void add_to_oom_reaper(struct task_struct *p); +extern void check_panic_on_foreground_kill(struct task_struct *p); +#define ULMK_MAGIC "lmkd" #endif /* _INCLUDE_LINUX_OOM_H */ diff --git a/kernel/signal.c b/kernel/signal.c index e8f1ce7a7e47..1ae3e276e51b 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1406,6 +1406,7 @@ int group_send_sig_info(int sig, struct kernel_siginfo *info, rcu_read_unlock(); if (!ret && sig) { + check_panic_on_foreground_kill(p); ret = do_send_sig_info(sig, info, p, type); if (capable(CAP_KILL) && sig == SIGKILL) add_to_oom_reaper(p); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index c19945135938..987a84f72c7b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -58,6 +58,9 @@ int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks = 1; int sysctl_reap_mem_on_sigkill = 1; +static int panic_on_adj_zero; +module_param(panic_on_adj_zero, int, 0644); + /* * Serializes oom killer invocations (out_of_memory()) from all contexts to * prevent from over eager oom killing (e.g. when the oom killer is invoked @@ -1197,3 +1200,18 @@ void add_to_oom_reaper(struct task_struct *p) put_task_struct(p); } + +/* + * Should be called prior to sending sigkill. To guarantee that the + * process to-be-killed is still untouched. + */ +void check_panic_on_foreground_kill(struct task_struct *p) +{ + if (unlikely(!strcmp(current->comm, ULMK_MAGIC) + && p->signal->oom_score_adj == 0 + && panic_on_adj_zero)) { + show_mem(SHOW_MEM_FILTER_NODES, NULL); + show_mem_call_notifiers(); + panic("Attempt to kill foreground task: %s", p->comm); + } +}