From 4d7fc7aaec9c7089662c88cdcb0ddf5feb0e08be 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 Signed-off-by: Sudarshan Rajagopalan --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 5 +++++ mm/oom_kill.c | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 73847cacaae2..4b01c4e6a31d 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -198,6 +198,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_memory_nx); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_memory_rw); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_module_permit_before_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_module_permit_after_init); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_oom_check_panic); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_selinux_is_initialized); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_mmap_file); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_file_open); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 22dcee0d90a1..36bafc54e4bb 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -9,6 +9,8 @@ #include +#include +#include #include #include @@ -21,6 +23,9 @@ DECLARE_RESTRICTED_HOOK(android_rvh_set_gfp_zone_flags, DECLARE_RESTRICTED_HOOK(android_rvh_set_readahead_gfp_mask, TP_PROTO(gfp_t *flags), TP_ARGS(flags), 1); +DECLARE_HOOK(android_vh_oom_check_panic, + TP_PROTO(struct oom_control *oc, int *ret), + TP_ARGS(oc, ret)); #endif /* _TRACE_HOOK_MM_H */ diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 2d5452f19afd..bd42d3701641 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -52,6 +52,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; @@ -1103,6 +1106,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"); /*