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 <pdaly@codeaurora.org>
[cgoldswo@codeaurora.org: Add macro introduced in obsolete patch]
Signed-off-by: Chris Goldsworthy <cgoldswo@codeaurora.org>
This commit is contained in:
Patrick Daly 2019-10-18 17:34:17 -07:00 • committed by Chris Goldsworthy
commit 90ec8176a8
3 changed files with 21 additions and 0 deletions

View file

@ -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 */

View file

@ -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);

View file

@ -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);
}
}