* [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; 6+ 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] 6+ messages in thread* Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd 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 0 siblings, 1 reply; 6+ messages in thread From: Barry Song @ 2026-11-25 7:38 UTC (permalink / raw) To: bingfangguo Cc: Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Yu Zhao, Bingfang Guo, linux-mm, linux-kernel, stable On Wed, Nov 25, 2026 at 12:32 PM Bingfang Guo via B4 Relay <devnull+bingfangguo.tencent.com@kernel.org> wrote: > > 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. It seems we should address the underlying issue of why order-9 reclaim keeps advancing memcg generations until all memcgs are younger than min_ttl. > > 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. I'm not really convinced this is the correct fix. It seems to work around an issue with min_ttl for higher-order allocations, but it doesn't appear to address the root cause. And what about order-1 and order-2 allocations? > > 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. > So the real question is: if order-9 reclaim can't make progress, why do we keep triggering memcg aging and end up over-reclaiming? > 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. I know, I know. But this isn't really the root cause, is it? Even if we avoid OOM kills, we may still end up with excessive reclaim or system overheating, right? > > -- > 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> > > Thanks, Barry ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd 2026-11-25 7:38 ` Barry Song @ 2026-11-25 9:31 ` Bingfang Guo 2026-11-26 0:40 ` Barry Song 0 siblings, 1 reply; 6+ messages in thread From: Bingfang Guo @ 2026-11-25 9:31 UTC (permalink / raw) To: Barry Song Cc: bingfangguo, Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Yu Zhao, linux-mm, linux-kernel, stable On Wed, Nov 25, 2026 at 03:38:25PM +0800, Barry Song wrote: > On Wed, Nov 25, 2026 at 12:32 PM Bingfang Guo via B4 Relay > <devnull+bingfangguo.tencent.com@kernel.org> wrote: > > > > 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. > > It seems we should address the underlying issue of why order-9 reclaim > keeps advancing memcg generations until all memcgs are younger than > min_ttl. > > > > > 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. > > I'm not really convinced this is the correct fix. It seems to work > around an issue with min_ttl for higher-order allocations, but it > doesn't appear to address the root cause. > > And what about order-1 and order-2 allocations? > Hi, Barry! Thanks for your reviewing! I agree that we should fix the root cause. Reclaims triggered by high order allocations should not push the generations forward too frequently. That is really insightful! > > > > 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. > > > > So the real question is: if order-9 reclaim can't make progress, why > do we keep triggering memcg aging and end up over-reclaiming? > > > 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. > > I know, I know. But this isn't really the root cause, is it? > Even if we avoid OOM kills, we may still end up with excessive reclaim > or system overheating, right? > You are right. Maybe we can start from skipping aging in reclaim path if the youngest gen is still too young? And maybe for this path, min_ttl can have a default value? Is that a good idea? diff --git a/mm/vmscan.c b/mm/vmscan.c index d891ae46baf49..7f9b14b772d14 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5136,8 +5136,11 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, return false; + /* avoid excessive aging for huge allocations */ + if (unlikely(sc->order)) { + int gen = lru_gen_from_seq(max_seq); + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); + return !time_is_before_jiffies(birth + min_ttl); + } /* better to run aging even though eviction is still possible */ return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS == max_seq; I will give this a test later and share more findings. Thanks, Bingfang > > > > -- > > 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> > > > > > > Thanks, > Barry ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd 2026-11-25 9:31 ` Bingfang Guo @ 2026-11-26 0:40 ` Barry Song 2026-11-26 9:55 ` Bingfang Guo 0 siblings, 1 reply; 6+ messages in thread From: Barry Song @ 2026-11-26 0:40 UTC (permalink / raw) To: Bingfang Guo Cc: bingfangguo, Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Yu Zhao, linux-mm, linux-kernel, stable On Wed, Nov 25, 2026 at 5:32 PM Bingfang Guo <bfguo@icloud.com> wrote: [...] > You are right. Maybe we can start from skipping aging in reclaim path if the > youngest gen is still too young? And maybe for this path, min_ttl can have a > default value? Is that a good idea? > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index d891ae46baf49..7f9b14b772d14 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -5136,8 +5136,11 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, > return false; > > + /* avoid excessive aging for huge allocations */ > + if (unlikely(sc->order)) { > + int gen = lru_gen_from_seq(max_seq); > + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); > + return !time_is_before_jiffies(birth + min_ttl); > + } I'm not convinced that we need to couple the aging decision with min_ttl protection. This has been a long-standing problem: high-order allocations can trigger excessive reclaim and still fail to obtain contiguous memory. I've tried to address this twice, but haven't found a satisfactory solution yet: https://lore.kernel.org/linux-mm/20260422021842.78495-1-baohua@kernel.org/ Johannes shared some thoughts on this here: https://lore.kernel.org/linux-mm/aejtfpBUu7gNV6Tk@cmpxchg.org/ Do you have any traces showing how many pages kswapd scans and reclaims while kcompactd makes little progress toward satisfying order-9 allocations? Basically, I think we need some form of throttling to prevent kswapd from freeing more and more memory when there is already plenty of free memory, yet compaction is making little progress toward satisfying order-9 allocations. > > /* better to run aging even though eviction is still possible */ > return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS == max_seq; > > I will give this a test later and share more findings. Thanks, Barry ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd 2026-11-26 0:40 ` Barry Song @ 2026-11-26 9:55 ` Bingfang Guo 2026-11-26 11:51 ` Barry Song 0 siblings, 1 reply; 6+ messages in thread From: Bingfang Guo @ 2026-11-26 9:55 UTC (permalink / raw) To: Barry Song Cc: bingfangguo, Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Yu Zhao, linux-mm, linux-kernel, stable Hi, Barry! On Thu, Nov 26, 2026 at 08:40:44AM +0800, Barry Song wrote: > On Wed, Nov 25, 2026 at 5:32 PM Bingfang Guo <bfguo@icloud.com> wrote: > [...] > > You are right. Maybe we can start from skipping aging in reclaim path if the > > youngest gen is still too young? And maybe for this path, min_ttl can have a > > default value? Is that a good idea? > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index d891ae46baf49..7f9b14b772d14 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -5136,8 +5136,11 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, > > return false; > > > > + /* avoid excessive aging for huge allocations */ > > + if (unlikely(sc->order)) { > > + int gen = lru_gen_from_seq(max_seq); > > + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); > > + return !time_is_before_jiffies(birth + min_ttl); > > + } > > I'm not convinced that we need to couple the aging decision with > min_ttl protection. > > This has been a long-standing problem: high-order allocations can > trigger excessive reclaim and still fail to obtain contiguous > memory. > > I've tried to address this twice, but haven't found a satisfactory > solution yet: > > https://lore.kernel.org/linux-mm/20260422021842.78495-1-baohua@kernel.org/ > > Johannes shared some thoughts on this here: > > https://lore.kernel.org/linux-mm/aejtfpBUu7gNV6Tk@cmpxchg.org/ > > Do you have any traces showing how many pages kswapd scans and > reclaims while kcompactd makes little progress toward satisfying > order-9 allocations? We encountered this problem when running a stability test on a 6G VM with 2 nodes. It populates the system with hwpoisoned pages per 511 pages so order-9 migrations should mostly fail. Then it tries to allocate order-9 pages. So the results might not quite reflect real scenarios, but I think that applies to unmigratable pages such as slab as well. When the system OOMs and kills all the processes, we have about 4.8 GiB memory free and: PGSCAN_KSWAPD : 162,406,932 PGSTEAL_KSWAPD : 91,233,588 COMPACTMIGRATE_SCANNED : 6,542,604,811 (kcompactd: 4,041,105,566, 61.8%) COMPACTFREE_SCANNED : 541,265,798 (kcompactd: 348,448,520, 64.4%) COMPACTISOLATED : 174,688,832 (2.67% of migrated) PGMIGRATE_SUCCESS : 100,824,439 PGMIGRATE_FAIL : 2,022,069 So seems in this case, compaction fail rate is quite high and we have really many scanned pages compared to the actually used size (about 1G). > > Basically, I think we need some form of throttling to prevent > kswapd from freeing more and more memory when there is already > plenty of free memory, yet compaction is making little progress > toward satisfying order-9 allocations. > Yes! And I've read your and Johannes's previous discussions. It also seems weird to me to keep reclaiming even if there are plenty of pages available there. And it's quite tricky to balance between that and concurrency... Looking into shrink path in kswapd, sc->nr_to_reclaim += max(high_wmark_pages(z: zone), SWAP_CLUSTER_MAX); I think this is too much, for this case. So I think maybe we can still reclaim for scalability, but reduce its target. At least we should take reclaimable memory size and free memory size into consideration, and rescale nr_to_reclaim. The check to restore sc->order below can be relaxed as well, if free pages are sufficient. Thanks, Bingfang > > > > /* better to run aging even though eviction is still possible */ > > return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS == max_seq; > > > > I will give this a test later and share more findings. > > Thanks, > Barry ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd 2026-11-26 9:55 ` Bingfang Guo @ 2026-11-26 11:51 ` Barry Song 0 siblings, 0 replies; 6+ messages in thread From: Barry Song @ 2026-11-26 11:51 UTC (permalink / raw) To: Bingfang Guo Cc: bingfangguo, Andrew Morton, Johannes Weiner, David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Yu Zhao, linux-mm, linux-kernel, stable On Thu, Nov 26, 2026 at 5:56 PM Bingfang Guo <bfguo@icloud.com> wrote: > > Hi, Barry! > > On Thu, Nov 26, 2026 at 08:40:44AM +0800, Barry Song wrote: > > On Wed, Nov 25, 2026 at 5:32 PM Bingfang Guo <bfguo@icloud.com> wrote: > > [...] > > > You are right. Maybe we can start from skipping aging in reclaim path if the > > > youngest gen is still too young? And maybe for this path, min_ttl can have a > > > default value? Is that a good idea? > > > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > > index d891ae46baf49..7f9b14b772d14 100644 > > > --- a/mm/vmscan.c > > > +++ b/mm/vmscan.c > > > @@ -5136,8 +5136,11 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, > > > return false; > > > > > > + /* avoid excessive aging for huge allocations */ > > > + if (unlikely(sc->order)) { > > > + int gen = lru_gen_from_seq(max_seq); > > > + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); > > > + return !time_is_before_jiffies(birth + min_ttl); > > > + } > > > > I'm not convinced that we need to couple the aging decision with > > min_ttl protection. > > > > This has been a long-standing problem: high-order allocations can > > trigger excessive reclaim and still fail to obtain contiguous > > memory. > > > > I've tried to address this twice, but haven't found a satisfactory > > solution yet: > > > > https://lore.kernel.org/linux-mm/20260422021842.78495-1-baohua@kernel.org/ > > > > Johannes shared some thoughts on this here: > > > > https://lore.kernel.org/linux-mm/aejtfpBUu7gNV6Tk@cmpxchg.org/ > > > > Do you have any traces showing how many pages kswapd scans and > > reclaims while kcompactd makes little progress toward satisfying > > order-9 allocations? > > We encountered this problem when running a stability test on a 6G > VM with 2 nodes. It populates the system with hwpoisoned pages > per 511 pages so order-9 migrations should mostly fail. Then it > tries to allocate order-9 pages. So the results might not quite > reflect real scenarios, but I think that applies to unmigratable > pages such as slab as well. > > When the system OOMs and kills all the processes, we have about > 4.8 GiB memory free and: > > PGSCAN_KSWAPD : 162,406,932 > PGSTEAL_KSWAPD : 91,233,588 > COMPACTMIGRATE_SCANNED : 6,542,604,811 (kcompactd: 4,041,105,566, 61.8%) > COMPACTFREE_SCANNED : 541,265,798 (kcompactd: 348,448,520, 64.4%) > COMPACTISOLATED : 174,688,832 (2.67% of migrated) > PGMIGRATE_SUCCESS : 100,824,439 > PGMIGRATE_FAIL : 2,022,069 > > So seems in this case, compaction fail rate is quite high and we > have really many scanned pages compared to the actually used size > (about 1G). > > > > > Basically, I think we need some form of throttling to prevent > > kswapd from freeing more and more memory when there is already > > plenty of free memory, yet compaction is making little progress > > toward satisfying order-9 allocations. > > > > Yes! And I've read your and Johannes's previous discussions. It > also seems weird to me to keep reclaiming even if there are > plenty of pages available there. And it's quite tricky to balance > between that and concurrency... > > Looking into shrink path in kswapd, > > sc->nr_to_reclaim += max(high_wmark_pages(z: zone), SWAP_CLUSTER_MAX); > > I think this is too much, for this case. So I think maybe we can > still reclaim for scalability, but reduce its target. At least we > should take reclaimable memory size and free memory size into > consideration, and rescale nr_to_reclaim. So, conceptually, is this along the lines of what we have in mind? I'd also be interested in hearing Johannes's thoughts on this. diff --git a/mm/vmscan.c b/mm/vmscan.c index 81797b71228f..0144fe4be738 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7450,17 +7450,31 @@ static bool prepare_kswapd_sleep(pg_data_t *pgdat, int order, * This is used to determine if the scanning priority needs to be raised. */ static bool kswapd_shrink_node(pg_data_t *pgdat, - struct scan_control *sc) + struct scan_control *sc, + int highest_zoneidx) { struct zone *zone; int z; unsigned long nr_reclaimed = sc->nr_reclaimed; + bool can_compact = sc->order > 0; /* Reclaim a number of pages proportional to the number of zones */ sc->nr_to_reclaim = 0; + for_each_managed_zone_pgdat(zone, pgdat, z, sc->reclaim_idx) { + unsigned long mark = high_wmark_pages(zone); + + if (can_compact && !compaction_suitable(zone, sc->order, mark, highest_zoneidx)) + can_compact = false; sc->nr_to_reclaim += max(high_wmark_pages(zone), SWAP_CLUSTER_MAX); } + /* + * If all eligible zones are already suitable for compaction, + * limit further reclaim to avoid over-reclaiming due to + * fragmentation. + */ + if (can_compact) + sc->nr_to_reclaim = min(sc->nr_to_reclaim, compact_gap(sc->order)); /* * Historically care was taken to put equal pressure on all zones but @@ -7637,7 +7651,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) * enough pages are already being scanned that the high * watermark would be met at 100% efficiency. */ - if (kswapd_shrink_node(pgdat, &sc)) + if (kswapd_shrink_node(pgdat, &sc, highest_zoneidx)) raise_priority = false; /* Thanks, Barry ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 11:51 UTC | newest] Thread overview: 6+ 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 2026-11-26 0:40 ` Barry Song 2026-11-26 9:55 ` Bingfang Guo 2026-11-26 11:51 ` Barry Song
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox