--- zzzz-none-000/linux-4.1.52/mm/oom_kill.c 2018-05-28 02:26:45.000000000 +0000 +++ bcm63-7530ax-731/linux-4.1.52/mm/oom_kill.c 2022-03-02 11:37:13.000000000 +0000 @@ -194,6 +194,8 @@ /* * Determine the type of allocation constraint. */ +#if !defined(CONFIG_BCM_KF_OOM_REBOOT) + #ifdef CONFIG_NUMA static enum oom_constraint constrained_alloc(struct zonelist *zonelist, gfp_t gfp_mask, nodemask_t *nodemask, @@ -253,6 +255,7 @@ return CONSTRAINT_NONE; } #endif +#endif /* CONFIG_BCM_KF_OOM_REBOOT */ enum oom_scan_t oom_scan_process_thread(struct task_struct *task, unsigned long totalpages, const nodemask_t *nodemask, @@ -285,6 +288,7 @@ return OOM_SCAN_OK; } +#if !defined(CONFIG_BCM_KF_OOM_REBOOT) /* * Simple selection loop. We chose the process with the highest * number of 'points'. Returns -1 on scan abort. @@ -335,6 +339,7 @@ return chosen; } +#endif /** * dump_tasks - dump current memory state of all system tasks * @memcg: current's memory controller, if constrained @@ -407,6 +412,7 @@ bool oom_killer_disabled __read_mostly; static DECLARE_RWSEM(oom_sem); + /** * mark_tsk_oom_victim - marks the given task as OOM victim. * @tsk: task to mark @@ -493,6 +499,8 @@ up_write(&oom_sem); } + + #define K(x) ((x) << (PAGE_SHIFT-10)) /* * Must be called while holding a reference to p, which will be released upon @@ -707,6 +715,13 @@ static void __out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order, nodemask_t *nodemask, bool force_kill) { +#if defined(CONFIG_BCM_KF_OOM_REBOOT) +#define OOM_REBOOT_DELAY (5) +#define OOM_REBOOT_INTERVAL (HZ*120) + static int oom_count=0; + static unsigned long oom_timestamp=0; + unsigned long freed = 0; +#else const nodemask_t *mpol_mask; struct task_struct *p; unsigned long totalpages; @@ -714,6 +729,7 @@ unsigned int uninitialized_var(points); enum oom_constraint constraint = CONSTRAINT_NONE; int killed = 0; +#endif blocking_notifier_call_chain(&oom_notify_list, 0, &freed); if (freed > 0) @@ -734,6 +750,40 @@ return; } +#if defined(CONFIG_BCM_KF_OOM_REBOOT) + + /* For our embedded system, most of the processes are considered essential. */ + /* Randomly killing a process is no better than a reboot so we won't kill process here*/ + + printk(KERN_WARNING "\n\n%s triggered out of memory codition (oom killer not called): " + "gfp_mask=0x%x, order=%d, oom_score_adj=%d\n\n", + current->comm, gfp_mask, order, current->signal->oom_score_adj); + dump_stack(); + show_mem(0); + printk("\n"); + /* + * The process that triggered the oom is not necessarily the one that + * caused it. dump_tasks shows all tasks and their memory usage. + */ + read_lock(&tasklist_lock); + dump_tasks(NULL, nodemask); + read_unlock(&tasklist_lock); + + /* Reboot if OOM, but don't do it immediately - just in case this can be too sensitive */ + if ((jiffies - oom_timestamp) > OOM_REBOOT_INTERVAL) { + oom_timestamp = jiffies; + oom_count = 0; + } + else { + oom_count++; + if (oom_count >= OOM_REBOOT_DELAY) { + panic("Reboot due to persistent out of memory codition.."); + } + } + schedule_timeout_interruptible(HZ*5); + +#else + /* * Check if there were limitations on the allocation (only relevant for * NUMA) that may require different handling. @@ -771,6 +821,7 @@ */ if (killed) schedule_timeout_killable(1); +#endif } /**