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

Commit 93de5f5d authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "lowmemorykiller: fix scan_mutex contention"

parents b36c8266 4af2c261
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -211,6 +211,22 @@ static int test_task_flag(struct task_struct *p, int flag)
	return 0;
}

static int test_task_state(struct task_struct *p, int state)
{
	struct task_struct *t;

	for_each_thread(p, t) {
		task_lock(t);
		if (t->state & state) {
			task_unlock(t);
			return 1;
		}
		task_unlock(t);
	}

	return 0;
}

static DEFINE_MUTEX(scan_mutex);

int can_use_cma_pages(gfp_t gfp_mask)
@@ -398,7 +414,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
	int other_free;
	int other_file;

	if (mutex_lock_interruptible(&scan_mutex) < 0)
	if (!mutex_trylock(&scan_mutex))
		return 0;

	other_free = global_page_state(NR_FREE_PAGES);
@@ -457,8 +473,6 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
		if (time_before_eq(jiffies, lowmem_deathpending_timeout)) {
			if (test_task_flag(tsk, TIF_MEMDIE)) {
				rcu_read_unlock();
				/* give the system time to free up the memory */
				msleep_interruptible(20);
				mutex_unlock(&scan_mutex);
				return 0;
			}
@@ -495,6 +509,17 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
		long cache_limit = minfree * (long)(PAGE_SIZE / 1024);
		long free = other_free * (long)(PAGE_SIZE / 1024);
		trace_lowmemory_kill(selected, cache_size, cache_limit, free);

		if (test_task_flag(selected, TIF_MEMDIE) &&
		    (test_task_state(selected, TASK_UNINTERRUPTIBLE))) {
			lowmem_print(2, "'%s' (%d) is already killed\n",
				     selected->comm,
				     selected->pid);
			rcu_read_unlock();
			mutex_unlock(&scan_mutex);
			return 0;
		}

		lowmem_print(1, "Killing '%s' (%d), adj %hd,\n" \
				"   to free %ldkB on behalf of '%s' (%d) because\n" \
				"   cache %ldkB is below limit %ldkB for oom_score_adj %hd\n" \