Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd
@ 2026-11-25  4:32 Bingfang Guo via B4 Relay
  2026-11-25  7:38 ` Barry Song
  0 siblings, 1 reply; 3+ messages in thread
From: Bingfang Guo via B4 Relay @ 2026-11-25  4:32 UTC (permalink / raw)
  To: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko,
	Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Barry Song,
	Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
	Yu Zhao, Bingfang Guo
  Cc: linux-mm, linux-kernel, stable, Bingfang Guo

From: Bingfang Guo <bingfangguo@tencent.com>

We observed that when MGLRU min_ttl is set and the system is highly
fragmented, high order allocations (e.g. order == 9) will fail and wake
up kswapd. It can not make any progress, while pushing generations of
memcgs so that they all end up younger than min_ttl_ms, repeatedly
triggering the OOM killer in lru_gen_age_node(). Then the whole process
repeats until all processes are killed and the kernel panics.

The purpose of the min_ttl is to prevent thrashing when all memcgs are
too young to reclaim instead of preventing fragmentation. So fix this by
restoring the behavior in commit 30d77b7eef019 ("mm/mglru: fix
ineffective protection calculation"), which skips OOM killer invocations
in lru_gen_age_node() for sc->order != 0.

Fixes: 30d77b7eef019 ("mm/mglru: fix ineffective protection calculation")
Signed-off-by: Bingfang Guo <bingfangguo@tencent.com>
---
==== Testing ====

Tested on a VM with 6 cores and 6GiB of memory, HZ=1000, MGLRU enabled,
min_ttl_ms set to 1000, and a workload that fragments the memory then
allocates 2M pages.

Without the patch, kswapd kills all processes and panics the system even
with plenty of memory available. With the patch, allocations fail but
the system remains stable.

--
Changes in v2:
- Reword the comments to explain the purpose clearly. (Kairui)
- Relax the skip condition to sc->order != 0 for soundness. (sashiko)
- Rebase to mm-unstable.
- Cc stable.
- Link to v1: https://lore.kernel.org/all/20261027-fix-mglru-kswapd-age-v1-1-b1ffdec4ae52@tencent.com/
---
 mm/vmscan.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 836f50814ffa..9fadc6f9da49 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4351,7 +4351,7 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
 {
 	struct mem_cgroup *memcg;
 	unsigned long min_ttl = READ_ONCE(lru_gen_min_ttl);
-	bool reclaimable = !min_ttl;
+	bool reclaimable = !min_ttl || sc->order;
 
 	VM_WARN_ON_ONCE(!current_is_kswapd());
 
@@ -4371,6 +4371,9 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
 	 * The main goal is to OOM kill if every generation from all memcgs is
 	 * younger than min_ttl. However, another possibility is all memcgs are
 	 * either too small or below min.
+	 *
+	 * OOM killing for fragmentation is not desired. So skip this when
+	 * sc->order != 0.
 	 */
 	if (!reclaimable && mutex_trylock(&oom_lock)) {
 		struct oom_control oc = {

---
base-commit: a3d0117e02bfa1c3bb6c50e7afe42bbecdbb3459
change-id: 20261026-fix-mglru-kswapd-age-98390614c746

Best regards,
-- 
Bingfang Guo <bingfangguo@tencent.com>




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25  9:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  4:32 [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd Bingfang Guo via B4 Relay
2026-11-25  7:38 ` Barry Song
2026-11-25  9:31   ` Bingfang Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox