* [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
@ 2026-10-24 5:35 Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 1/2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM Leno Hou via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Leno Hou via B4 Relay @ 2026-10-24 5:35 UTC (permalink / raw)
To: stable
Cc: Leno Hou, Wei Xu, Zeng Jingxiang, Kairui Song, Chris Li,
T.J. Mercier, Yu Zhao, Andrew Morton, Baolin Wang, Barry Song,
Johannes Weiner, Shakeel Butt, Axel Rasmussen, David Hildenbrand,
Lorenzo Stoakes (Oracle), Michal Hocko, Qi Zheng, Yuanchu Xie
The series backports the following upstream commits:
1. 1bc542c6a0d1 ("mm/vmscan: wake up flushers conditionally to avoid cgroup OOM")
2. 13b6b6209104 ("mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU")
Patch 1 wakes up flushers conditionally when a memcg is about to OOM due
to dirty caches. It restores the flusher wakeup that was removed by
14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle").
Patch 2 handles cgroup v1, where balance_dirty_pages() does not throttle
dirty folios. See 9badce000e2c ("cgroup, writeback: don't enable cgroup
writeback on traditional hierarchies"). After 6b0dfabb3555 ("fs: Remove
aops->writepage"), reclaim no longer writes back filesystem folios
directly. On large memory systems, the flusher may not be able to write
back quickly enough, leaving many folios already under writeback. Since
MGLRU cannot reclaim these dirty folios, the system may run out of memory
and trigger the OOM killer. Patch 2 throttles reclaim after waking up
the flusher for cgroup v1, similar to 81a70c21d917
("mm/cgroup/reclaim: fix dirty pages throttling on cgroup v1").
Signed-off-by: Leno Hou <lenohou@gmail.com>
---
Changes in v2:
- Link to v1: https://patch.msgid.link/20261024-linux-6-1-y-v1-0-cf381365f30b@gmail.com
---
Leno Hou (2):
mm/vmscan: wake up flushers conditionally to avoid cgroup OOM
mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
mm/vmscan.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
---
base-commit: 0aebf2870d53a8d97e02a99e2103ea0b38950c1b
change-id: 20261024-fix-mglru-v6-6-v2-d8bc9d4183c7
Best regards,
--
Leno Hou <lenohou@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH PATCH 6.12 1/2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM
2026-10-24 5:35 [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
@ 2026-10-24 5:35 ` Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 2/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
2026-10-26 15:50 ` [PATCH 6.12 0/2] " Leno Hou
2 siblings, 0 replies; 6+ messages in thread
From: Leno Hou via B4 Relay @ 2026-10-24 5:35 UTC (permalink / raw)
To: stable
Cc: Leno Hou, Wei Xu, Zeng Jingxiang, Kairui Song, Chris Li,
T.J. Mercier, Yu Zhao, Andrew Morton
From: Leno Hou <lenohou@gmail.com>
[ Upstream commit 1bc542c6a0d1444559ab75823a89a94d244bf933 ]
Commit 14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle")
removed the opportunity to wake up flushers during the MGLRU page
reclamation process can lead to an increased likelihood of triggering OOM
when encountering many dirty pages during reclamation on MGLRU.
This leads to premature OOM if there are too many dirty pages in cgroup:
Killed
dd invoked oom-killer: gfp_mask=0x101cca(GFP_HIGHUSER_MOVABLE|__GFP_WRITE),
order=0, oom_score_adj=0
Call Trace:
<TASK>
dump_stack_lvl+0x5f/0x80
dump_stack+0x14/0x20
dump_header+0x46/0x1b0
oom_kill_process+0x104/0x220
out_of_memory+0x112/0x5a0
mem_cgroup_out_of_memory+0x13b/0x150
try_charge_memcg+0x44f/0x5c0
charge_memcg+0x34/0x50
__mem_cgroup_charge+0x31/0x90
filemap_add_folio+0x4b/0xf0
__filemap_get_folio+0x1a4/0x5b0
? srso_return_thunk+0x5/0x5f
? __block_commit_write+0x82/0xb0
ext4_da_write_begin+0xe5/0x270
generic_perform_write+0x134/0x2b0
ext4_buffered_write_iter+0x57/0xd0
ext4_file_write_iter+0x76/0x7d0
? selinux_file_permission+0x119/0x150
? srso_return_thunk+0x5/0x5f
? srso_return_thunk+0x5/0x5f
vfs_write+0x30c/0x440
ksys_write+0x65/0xe0
__x64_sys_write+0x1e/0x30
x64_sys_call+0x11c2/0x1d50
do_syscall_64+0x47/0x110
entry_SYSCALL_64_after_hwframe+0x76/0x7e
memory: usage 308224kB, limit 308224kB, failcnt 2589
swap: usage 0kB, limit 9007199254740988kB, failcnt 0
...
file_dirty 303247360
file_writeback 0
...
oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=test,
mems_allowed=0,oom_memcg=/test,task_memcg=/test,task=dd,pid=4404,uid=0
Memory cgroup out of memory: Killed process 4404 (dd) total-vm:10512kB,
anon-rss:1152kB, file-rss:1824kB, shmem-rss:0kB, UID:0 pgtables:76kB
oom_score_adj:0
The flusher wake up was removed to decrease SSD wearing, but if we are
seeing all dirty folios at the tail of an LRU, not waking up the flusher
could lead to thrashing easily. So wake it up when a memcg is about to
OOM due to dirty caches.
I did run the build kernel test[1] on V6, with -j16 1G memcg on my local
branch:
Without the patch(10 times):
user 1449.394
system 368.78 372.58 363.03 362.31 360.84 372.70 368.72 364.94 373.51
366.58 (avg 367.399)
real 164.883
With the V6 patch(10 times):
user 1447.525
system 360.87 360.63 372.39 364.09 368.49 365.15 359.93 362.04 359.72
354.60 (avg 362.79)
real 164.514
Test results show that this patch has about 1% performance improvement,
which should be caused by noise.
Link: https://lkml.kernel.org/r/20241026115714.1437435-1-jingxiangzeng.cas@gmail.com
Link: https://lore.kernel.org/all/CACePvbV4L-gRN9UKKuUnksfVJjOTq_5Sti2-e=pb_w51kucLKQ@mail.gmail.com/ [1]
Fixes: 14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle")
Suggested-by: Wei Xu <weixugc@google.com>
Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
Signed-off-by: Kairui Song <kasong@tencent.com>
Reviewed-by: Wei Xu <weixugc@google.com>
Tested-by: Chris Li <chrisl@kernel.org>
Cc: T.J. Mercier <tjmercier@google.com>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Leno Hou <lenohou@gmail.com>
---
mm/vmscan.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 4197e10a27b6..a165f685216d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4913,6 +4913,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c
int tier_idx)
{
bool success;
+ bool dirty, writeback;
int gen = folio_lru_gen(folio);
int type = folio_is_file_lru(folio);
int zone = folio_zonenum(folio);
@@ -4961,9 +4962,17 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c
return true;
}
+ dirty = folio_test_dirty(folio);
+ writeback = folio_test_writeback(folio);
+ if (type == LRU_GEN_FILE && dirty) {
+ sc->nr.file_taken += delta;
+ if (!writeback)
+ sc->nr.unqueued_dirty += delta;
+ }
+
/* waiting for writeback */
- if (folio_test_locked(folio) || folio_test_writeback(folio) ||
- (type == LRU_GEN_FILE && folio_test_dirty(folio))) {
+ if (folio_test_locked(folio) || writeback ||
+ (type == LRU_GEN_FILE && dirty)) {
gen = folio_inc_gen(lruvec, folio, true);
list_move(&folio->lru, &lrugen->folios[gen][type][zone]);
return true;
@@ -5075,6 +5084,8 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc,
__count_memcg_events(memcg, PGREFILL, sorted);
__count_vm_events(PGSCAN_ANON + type, isolated);
+ if (type == LRU_GEN_FILE)
+ sc->nr.file_taken += isolated;
/*
* There might not be eligible folios due to reclaim_idx. Check the
* remaining to prevent livelock if it's not making progress.
@@ -5203,6 +5214,7 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap
return scanned;
retry:
reclaimed = shrink_folio_list(&list, pgdat, sc, &stat, false);
+ sc->nr.unqueued_dirty += stat.nr_unqueued_dirty;
sc->nr_reclaimed += reclaimed;
list_for_each_entry_safe_reverse(folio, next, &list, lru) {
@@ -5415,6 +5427,12 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
cond_resched();
}
+ /*
+ * If too many file cache in the coldest generation can't be evicted
+ * due to being dirty, wake up the flusher.
+ */
+ if (sc->nr.unqueued_dirty && sc->nr.unqueued_dirty == sc->nr.file_taken)
+ wakeup_flusher_threads(WB_REASON_VMSCAN);
/* whether this lruvec should be rotated */
return nr_to_scan < 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH PATCH 6.12 2/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
2026-10-24 5:35 [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 1/2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM Leno Hou via B4 Relay
@ 2026-10-24 5:35 ` Leno Hou via B4 Relay
2026-10-26 15:50 ` [PATCH 6.12 0/2] " Leno Hou
2 siblings, 0 replies; 6+ messages in thread
From: Leno Hou via B4 Relay @ 2026-10-24 5:35 UTC (permalink / raw)
To: stable
Cc: Leno Hou, Baolin Wang, Barry Song, Kairui Song, Johannes Weiner,
Shakeel Butt, Axel Rasmussen, David Hildenbrand,
Lorenzo Stoakes (Oracle), Michal Hocko, Qi Zheng, Wei Xu,
Yuanchu Xie, Andrew Morton
From: Leno Hou <lenohou@gmail.com>
[ Upstream commit 13b6b620910436c29dea398382e83c9499fd13e4 ]
The balance_dirty_pages() won't do the dirty folios throttling on
cgroupv1. See commit 9badce000e2c ("cgroup, writeback: don't enable
cgroup writeback on traditional hierarchies").
Moreover, after commit 6b0dfabb3555 ("fs: Remove aops->writepage"), we no
longer attempt to write back filesystem folios through reclaim.
On large memory systems, the flusher may not be able to write back quickly
enough. Consequently, MGLRU will encounter many folios that are already
under writeback. Since we cannot reclaim these dirty folios, the system
may run out of memory and trigger the OOM killer.
Hence, for cgroup v1, let's throttle reclaim after waking up the flusher,
which is similar to commit 81a70c21d917 ("mm/cgroup/reclaim: fix dirty
pages throttling on cgroup v1"), to avoid unnecessary OOM.
The following test program can easily reproduce the OOM issue. With this
patch applied, the test passes successfully.
$mkdir /sys/fs/cgroup/memory/test
$echo 256M > /sys/fs/cgroup/memory/test/memory.limit_in_bytes
$echo $$ > /sys/fs/cgroup/memory/test/cgroup.procs
$dd if=/dev/zero of=/mnt/data.bin bs=1M count=800
Link: https://lore.kernel.org/3445af0f09e8ca945492e052e82594f8c4f2e2f6.1774606060.git.baolin.wang@linux.alibaba.com
Fixes: ac35a4902374 ("mm: multi-gen LRU: minimal implementation")
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Barry Song <baohua@kernel.org>
Reviewed-by: Kairui Song <kasong@tencent.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Leno Hou <lenohou@gmail.com>
---
mm/vmscan.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index a165f685216d..43b808e4e9f2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5431,8 +5431,22 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
* If too many file cache in the coldest generation can't be evicted
* due to being dirty, wake up the flusher.
*/
- if (sc->nr.unqueued_dirty && sc->nr.unqueued_dirty == sc->nr.file_taken)
+ if (sc->nr.unqueued_dirty && sc->nr.unqueued_dirty == sc->nr.file_taken) {
+ struct pglist_data *pgdat = lruvec_pgdat(lruvec);
+
wakeup_flusher_threads(WB_REASON_VMSCAN);
+ /*
+ * For cgroupv1 dirty throttling is achieved by waking up
+ * the kernel flusher here and later waiting on folios
+ * which are in writeback to finish (see shrink_folio_list()).
+ *
+ * Flusher may not be able to issue writeback quickly
+ * enough for cgroupv1 writeback throttling to work
+ * on a large system.
+ */
+ if (!writeback_throttling_sane(sc))
+ reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK);
+ }
/* whether this lruvec should be rotated */
return nr_to_scan < 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
2026-10-24 5:35 [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 1/2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 2/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
@ 2026-10-26 15:50 ` Leno Hou
2026-10-26 18:08 ` Greg KH
2 siblings, 1 reply; 6+ messages in thread
From: Leno Hou @ 2026-10-26 15:50 UTC (permalink / raw)
To: lenohou
Cc: stable, Wei Xu, Zeng Jingxiang, Kairui Song, Chris Li,
T.J. Mercier, Yu Zhao, Andrew Morton, Baolin Wang, Barry Song,
Johannes Weiner, Shakeel Butt, Axel Rasmussen, David Hildenbrand,
Lorenzo Stoakes (Oracle), Michal Hocko, Qi Zheng, Yuanchu Xie
Sorry, please skip 6.12 branch and just use 6.1 & 6.6 branch
Thanks
Leno Hou
E-mail : lenohou@gmail.com
On Mon, Oct 26, 2026 at 11:46 PM Leno Hou via B4 Relay
<devnull+lenohou.gmail.com@kernel.org> wrote:
>
> The series backports the following upstream commits:
>
> 1. 1bc542c6a0d1 ("mm/vmscan: wake up flushers conditionally to avoid cgroup OOM")
> 2. 13b6b6209104 ("mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU")
>
> Patch 1 wakes up flushers conditionally when a memcg is about to OOM due
> to dirty caches. It restores the flusher wakeup that was removed by
> 14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle").
>
> Patch 2 handles cgroup v1, where balance_dirty_pages() does not throttle
> dirty folios. See 9badce000e2c ("cgroup, writeback: don't enable cgroup
> writeback on traditional hierarchies"). After 6b0dfabb3555 ("fs: Remove
> aops->writepage"), reclaim no longer writes back filesystem folios
> directly. On large memory systems, the flusher may not be able to write
> back quickly enough, leaving many folios already under writeback. Since
> MGLRU cannot reclaim these dirty folios, the system may run out of memory
> and trigger the OOM killer. Patch 2 throttles reclaim after waking up
> the flusher for cgroup v1, similar to 81a70c21d917
> ("mm/cgroup/reclaim: fix dirty pages throttling on cgroup v1").
>
> Signed-off-by: Leno Hou <lenohou@gmail.com>
> ---
> Changes in v2:
> - Link to v1: https://patch.msgid.link/20261024-linux-6-1-y-v1-0-cf381365f30b@gmail.com
>
> ---
> Leno Hou (2):
> mm/vmscan: wake up flushers conditionally to avoid cgroup OOM
> mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
>
> mm/vmscan.c | 36 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 34 insertions(+), 2 deletions(-)
> ---
> base-commit: 0aebf2870d53a8d97e02a99e2103ea0b38950c1b
> change-id: 20261024-fix-mglru-v6-6-v2-d8bc9d4183c7
>
> Best regards,
> --
> Leno Hou <lenohou@gmail.com>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
2026-10-26 15:50 ` [PATCH 6.12 0/2] " Leno Hou
@ 2026-10-26 18:08 ` Greg KH
2026-10-27 16:39 ` Leno Hou
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2026-10-26 18:08 UTC (permalink / raw)
To: Leno Hou
Cc: stable, Wei Xu, Zeng Jingxiang, Kairui Song, Chris Li,
T.J. Mercier, Yu Zhao, Andrew Morton, Baolin Wang, Barry Song,
Johannes Weiner, Shakeel Butt, Axel Rasmussen, David Hildenbrand,
Lorenzo Stoakes (Oracle), Michal Hocko, Qi Zheng, Yuanchu Xie
On Mon, Oct 26, 2026 at 11:50:47PM +0800, Leno Hou wrote:
> Sorry, please skip 6.12 branch and just use 6.1 & 6.6 branch
We can't do that, you have to have all patches in all relevant branches
(i.e. you can not just have fixes in older branches, otherwise users
will have regressions when they upgrade.)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU
2026-10-26 18:08 ` Greg KH
@ 2026-10-27 16:39 ` Leno Hou
0 siblings, 0 replies; 6+ messages in thread
From: Leno Hou @ 2026-10-27 16:39 UTC (permalink / raw)
To: Greg KH
Cc: stable, Wei Xu, Zeng Jingxiang, Kairui Song, Chris Li,
T.J. Mercier, Yu Zhao, Andrew Morton, Baolin Wang, Barry Song,
Johannes Weiner, Shakeel Butt, Axel Rasmussen, David Hildenbrand,
Lorenzo Stoakes (Oracle), Michal Hocko, Qi Zheng, Yuanchu Xie
OK, resend as following and also for 6.18 without regressions
[PATCH Resend 6.12] mm: vmscan: fix dirty folios throttling on cgroup
v1 for MGLRU
Leno Hou
E-mail : lenohou@gmail.com
On Tue, Oct 27, 2026 at 2:08 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Mon, Oct 26, 2026 at 11:50:47PM +0800, Leno Hou wrote:
> > Sorry, please skip 6.12 branch and just use 6.1 & 6.6 branch
>
> We can't do that, you have to have all patches in all relevant branches
> (i.e. you can not just have fixes in older branches, otherwise users
> will have regressions when they upgrade.)
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-27 16:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-24 5:35 [PATCH 6.12 0/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 1/2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM Leno Hou via B4 Relay
2026-10-24 5:35 ` [PATCH PATCH 6.12 2/2] mm: vmscan: fix dirty folios throttling on cgroup v1 for MGLRU Leno Hou via B4 Relay
2026-10-26 15:50 ` [PATCH 6.12 0/2] " Leno Hou
2026-10-26 18:08 ` Greg KH
2026-10-27 16:39 ` Leno Hou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox