Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd
From: Bingfang Guo
Date: Thu Nov 26 2026 - 04:56:08 EST
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@xxxxxxxxxx> 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@xxxxxxxxxx/
>
> Johannes shared some thoughts on this here:
>
> https://lore.kernel.org/linux-mm/aejtfpBUu7gNV6Tk@xxxxxxxxxxx/
>
> 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