Skip to content

Commit

Permalink
mm: oom: ensure emergency trigger is raised before enter into oom
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: engstk <[email protected]>
  • Loading branch information
Charan Teja Reddy authored and engstk committed Jul 22, 2020
1 parent 2720b77 commit e0b9204
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit e0b9204

Please sign in to comment.