mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: David Hildenbrand <david@kernel.org>
Cc: David Rientjes <rientjes@google.com>,
	Ben Gardon <bgardon@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	mhocko@suse.com, Andrew Morton <akpm@linux-foundation.org>,
	<linux-mm@kvack.org>, LKML <linux-kernel@vger.kernel.org>,
	Chris Mason <mason@kernel.org>
Subject: [PATCH 02/10] mm/oom_kill: keep the allocating mm eligible
Date: Wed,  2 Dec 2026 10:53:55 +0100	[thread overview]
Message-ID: <20261202095450.296675-3-mhocko@kernel.org> (raw)
In-Reply-To: <20261202095450.296675-1-mhocko@kernel.org>

From: Chris Mason <mason@kernel.org>

On a NUMA machine, a process can exhaust nodes that its own task
mempolicy or cpuset. The mempolicy can kill unrelated tasks one after
the other, and then panic, while that process is never selected.

The OOM killer skips a task that oom_cpuset_eligible() rejects, on the
assumption that killing it frees nothing on the nodes that ran out. But
each of the two tests in that function can reject the process whose mm
is filling those nodes:

- In a mempolicy OOM, the function checks the mempolicy of the task.
  But the nodemask of the allocation can come from the mempolicy of a
  VMA, so a task with MPOL_BIND to other nodes can still fill the
  exhausted nodes.
- In a cpuset OOM, the function compares the mems_allowed of the task
  with that of current. mems_allowed is per task, so a vfork() child can
  allocate in a different cpuset from its parent. oom_badness() skips
  the child because it is in vfork(). The parent shares the mm, but it
  is rejected because its cpuset has other nodes.

Tasks with no mempolicy, or in the root cpuset, pass these tests and are
killed instead. When none is left, out_of_memory() panics.

The fix used here is to treat every process that shares the mm of
current as eligible, since current is allocating on the exhausted nodes.

Fixes: 6f48d0ebd907 ("oom: select task from tasklist for mempolicy ooms")
Signed-off-by: Chris Mason <mason@kernel.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 mm/oom_kill.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 9de57a23893c..30c314069d5b 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -82,7 +82,8 @@ static inline bool is_memcg_oom(struct oom_control *oc)
  *
  * Task eligibility is determined by whether or not a candidate task, @tsk,
  * shares the same mempolicy nodes as current if it is bound by such a policy
- * and whether or not it has the same set of allowed cpuset nodes.
+ * and whether or not it has the same set of allowed cpuset nodes. A process
+ * that shares the mm of current is always eligible.
  *
  * This function is assuming oom-killer context and 'current' has triggered
  * the oom-killer.
@@ -90,11 +91,23 @@ static inline bool is_memcg_oom(struct oom_control *oc)
 static bool oom_cpuset_eligible(struct task_struct *start,
 				struct oom_control *oc)
 {
+	struct mm_struct *mm = current->mm;
 	struct task_struct *tsk;
 	bool ret = false;
 	const nodemask_t *mask = oc->nodemask;
 
 	rcu_read_lock();
+	/*
+	 * current allocates on the nodes of this oom, so its mm may have memory
+	 * there. The tests below can miss that: the nodemask can come from the
+	 * mempolicy of a vma while that of the task binds it to other nodes, and
+	 * a process that shares the mm can be in another cpuset.
+	 */
+	if (mm && process_shares_mm(start, mm)) {
+		ret = true;
+		goto unlock;
+	}
+
 	for_each_thread(start, tsk) {
 		if (mask) {
 			/*
@@ -114,6 +127,7 @@ static bool oom_cpuset_eligible(struct task_struct *start,
 		if (ret)
 			break;
 	}
+unlock:
 	rcu_read_unlock();
 
 	return ret;
@@ -407,8 +421,8 @@ static int dump_task(struct task_struct *p, void *arg)
  * @oc: pointer to struct oom_control
  *
  * Dumps the current memory state of all eligible tasks.  Tasks not in the same
- * memcg, not in the same cpuset, or bound to a disjoint set of mempolicy nodes
- * are not shown.
+ * memcg are not shown.  Nor are tasks not in the same cpuset or bound to a
+ * disjoint set of mempolicy nodes, unless they share the mm of current.
  * State information includes task's pid, uid, tgid, vm size, rss,
  * pgtables_bytes, swapents, oom_score_adj value, and name.
  */
-- 
2.56.1


  parent reply	other threads:[~2026-12-02  9:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:53 [PATCH 0/10] assorted oom fixes Michal Hocko
2026-12-02  9:53 ` [PATCH 01/10] memcg-v1, oom: do not sleep in worker contexts Michal Hocko
2026-12-02  9:53 ` Michal Hocko [this message]
2026-12-02  9:53 ` [PATCH 03/10] mm, oom: do not panic on constrained OOMs Michal Hocko
2026-12-02  9:53 ` [PATCH 04/10] mm/oom_kill: ratelimit memcg OOM reports with no victim Michal Hocko
2026-12-02  9:53 ` [PATCH 05/10] mm, oom: thaw tasks sharing the mm with the oom victim Michal Hocko
2026-12-02  9:53 ` [PATCH 06/10] mm, oom: check oom victims prior to numa placement Michal Hocko
2026-12-02  9:54 ` [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Michal Hocko
2026-12-02  9:54 ` [PATCH 08/10] mm, " Michal Hocko
2026-12-02  9:54 ` [PATCH 09/10] mm, oom: add rcu_barrier before hiding victim from the oom killer Michal Hocko
2026-12-02  9:54 ` [PATCH 10/10] memcg: wake v1 OOM lock contenders on unlock Michal Hocko
2026-12-02 13:06 ` [PATCH 0/10] assorted oom fixes David Hildenbrand (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202095450.296675-3-mhocko@kernel.org \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgardon@google.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mason@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®