From e0b9204b082cc81eac62755d360190527b4e2b83 Mon Sep 17 00:00:00 2001 From: Charan Teja Reddy Date: Tue, 30 Jun 2020 16:42:07 +0530 Subject: [PATCH] mm: oom: ensure emergency trigger is raised before enter into oom When there is no kill in the system since the last PSI event, the should_ulmk_retry() returns with out raising the emergency trigger thus system follows OOM path. Avoid this by making sure that the PSI emergency trigger is raised in the last ULMK_EMERG_TRIG_TIMEOUT window. Change-Id: I99754c30c08a04902a2849c051510b371538467a Signed-off-by: Charan Teja Reddy Signed-off-by: engstk --- mm/oom_kill.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 351d9c6573..8259736ab5 100755 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -80,6 +80,7 @@ DEFINE_MUTEX(oom_lock); /* The maximum amount of time to loop in should_ulmk_retry() */ #define ULMK_TIMEOUT (20 * HZ) +#define ULMK_EMERG_TRIG_TIMEOUT (ULMK_TIMEOUT + 10 * HZ) #define ULMK_DBG_POLICY_TRIGGER (BIT(0)) #define ULMK_DBG_POLICY_WDOG (BIT(1)) @@ -92,6 +93,7 @@ static atomic64_t ulmk_wdog_expired = ATOMIC64_INIT(0); static atomic64_t ulmk_kill_jiffies = ATOMIC64_INIT(INITIAL_JIFFIES); static atomic64_t ulmk_watchdog_pet_jiffies = ATOMIC64_INIT(INITIAL_JIFFIES); static unsigned long psi_emergency_jiffies = INITIAL_JIFFIES; +static unsigned long psi_emerg_trigger_jiffies = INITIAL_JIFFIES; /* Prevents contention on the mutex_trylock in psi_emergency_jiffies */ static DEFINE_MUTEX(ulmk_retry_lock); @@ -170,9 +172,10 @@ bool should_ulmk_retry(gfp_t gfp_mask) * current time and return true. * * b) If no kill have had happened in the last ULMK_TIMEOUT and - * LMKD also stuck for the last ULMK_TIMEOUT, which then means - * that system kill logic is not responding despite PSI events - * sent from kernel. Return false. + * LMKD also stuck for the last ULMK_TIMEOUT despite an + * emergency trigger in the last ULMK_EMERG_TRIG_TIMEOUT, which + * then means that system kill logic is not responding despite + * PSI events sent from kernel. Return false. * * c) Cond1: trigger = !active && wdog_expired = false: * Then give a chance to the ULMK by raising emergnecy trigger @@ -199,11 +202,14 @@ bool should_ulmk_retry(gfp_t gfp_mask) psi_emergency_jiffies = now; ret = true; } else if (time_after(now, psi_emergency_jiffies + ULMK_TIMEOUT) && - time_after(now, last_wdog_pet + ULMK_TIMEOUT)) { + time_after(now, last_wdog_pet + ULMK_TIMEOUT) && + time_after(psi_emerg_trigger_jiffies, + now - ULMK_EMERG_TRIG_TIMEOUT)) { ret = false; } else if (!trigger_active) { BUG_ON(ulmk_dbg_policy & ULMK_DBG_POLICY_TRIGGER); psi_emergency_trigger(); + psi_emerg_trigger_jiffies = now; ret = true; } else if (wdog_expired) { mutex_lock(&oom_lock);