From 0687aa19008d1f5186f335f7e27ec84bcbc58938 Mon Sep 17 00:00:00 2001 From: Weilong chen Date: Wed, 6 Nov 2019 11:32:09 +0800 Subject: [PATCH] kernel:mm: Support disable oom-killer and report oom events ascend inclusion category: feature bugzilla: NA CVE: NA ------------------- Aascend support disable oom-killer and report oom events to bbox. Signed-off-by: Weilong Chen Signed-off-by: Zhou Guanghui Signed-off-by: Chen Jun Signed-off-by: Lijun Fang Reviewed-by: Li Zefan Reviewed-by: Hanjun Guo Signed-off-by: Yang Yingliang --- include/linux/oom.h | 14 ++++++++++++++ kernel/sysctl.c | 11 +++++++++++ mm/oom_kill.c | 39 +++++++++++++++++++++++++++++++++++++++ mm/util.c | 2 ++ 4 files changed, 66 insertions(+) diff --git a/include/linux/oom.h b/include/linux/oom.h index 69864a547663..4e9d3b32e911 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -117,4 +117,18 @@ extern struct task_struct *find_lock_task_mm(struct task_struct *p); extern int sysctl_oom_dump_tasks; extern int sysctl_oom_kill_allocating_task; extern int sysctl_panic_on_oom; + +#ifdef CONFIG_ARCH_ASCEND + +extern int sysctl_enable_oom_killer; +extern int register_hisi_oom_notifier(struct notifier_block *nb); +extern int hisi_oom_notifier_call(unsigned long val, void *v); +extern int unregister_hisi_oom_notifier(struct notifier_block *nb); + +#else + +#define sysctl_enable_oom_killer 1 +#define hisi_oom_notifier_call(val, p) ({NOTIFY_DONE; }) +#endif + #endif /* _INCLUDE_LINUX_OOM_H */ diff --git a/kernel/sysctl.c b/kernel/sysctl.c index a22bc53edfd2..39b8c7f41faf 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1264,6 +1264,17 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &two, }, +#ifdef CONFIG_ARCH_ASCEND + { + .procname = "enable_oom_killer", + .data = &sysctl_enable_oom_killer, + .maxlen = sizeof(sysctl_enable_oom_killer), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, +#endif { .procname = "oom_kill_allocating_task", .data = &sysctl_oom_kill_allocating_task, diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8a4570c53e83..320ed1aca55b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -1047,6 +1047,40 @@ int unregister_oom_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(unregister_oom_notifier); +#ifdef CONFIG_ARCH_ASCEND + +int sysctl_enable_oom_killer; +static BLOCKING_NOTIFIER_HEAD(hisi_oom_notify_list); + +int register_hisi_oom_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&hisi_oom_notify_list, nb); +} +EXPORT_SYMBOL_GPL(register_hisi_oom_notifier); + +static unsigned long last_jiffies; +int hisi_oom_notifier_call(unsigned long val, void *v) +{ + /* Print time interval to 10 seconds */ + if (time_after(jiffies, last_jiffies + 10 * HZ)) { + pr_warn("HISI_OOM_NOTIFIER: oom type %lu\n", val); + dump_stack(); + show_mem(SHOW_MEM_FILTER_NODES, NULL); + dump_tasks(NULL, 0); + last_jiffies = jiffies; + } + return blocking_notifier_call_chain(&hisi_oom_notify_list, val, v); +} +EXPORT_SYMBOL_GPL(hisi_oom_notifier_call); + +int unregister_hisi_oom_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&hisi_oom_notify_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_hisi_oom_notifier); + +#endif + /** * out_of_memory - kill the "best" process when we run out of memory * @oc: pointer to struct oom_control @@ -1064,6 +1098,11 @@ bool out_of_memory(struct oom_control *oc) if (oom_killer_disabled) return false; + if (!sysctl_enable_oom_killer) { + hisi_oom_notifier_call(0, NULL); + return false; + } + if (!is_memcg_oom(oc)) { blocking_notifier_call_chain(&oom_notify_list, 0, &freed); if (freed > 0) diff --git a/mm/util.c b/mm/util.c index bc847ae3a626..4531b792d4da 100644 --- a/mm/util.c +++ b/mm/util.c @@ -17,6 +17,7 @@ #include #include +#include #include "internal.h" @@ -726,6 +727,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin) if (percpu_counter_read_positive(&vm_committed_as) < allowed) return 0; error: + hisi_oom_notifier_call(1, NULL); vm_unacct_memory(pages); return -ENOMEM; -- GitLab