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

Commit c9f01245 authored by David Rientjes's avatar David Rientjes Committed by Linus Torvalds
Browse files

oom: remove oom_disable_count



This removes mm->oom_disable_count entirely since it's unnecessary and
currently buggy.  The counter was intended to be per-process but it's
currently decremented in the exit path for each thread that exits, causing
it to underflow.

The count was originally intended to prevent oom killing threads that
share memory with threads that cannot be killed since it doesn't lead to
future memory freeing.  The counter could be fixed to represent all
threads sharing the same mm, but it's better to remove the count since:

 - it is possible that the OOM_DISABLE thread sharing memory with the
   victim is waiting on that thread to exit and will actually cause
   future memory freeing, and

 - there is no guarantee that a thread is disabled from oom killing just
   because another thread sharing its mm is oom disabled.

Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
Reported-by: default avatarOleg Nesterov <oleg@redhat.com>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Ying Han <yinghan@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7b0d44fa
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -841,10 +841,6 @@ static int exec_mmap(struct mm_struct *mm)
	tsk->mm = mm;
	tsk->active_mm = mm;
	activate_mm(active_mm, mm);
	if (old_mm && tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) {
		atomic_dec(&old_mm->oom_disable_count);
		atomic_inc(&tsk->mm->oom_disable_count);
	}
	task_unlock(tsk);
	arch_pick_mmap_layout(mm);
	if (old_mm) {
+0 −13
Original line number Diff line number Diff line
@@ -1107,13 +1107,6 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
		goto err_sighand;
	}

	if (oom_adjust != task->signal->oom_adj) {
		if (oom_adjust == OOM_DISABLE)
			atomic_inc(&task->mm->oom_disable_count);
		if (task->signal->oom_adj == OOM_DISABLE)
			atomic_dec(&task->mm->oom_disable_count);
	}

	/*
	 * Warn that /proc/pid/oom_adj is deprecated, see
	 * Documentation/feature-removal-schedule.txt.
@@ -1215,12 +1208,6 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
		goto err_sighand;
	}

	if (oom_score_adj != task->signal->oom_score_adj) {
		if (oom_score_adj == OOM_SCORE_ADJ_MIN)
			atomic_inc(&task->mm->oom_disable_count);
		if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
			atomic_dec(&task->mm->oom_disable_count);
	}
	task->signal->oom_score_adj = oom_score_adj;
	if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
		task->signal->oom_score_adj_min = oom_score_adj;
+0 −3
Original line number Diff line number Diff line
@@ -336,9 +336,6 @@ struct mm_struct {
	unsigned int token_priority;
	unsigned int last_interval;

	/* How many tasks sharing this mm are OOM_DISABLE */
	atomic_t oom_disable_count;

	unsigned long flags; /* Must use atomic bitops to access the bits */

	struct core_state *core_state; /* coredumping support */
+0 −2
Original line number Diff line number Diff line
@@ -681,8 +681,6 @@ static void exit_mm(struct task_struct * tsk)
	enter_lazy_tlb(mm, current);
	/* We don't want this task to be frozen prematurely */
	clear_freeze_flag(tsk);
	if (tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
		atomic_dec(&mm->oom_disable_count);
	task_unlock(tsk);
	mm_update_next_owner(mm);
	mmput(mm);
+1 −9
Original line number Diff line number Diff line
@@ -501,7 +501,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
	mm->cached_hole_size = ~0UL;
	mm_init_aio(mm);
	mm_init_owner(mm, p);
	atomic_set(&mm->oom_disable_count, 0);

	if (likely(!mm_alloc_pgd(mm))) {
		mm->def_flags = 0;
@@ -816,8 +815,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
	/* Initializing for Swap token stuff */
	mm->token_priority = 0;
	mm->last_interval = 0;
	if (tsk->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
		atomic_inc(&mm->oom_disable_count);

	tsk->mm = mm;
	tsk->active_mm = mm;
@@ -1391,13 +1388,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
bad_fork_cleanup_namespaces:
	exit_task_namespaces(p);
bad_fork_cleanup_mm:
	if (p->mm) {
		task_lock(p);
		if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
			atomic_dec(&p->mm->oom_disable_count);
		task_unlock(p);
	if (p->mm)
		mmput(p->mm);
	}
bad_fork_cleanup_signal:
	if (!(clone_flags & CLONE_THREAD))
		free_signal_struct(p->signal);
Loading