Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 276c45c7 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "mm: check for possibility of ulmk kills in should_ulmk_retry"

parents 0ad99395 1f4c00bc
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -80,6 +80,28 @@ static atomic64_t ulmk_kill_jiffies = ATOMIC64_INIT(INITIAL_JIFFIES);
static unsigned long psi_emergency_jiffies = INITIAL_JIFFIES;
static DEFINE_MUTEX(ulmk_retry_lock);

static bool ulmk_kill_possible(void)
{
	struct task_struct *tsk;
	bool ret = false;

	rcu_read_lock();
	for_each_process(tsk) {
		if (tsk->flags & PF_KTHREAD)
			continue;

		task_lock(tsk);
		if (tsk->signal->oom_score_adj >= 0) {
			ret = true;
			task_unlock(tsk);
			break;
		}
		task_unlock(tsk);
	}
	rcu_read_unlock();

	return ret;
}

/*
 * psi_emergency_jiffies represents the last ULMK emergency event.
@@ -107,6 +129,20 @@ bool should_ulmk_retry(void)
		goto out;
	}

	/*
	 * We reached here means no kill have had happened since the last
	 * emergency trigger for 2*HZ window. We can't derive the status
	 * of the low memory killer here. So, before falling back to OOM,
	 * check for any +ve adj tasks left in the system in repeat for
	 * next 20*HZ. Indirectly the below logic also giving 20HZ window
	 * for the first emergency trigger.
	 */
	if (time_after(psi_emergency_jiffies + 20 * HZ, now) &&
	    ulmk_kill_possible()) {
		ret = true;
		goto out;
	}

out:
	mutex_unlock(&ulmk_retry_lock);
	return ret;