From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,ziy@nvidia.com,yu-cheng.yu@intel.com,
ying.huang@linux.alibaba.com,willy@infradead.org,vbabka@kernel.org,
usama.arif@linux.dev,tj@kernel.org,surenb@google.com,stable@vger.kernel.org,
shakeel.butt@linux.dev,rppt@kernel.org,rientjes@google.com,
rick.p.edgecombe@intel.com,pfalcato@suse.de,peng.fan@nxp.com,
nphamcs@gmail.com,mhocko@suse.com,matthew.brost@intel.com,mason@kernel.org,
liam@infradead.org,kasong@tencent.com,kas@kernel.org,joshua.hahnjy@gmail.com,
jglisse@redhat.com,jbacik@fb.com,jannh@google.com,jack@suse.cz,
hannes@cmpxchg.org,gourry@gourry.net,dennisszhou@gmail.com,dennis@kernel.org,
david@kernel.org,dave.hansen@linux.intel.com,cl@gentwo.org,
chris@chrisdown.name,byungchul@sk.com,broonie@kernel.org,bp@alien8.de,
balbirs@nvidia.com,apopple@nvidia.com,ljs@kernel.org,
akpm@linux-foundation.org
Subject: + mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch added to mm-unstable branch
Date: Tue, 24 Nov 2026 08:18:32 -0800 [thread overview]
Message-ID: <20261124161833.834211F000E0@smtp.kernel.org> (raw)
In-Reply-To: <20261113-mason-migrate-et-al-fixes-v2-1-50a2ed382b61@kernel.org>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7477 bytes --]
The patch titled
Subject: mm/mmap: free gathered pages before MMF_OOM_SKIP
has been added to the -mm mm-unstable branch. Its filename is
mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Subject: mm/mmap: free gathered pages before MMF_OOM_SKIP
Date: Fri, 13 Nov 2026 21:45:19 +0000
The OOM killer can quickly trigger again after having selected a
victim. That victim might not have freed its memory yet, but its mm will
be marked MMF_OOM_SKIP by this point, so the OOM killer will ignore it.
This can cause the OOM killer to kill an innocent process when the first
might have freed enough memory to relieve the memory pressure.
exit_mmap() marks the mm MMF_OOM_SKIP once unmap_vmas() returns.
However unmap_vmas() does not free the last batch of pages it
gathered. That is left to tlb_finish_mmu(), which runs after
MMF_OOM_SKIP is set, and the batch can be large.
Fix the issue by freeing the gathered pages of an OOM victim before
marking the mm MMF_OOM_SKIP.
Note that the task which calls mmput() might not be the victim - if it
took a reference on the mm (e.g. ptrace), it may hold the last reference
and release it when it calls mmput().
Therefore we cannot rely on current to tell whether the mm belongs to an
OOM victim. Instead, partially revert commit b3541d912a84 ("mm: delete
unused MMF_OOM_VICTIM flag") to reinstate MMF_OOM_VICTIM, which
mark_oom_victim() sets on the victim's mm, and check that.
Link: https://patch.msgid.link/20261113-mason-migrate-et-al-fixes-v2-1-50a2ed382b61@kernel.org
Fixes: bf3980c85212 ("mm: drop oom code from exit_mmap")
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Chris Mason <mason@kernel.org>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Acked-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Chris Down <chris@chrisdown.name>
Tested-by: Chris Down <chris@chrisdown.name>
Link: https://lore.kernel.org/20261114115630.0b75d0b49869d4fa@chrisdown.name
Acked-by: Balbir Singh <balbirs@nvidia.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Jann Horn <jannh@google.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Yu, Yu-cheng <yu-cheng.yu@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@gentwo.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Josef Bacik <jbacik@fb.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Mark Brown <broonie@kernel.org>
Cc: Dennis Zhou (Facebook) <dennisszhou@gmail.com>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: <stable@vger.kernel.org>
include/linux/mm_types.h | 2 ++
include/linux/oom.h | 9 +++++++++
mm/mmap.c | 9 ++++++++-
mm/oom_kill.c | 4 +++-
4 files changed, 22 insertions(+), 2 deletions(-)
--- a/include/linux/mm_types.h~mm-mmap-free-gathered-pages-before-mmf_oom_skip
+++ a/include/linux/mm_types.h
@@ -2030,6 +2030,8 @@ enum {
#define MMF_TOPDOWN 31 /* mm searches top down by default */
#define MMF_TOPDOWN_MASK BIT(MMF_TOPDOWN)
+#define MMF_OOM_VICTIM 32 /* mm is the oom victim */
+
#define MMF_INIT_LEGACY_MASK (MMF_DUMP_FILTER_MASK |\
MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\
MMF_VM_MERGE_ANY_MASK | MMF_TOPDOWN_MASK)
--- a/include/linux/oom.h~mm-mmap-free-gathered-pages-before-mmf_oom_skip
+++ a/include/linux/oom.h
@@ -77,6 +77,15 @@ static inline bool tsk_is_oom_victim(str
}
/*
+ * Use this helper if tsk->mm != mm and the victim mm needs a special
+ * handling. This is guaranteed to stay true after once set.
+ */
+static inline bool mm_is_oom_victim(struct mm_struct *mm)
+{
+ return mm_flags_test(MMF_OOM_VICTIM, mm);
+}
+
+/*
* Checks whether a page fault on the given mm is still reliable.
* This is no longer true if the oom reaper started to reap the
* address space which is reflected by MMF_UNSTABLE flag set in
--- a/mm/mmap.c~mm-mmap-free-gathered-pages-before-mmf_oom_skip
+++ a/mm/mmap.c
@@ -1317,11 +1317,18 @@ void exit_mmap(struct mm_struct *mm)
/* update_hiwater_rss(mm) here? but nobody should be looking */
/* Use ULONG_MAX here to ensure all VMAs in the mm are unmapped */
unmap_vmas(&tlb, &unmap);
+
+ /*
+ * Free the memory before marking MMF_OOM_SKIP so a re-triggered OOM
+ * killer will only skip this mm if it's already freed all it can.
+ */
+ if (mm_is_oom_victim(mm))
+ tlb_flush_mmu(&tlb);
mmap_read_unlock(mm);
/*
* Set MMF_OOM_SKIP to hide this task from the oom killer/reaper
- * because the memory has been already freed.
+ * because the memory has been already unmapped.
*/
mm_flags_set(MMF_OOM_SKIP, mm);
mmap_write_lock(mm);
--- a/mm/oom_kill.c~mm-mmap-free-gathered-pages-before-mmf_oom_skip
+++ a/mm/oom_kill.c
@@ -752,8 +752,10 @@ static void mark_oom_victim(struct task_
return;
/* oom_mm is bound to the signal struct life time. */
- if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm))
+ if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) {
mmgrab(tsk->signal->oom_mm);
+ mm_flags_set(MMF_OOM_VICTIM, mm);
+ }
/*
* Make sure that the process is woken up from uninterruptible sleep
_
Patches currently in -mm which might be from ljs@kernel.org are
mm-msync-return-enomem-if-page-aligned-length-overflows.patch
mm-vma-predicate-vma_assert_stabilised-on-config_debug_vm.patch
mm-only-assert-mmap-locks-if-config_debug_vm-or-lockdep-is-set.patch
mm-only-assert-vma-locks-if-config_debug_vm-is-set.patch
mm-convert-warn_on_onces-to-vm_warn_on_once-in-vma-lock-code.patch
mm-madvise-zap-markers-from-guard-regions.patch
mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch
percpu-fix-contig-hints-that-are-too-low.patch
percpu-search-the-whole-reserved-chunk.patch
next prev parent reply other threads:[~2026-11-24 16:18 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 21:45 [PATCH v2 00/13] mm: batch of (urgentish?) fixes in oomk, cachestat, dev-migrate, percpu Lorenzo Stoakes (ARM)
2026-11-13 21:45 ` [PATCH v2 01/13] mm/mmap: free gathered pages before MMF_OOM_SKIP Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-16 1:53 ` Balbir Singh
2026-11-24 16:18 ` Andrew Morton [this message]
2026-11-13 21:45 ` [PATCH v2 02/13] mm: cachestat: count each page only once Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-24 16:18 ` + mm-cachestat-count-each-page-only-once.patch added to mm-unstable branch Andrew Morton
2026-11-13 21:45 ` [PATCH v2 04/13] mm/migrate_device: allocate THP deferred split heads Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-18 15:25 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 05/13] mm/migrate_device: don't collect a range twice Lorenzo Stoakes (ARM)
2026-11-14 5:09 ` Balbir Singh
2026-11-14 6:45 ` Mika Penttilä
2026-11-14 18:34 ` Lorenzo Stoakes (ARM)
2026-11-15 9:24 ` Mika Penttilä
2026-11-14 19:56 ` Chris Down
2026-11-18 15:29 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 06/13] mm/migrate_device: don't let go of the fault page Lorenzo Stoakes (ARM)
2026-11-13 22:31 ` Balbir Singh
2026-11-14 19:56 ` Chris Down
2026-11-18 15:31 ` David Hildenbrand (Arm)
2026-11-18 16:41 ` Lorenzo Stoakes (ARM)
2026-11-13 21:45 ` [PATCH v2 07/13] mm/migrate_device: look up fault folio after a split Lorenzo Stoakes (ARM)
2026-11-13 22:20 ` Balbir Singh
2026-11-14 19:56 ` Chris Down
2026-11-18 15:31 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 08/13] mm/migrate_device: fix ksmd oops on a migrated KSM page Lorenzo Stoakes (ARM)
2026-11-14 19:56 ` Chris Down
2026-11-15 12:43 ` Lorenzo Stoakes (ARM)
2026-11-18 15:32 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 09/13] mm/migrate_device: fix use-after-free of the anon rmap Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-18 15:33 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 10/13] mm/migrate_device: refuse to migrate shadow stacks Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-18 15:33 ` David Hildenbrand (Arm)
2026-11-13 21:45 ` [PATCH v2 12/13] percpu: search the whole reserved chunk Lorenzo Stoakes (ARM)
2026-11-14 19:57 ` Chris Down
2026-11-24 16:18 ` + percpu-search-the-whole-reserved-chunk.patch added to mm-unstable branch Andrew Morton
2026-11-16 15:37 ` [PATCH v2 00/13] mm: batch of (urgentish?) fixes in oomk, cachestat, dev-migrate, percpu David Hildenbrand (Arm)
2026-11-18 15:35 ` David Hildenbrand (Arm)
2026-11-18 17:21 ` Lorenzo Stoakes (ARM)
2026-11-18 19:47 ` David Hildenbrand (Arm)
2026-11-19 21:58 ` Lorenzo Stoakes (ARM)
2026-11-19 17:09 ` (subset) " David Hildenbrand
2026-11-19 17:10 ` David Hildenbrand
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=20261124161833.834211F000E0@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=byungchul@sk.com \
--cc=chris@chrisdown.name \
--cc=cl@gentwo.org \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=dennis@kernel.org \
--cc=dennisszhou@gmail.com \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jbacik@fb.com \
--cc=jglisse@redhat.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kas@kernel.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=ljs@kernel.org \
--cc=mason@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=mm-commits@vger.kernel.org \
--cc=nphamcs@gmail.com \
--cc=peng.fan@nxp.com \
--cc=pfalcato@suse.de \
--cc=rick.p.edgecombe@intel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--cc=yu-cheng.yu@intel.com \
--cc=ziy@nvidia.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