From 72488b3be40ef289ad69007bccc80f70d2e99760 Mon Sep 17 00:00:00 2001 From: Prakash Gupta Date: Thu, 22 Apr 2021 19:33:23 +0530 Subject: [PATCH] ANDROID: mm, oom: add vendor hook to prevent oom panic In some cases we would like to bypass oom panic and give the system more time to cleanup memory. Add vendor hook to allow skipping the oom panic. Bug: 186875166 Change-Id: I64e74b2c013d6f18d74504777c6559d9ae07e008 Signed-off-by: Prakash Gupta --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 4 ++++ mm/oom_kill.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index d16aa3d3e2bb..f53d2de118e5 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -285,6 +285,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_update_topology_flags_workfn); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_of_i2c_get_board_info); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_attach); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_dirty_limits); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_check_panic); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterruptible_tasks); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterruptible_tasks_dn); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_blk_reset); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index e6cec50cf1f4..99655b3657ee 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -78,6 +79,9 @@ DECLARE_HOOK(android_vh_mm_dirty_limits, unsigned long nr_reclaimable, unsigned long pages_dirtied), TP_ARGS(gdtc, strictlimit, dirty, bg_thresh, nr_reclaimable, pages_dirtied)); +DECLARE_HOOK(android_vh_oom_check_panic, + TP_PROTO(struct oom_control *oc, int *ret), + TP_ARGS(oc, ret)); DECLARE_HOOK(android_vh_save_vmalloc_stack, TP_PROTO(unsigned long flags, struct vm_struct *vm), TP_ARGS(flags, vm)); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 9072352545aa..acf064f3fc4e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -51,6 +51,9 @@ #define CREATE_TRACE_POINTS #include +#undef CREATE_TRACE_POINTS +#include + int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks = 1; @@ -1146,6 +1149,12 @@ bool out_of_memory(struct oom_control *oc) select_bad_process(oc); /* Found nothing?!?! */ if (!oc->chosen) { + int ret = false; + + trace_android_vh_oom_check_panic(oc, &ret); + if (ret) + return true; + dump_header(oc, NULL); pr_warn("Out of memory and no killable processes...\n"); /*