The Linux Kernel Mailing List
 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 06/10] mm, oom: check oom victims prior to numa placement
Date: Wed,  2 Dec 2026 10:53:59 +0100	[thread overview]
Message-ID: <20261202095450.296675-7-mhocko@kernel.org> (raw)
In-Reply-To: <20261202095450.296675-1-mhocko@kernel.org>

From: Michal Hocko <mhocko@suse.com>

oom_evaluate_task checks oom_cpuset_eligible before potential inflight
oom victims. This allows to have several oom victims on disjunct numa
domains but it also allows to unnecessarily kill more tasks than
necessary. But if we have tasks that consume memory in multiple numa
nodes (e.g. via vma memory policy) then we can bail too early:

TaskA (nodemask=1, vma->mpol=0), TaskB (nodemask=1)

OOM1(nodemask=0): TaskA killed
OOM2(nodemask=1): TaskA invisble due to oom_cpuset_eligible but
it will be freeing memopry from node=1 too.

Check for existing oom victims before numa placement and bail out
if there is any oom victim even if it could be in a different oom
domain. This is a slow path and postponed OOM killing is almost always a
better choice than killing that is too eager.

Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/oom_kill.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 6dc9424e6a05..6ff1e93ec6e3 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -318,10 +318,6 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
 	if (oom_unkillable_task(task))
 		goto next;
 
-	/* p may not have freeable memory in nodemask */
-	if (!is_memcg_oom(oc) && !oom_cpuset_eligible(task, oc))
-		goto next;
-
 	/*
 	 * This task already has access to memory reserves and is being killed.
 	 * Don't allow any other task to have access to the reserves unless
@@ -334,6 +330,10 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
 		goto abort;
 	}
 
+	/* p may not have freeable memory in nodemask */
+	if (!is_memcg_oom(oc) && !oom_cpuset_eligible(task, oc))
+		goto next;
+
 	/*
 	 * If task is allocating a lot of memory and has been marked to be
 	 * killed first if it triggers an oom, then select it.
-- 
2.56.1


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

Thread overview: 15+ 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 ` [PATCH 02/10] mm/oom_kill: keep the allocating mm eligible Michal Hocko
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 ` Michal Hocko [this message]
2026-12-02  9:54 ` [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Michal Hocko
2026-12-02 19:22   ` Harry Yoo
2026-12-02 19:33     ` 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)
2026-12-02 19:01   ` Michal Hocko

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-7-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