Skip to contentSkip to conversation

mm/mglru: fix a few reclaim issues

PATCH In review Barry Song (Xiaomi) 4 participants 10 messages Nov 29 – Dec 1

Subsystems (4)
lore
Share & tools
lore

Barry Song (Xiaomi)

author reviewer
#0 lore raw

cover mm/mglru: fix a few reclaim issues

This series contains three MGLRU fixes originally proposed by Chris Mason and passed on to us by David Hildenbrand.

The issues addressed are:

1. Reparented folios becoming unreclaimable due to generation accounting falling outside the parent's [min_seq, max_seq] range.
2. A potential deadlock between reclaim and compaction when isolating folios.
3. Missing vmpressure notifications for global reclaim on cgroup v1.

Kairui and I have reviewed the fixes and made minor adjustments where necessary.

The series is based on mm-new.

Chris Mason (3):
mm/mglru: count all generations as evictable mm/mglru: test PG_lru before taking a folio reference mm/mglru: report root reclaim to memory.pressure_level

 mm/vmscan.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.3 (Apple Git-146)
author reviewer
#1 lore raw

PATCH 1/3 mm/mglru: count all generations as evictable

From: Chris Mason <[email protected]>

With MGLRU enabled, clean page cache that was reparented from a removed memory cgroup can stay unreclaimable for as long as the parent has no other evictable folios on the same node.

try_to_shrink_lruvec() derives its scan count from lruvec_evictable_size(), and with a count of 0 it runs neither eviction nor aging. lruvec_evictable_size() adds up nr_pages[] only for the generations from min_seq to max_seq. That sum is complete only if the count of a generation is 0 by the time min_seq advances past it.

But try_to_inc_min_seq() ignores the counts: it advances min_seq past a generation as soon as the lists of that generation are empty. A folio that folio_update_gen() promoted is counted in its new generation, but stays on the list of the generation that it came from. Normally min_seq stops at that list, before it reaches the new generation.

Reparenting moves each list and each count to the same index in the parent, where that index can stand for a different age:

    index (seq % MAX_NR_GENS)    0  1  2  3
    seq in the child             0  1  2  3
    seq in the parent            4  5  6  3
    folio F:  on folios[0], counted in nr_pages[3]
    child:    folios[0] holds min_seq at 0
    parent:   folios[3] is empty, so min_seq goes from 3 to 4
    sum:      nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F

The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations in lruvec_evictable_size().

Fixes 163bc3d68c9f ("mm/mglru: restructure the reclaim loop")
[Barry: Rebased onto mm-new and added comments]
---
 mm/vmscan.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
mm/vmscan.c +6 -3
index cbed395955d4..60c416819c57 100644
@@ -4272,8 +4272,6 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	struct mem_cgroup *memcg = lruvec_memcg(lruvec);
 	int nid = lruvec_pgdat(lruvec)->node_id;
-	DEFINE_MAX_SEQ(lruvec);
-	DEFINE_MIN_SEQ(lruvec);
 
 	nr[LRU_GEN_ANON] = 0;
 	nr[LRU_GEN_FILE] = 0;
@@ -4281,7 +4279,12 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc
 	for_each_evictable_type(type, swappiness) {
 		if (type == LRU_GEN_ANON && !can_reclaim_anon_pages(memcg, nid, sc))
 			continue;
-		for (seq = min_seq[type]; seq <= max_seq; seq++)
+		/*
+		 * Reparenting can leave folios accounted for in
+		 * generations outside [min_seq, max_seq]. Count
+		 * them as well to ensure reclaim makes progress.
+		 */
+		for (seq = 0; seq < MAX_NR_GENS; seq++)
 			nr[type] += lruvec_gen_size(lrugen, type, seq, max_zone);
 	}
 }
Signature · 1 line
2.39.3 (Apple Git-146)
author reviewer
#4 lore raw

PATCH 2/3 mm/mglru: test PG_lru before taking a folio reference

In reply to Barry Song (Xiaomi)

From: Chris Mason <[email protected]>

With MGLRU, reclaim that races with compaction for a folio can deadlock on the lruvec->lru_lock that it already holds.

isolate_folio() runs under the lru_lock. It takes a reference, and drops it again if another isolator has already cleared PG_lru. That folio_put() must not be the last one, since the free path takes the lru_lock if PG_lru is set. But compaction can release the lru_lock while the folio is still on the list with PG_lru clear. If the folio is truncated or unmapped meanwhile, the two isolators hold the only references:

    isolate_migratepages_block()  evict_folios()
    ============================  ==============
    folio_get_nontail_page()
    folio_test_clear_lru()
    goto isolate_abort
    lruvec_unlock_irqrestore()
                                  lruvec_lock_irq()
                                  isolate_folio()
                                    folio_try_get()
                                    folio_test_clear_lru() fails
    folio_set_lru()
    folio_put()
                                    folio_put()
                                      __page_cache_release()
                                        folio_lruvec_lock_irqsave()

The fix used here is to leave a folio alone if PG_lru is already clear, before a reference is taken, as isolate_lru_folios() does. An isolator that clears PG_lru after that test has to take the lru_lock before it drops its own reference.

Fixes ac35a4902374 ("mm: multi-gen LRU: minimal implementation")
[Kairui: Improved the comment]
---
 mm/vmscan.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/vmscan.c +9 -0
index 60c416819c57..5fb3055a4302 100644
@@ -4802,6 +4802,15 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca
 {
 	bool success;
 
+	/*
+	 * If PG_lru is set, the folio_put() below can't be the last one and
+	 * free the folio: whoever clears the flag keeps its reference until
+	 * it sets the flag again or takes the folio off the list, and it has
+	 * to take the lru_lock we hold before it can do either.
+	 */
+	if (!folio_test_lru(folio))
+		return false;
+
 	/* raced with release_pages() */
 	if (!folio_try_get(folio))
 		return false;
Signature · 1 line
2.39.3 (Apple Git-146)
author reviewer
#7 lore raw

PATCH 3/3 mm/mglru: report root reclaim to memory.pressure_level

In reply to Barry Song (Xiaomi)

From: Chris Mason <[email protected]>

With MGLRU enabled, memory.pressure_level listeners on the cgroup v1 root can miss global reclaim: kswapd sends them no events, and direct reclaim only "critical" ones.

On v1 the eventfds are only fed by vmpressure() calls with tree=true. shrink_node() makes that call after walking the memcgs, but it hands root reclaim to lru_gen_shrink_node() and returns first. The MGLRU walk only calls vmpressure() from shrink_one(), with tree=false, which has no consumer on v1. That leaves vmpressure_prio() in direct reclaim.

The fix used here is to make the same subtree report at the end of the MGLRU walk of a node.

Listeners for "medium" and "critical" can miss events they got before, since a vmpressure_prio() report is now averaged with the pages that the walk freed in the same window.

Fixes e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
---
 mm/vmscan.c | 6 ++++++
 1 file changed, 6 insertions(+)
mm/vmscan.c +6 -0
index 5fb3055a4302..99cb209797b4 100644
@@ -5511,6 +5511,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc
 static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc)
 {
 	struct blk_plug plug;
+	unsigned long scanned = sc->nr_scanned;
 	unsigned long reclaimed = sc->nr_reclaimed;
 
 	VM_WARN_ON_ONCE(!root_reclaim(sc));
@@ -5545,6 +5546,11 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *
 	clear_mm_walk();
 
 	blk_finish_plug(&plug);
+
+	/* Record the subtree's reclaim efficiency */
+	if (!sc->proactive)
+		vmpressure(sc->gfp_mask, sc->order, sc->target_mem_cgroup, true,
+			   sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed);
 done:
 	if (sc->nr_reclaimed > reclaimed)
 		kswapd_try_clear_hopeless(pgdat, sc->order, sc->reclaim_idx);
Signature · 1 line
2.39.3 (Apple Git-146)
maintainer tree notice
#2 lore raw

+ mm-mglru-count-all-generations-as-evictable.patch added to mm-new branch

In reply to Barry Song (Xiaomi)
The patch titled Subject: mm/mglru: count all generations as evictable has been added to the -mm mm-new branch. Its filename is mm-mglru-count-all-generations-as-evictable.patch

The patch titled
Subject: mm/mglru: count all generations as evictable
has been added to the -mm mm-new branch. Its filename is
mm-mglru-count-all-generations-as-evictable.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-count-all-generations-as-evictable.patch

This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next

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: Chris Mason <[email protected]>
Subject: mm/mglru: count all generations as evictable
Date: Sun, 29 Nov 2026 22:37:57 +0800

Patch series "mm/mglru: fix a few reclaim issues".

This series contains three MGLRU fixes originally proposed by Chris Mason and passed on to us by David Hildenbrand.

The issues addressed are:

1. Reparented folios becoming unreclaimable due to generation accounting falling outside the parent's [min_seq, max_seq] range.
2. A potential deadlock between reclaim and compaction when isolating folios.
3. Missing vmpressure notifications for global reclaim on cgroup v1.

Kairui and I have reviewed the fixes and made minor adjustments where necessary.

The series is based on mm-new.

This patch (of 3):

With MGLRU enabled, clean page cache that was reparented from a removed memory cgroup can stay unreclaimable for as long as the parent has no other evictable folios on the same node.

try_to_shrink_lruvec() derives its scan count from lruvec_evictable_size(), and with a count of 0 it runs neither eviction nor aging. lruvec_evictable_size() adds up nr_pages[] only for the generations from min_seq to max_seq. That sum is complete only if the count of a generation is 0 by the time min_seq advances past it.

But try_to_inc_min_seq() ignores the counts: it advances min_seq past a generation as soon as the lists of that generation are empty. A folio that folio_update_gen() promoted is counted in its new generation, but stays on the list of the generation that it came from. Normally min_seq stops at that list, before it reaches the new generation.

Reparenting moves each list and each count to the same index in the parent, where that index can stand for a different age:

    index (seq % MAX_NR_GENS)    0  1  2  3
    seq in the child             0  1  2  3
    seq in the parent            4  5  6  3
    folio F:  on folios[0], counted in nr_pages[3]
    child:    folios[0] holds min_seq at 0
    parent:   folios[3] is empty, so min_seq goes from 3 to 4
    sum:      nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F

The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations in lruvec_evictable_size().

[[email protected]: Rebased onto mm-new and added comments]
Fixes 163bc3d68c9f ("mm/mglru: restructure the reclaim loop")
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Qi Zheng <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Kairui Song <[email protected]>
Cc Axel Rasmussen <[email protected]>
Cc Yuanchu Xie <[email protected]>
Cc Wei Xu <[email protected]>
Cc Baoquan He <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Ridong Chen <[email protected]>
Cc Yu Zhao <[email protected]>
 mm/vmscan.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
mm/vmscan.c renamed from mm/vmscan.c~mm-mglru-count-all-generations-as-evictable +6 -3
@@ -4272,8 +4272,6 @@ static void lruvec_evictable_size(struct
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	struct mem_cgroup *memcg = lruvec_memcg(lruvec);
 	int nid = lruvec_pgdat(lruvec)->node_id;
-	DEFINE_MAX_SEQ(lruvec);
-	DEFINE_MIN_SEQ(lruvec);
 
 	nr[LRU_GEN_ANON] = 0;
 	nr[LRU_GEN_FILE] = 0;
@@ -4281,7 +4279,12 @@ static void lruvec_evictable_size(struct
 	for_each_evictable_type(type, swappiness) {
 		if (type == LRU_GEN_ANON && !can_reclaim_anon_pages(memcg, nid, sc))
 			continue;
-		for (seq = min_seq[type]; seq <= max_seq; seq++)
+		/*
+		 * Reparenting can leave folios accounted for in
+		 * generations outside [min_seq, max_seq]. Count
+		 * them as well to ensure reclaim makes progress.
+		 */
+		for (seq = 0; seq < MAX_NR_GENS; seq++)
 			nr[type] += lruvec_gen_size(lrugen, type, seq, max_zone);
 	}
 }

_

Patches currently in -mm which might be from [email protected] are

mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch

maintainer tree notice
#5 lore raw

+ mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch added to mm-new branch

In reply to Barry Song (Xiaomi)
The patch titled Subject: mm/mglru: test PG_lru before taking a folio reference has been added to the -mm mm-new branch. Its filename is mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch

The patch titled
Subject: mm/mglru: test PG_lru before taking a folio reference
has been added to the -mm mm-new branch. Its filename is
mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch

This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next

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: Chris Mason <[email protected]>
Subject: mm/mglru: test PG_lru before taking a folio reference
Date: Sun, 29 Nov 2026 22:37:58 +0800

With MGLRU, reclaim that races with compaction for a folio can deadlock on the lruvec->lru_lock that it already holds.

isolate_folio() runs under the lru_lock. It takes a reference, and drops it again if another isolator has already cleared PG_lru. That folio_put() must not be the last one, since the free path takes the lru_lock if PG_lru is set. But compaction can release the lru_lock while the folio is still on the list with PG_lru clear. If the folio is truncated or unmapped meanwhile, the two isolators hold the only references:

    isolate_migratepages_block()  evict_folios()
    ============================  ==============
    folio_get_nontail_page()
    folio_test_clear_lru()
    goto isolate_abort
    lruvec_unlock_irqrestore()
                                  lruvec_lock_irq()
                                  isolate_folio()
                                    folio_try_get()
                                    folio_test_clear_lru() fails
    folio_set_lru()
    folio_put()
                                    folio_put()
                                      __page_cache_release()
                                        folio_lruvec_lock_irqsave()

The fix used here is to leave a folio alone if PG_lru is already clear, before a reference is taken, as isolate_lru_folios() does. An isolator that clears PG_lru after that test has to take the lru_lock before it drops its own reference.

[[email protected]: Improved the comment]
Fixes ac35a4902374 ("mm: multi-gen LRU: minimal implementation")
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Qi Zheng <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Axel Rasmussen <[email protected]>
Cc Yuanchu Xie <[email protected]>
Cc Wei Xu <[email protected]>
Cc Baoquan He <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Ridong Chen <[email protected]>
Cc Yu Zhao <[email protected]>
 mm/vmscan.c |    9 +++++++++
 1 file changed, 9 insertions(+)
mm/vmscan.c renamed from mm/vmscan.c~mm-mglru-test-pg_lru-before-taking-a-folio-reference +9 -0
@@ -4802,6 +4802,15 @@ static bool isolate_folio(struct lruvec
 {
 	bool success;
 
+	/*
+	 * If PG_lru is set, the folio_put() below can't be the last one and
+	 * free the folio: whoever clears the flag keeps its reference until
+	 * it sets the flag again or takes the folio off the list, and it has
+	 * to take the lru_lock we hold before it can do either.
+	 */
+	if (!folio_test_lru(folio))
+		return false;
+
 	/* raced with release_pages() */
 	if (!folio_try_get(folio))
 		return false;

_

Patches currently in -mm which might be from [email protected] are

mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch

maintainer tree notice
#8 lore raw

+ mm-mglru-report-root-reclaim-to-memorypressure_level.patch added to mm-new branch

In reply to Barry Song (Xiaomi)
The patch titled Subject: mm/mglru: report root reclaim to memory.pressure_level has been added to the -mm mm-new branch. Its filename is mm-mglru-report-root-reclaim-to-memorypressure_level.patch

The patch titled
Subject: mm/mglru: report root reclaim to memory.pressure_level
has been added to the -mm mm-new branch. Its filename is
mm-mglru-report-root-reclaim-to-memorypressure_level.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mglru-report-root-reclaim-to-memorypressure_level.patch

This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next

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: Chris Mason <[email protected]>
Subject: mm/mglru: report root reclaim to memory.pressure_level
Date: Sun, 29 Nov 2026 22:37:59 +0800

With MGLRU enabled, memory.pressure_level listeners on the cgroup v1 root can miss global reclaim: kswapd sends them no events, and direct reclaim only "critical" ones.

On v1 the eventfds are only fed by vmpressure() calls with tree=true. shrink_node() makes that call after walking the memcgs, but it hands root reclaim to lru_gen_shrink_node() and returns first. The MGLRU walk only calls vmpressure() from shrink_one(), with tree=false, which has no consumer on v1. That leaves vmpressure_prio() in direct reclaim.

The fix used here is to make the same subtree report at the end of the MGLRU walk of a node.

Listeners for "medium" and "critical" can miss events they got before, since a vmpressure_prio() report is now averaged with the pages that the walk freed in the same window.

Fixes e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
Cc Johannes Weiner <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Qi Zheng <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Kairui Song <[email protected]>
Cc Axel Rasmussen <[email protected]>
Cc Yuanchu Xie <[email protected]>
Cc Wei Xu <[email protected]>
Cc Baoquan He <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Ridong Chen <[email protected]>
Cc Yu Zhao <[email protected]>
 mm/vmscan.c |    6 ++++++
 1 file changed, 6 insertions(+)
mm/vmscan.c renamed from mm/vmscan.c~mm-mglru-report-root-reclaim-to-memorypressure_level +6 -0
@@ -5511,6 +5511,7 @@ static void lru_gen_shrink_lruvec(struct
 static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *sc)
 {
 	struct blk_plug plug;
+	unsigned long scanned = sc->nr_scanned;
 	unsigned long reclaimed = sc->nr_reclaimed;
 
 	VM_WARN_ON_ONCE(!root_reclaim(sc));
@@ -5545,6 +5546,11 @@ static void lru_gen_shrink_node(struct p
 	clear_mm_walk();
 
 	blk_finish_plug(&plug);
+
+	/* Record the subtree's reclaim efficiency */
+	if (!sc->proactive)
+		vmpressure(sc->gfp_mask, sc->order, sc->target_mem_cgroup, true,
+			   sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed);
 done:
 	if (sc->nr_reclaimed > reclaimed)
 		kswapd_try_clear_hopeless(pgdat, sc->order, sc->reclaim_idx);

_

Patches currently in -mm which might be from [email protected] are

mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch

Acked-by on the v1 series
#9 lore raw
In reply to Barry Song (Xiaomi)
Quoted 17 lines · Barry Song (Xiaomi)

This series contains three MGLRU fixes originally proposed by Chris Mason and passed on to us by David Hildenbrand.

The issues addressed are:

1. Reparented folios becoming unreclaimable due to generation accounting falling outside the parent's [min_seq, max_seq] range.
2. A potential deadlock between reclaim and compaction when isolating folios.
3. Missing vmpressure notifications for global reclaim on cgroup v1.

Kairui and I have reviewed the fixes and made minor adjustments where necessary.

The series is based on mm-new.

Quoted 7 lines

Chris Mason (3):
mm/mglru: count all generations as evictable mm/mglru: test PG_lru before taking a folio reference mm/mglru: report root reclaim to memory.pressure_level

 mm/vmscan.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Thanks Barry!

These commits are valid bugfixes and in good shape, so:

reviewer Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] mm/mglru: count all generations as evictable

In reply to Barry Song (Xiaomi)
Quoted 33 lines · Barry Song (Xiaomi)

From: Chris Mason <[email protected]>

With MGLRU enabled, clean page cache that was reparented from a removed memory cgroup can stay unreclaimable for as long as the parent has no other evictable folios on the same node.

try_to_shrink_lruvec() derives its scan count from lruvec_evictable_size(), and with a count of 0 it runs neither eviction nor aging. lruvec_evictable_size() adds up nr_pages[] only for the generations from min_seq to max_seq. That sum is complete only if the count of a generation is 0 by the time min_seq advances past it.

But try_to_inc_min_seq() ignores the counts: it advances min_seq past a generation as soon as the lists of that generation are empty. A folio that folio_update_gen() promoted is counted in its new generation, but stays on the list of the generation that it came from. Normally min_seq stops at that list, before it reaches the new generation.

Reparenting moves each list and each count to the same index in the parent, where that index can stand for a different age:

     index (seq % MAX_NR_GENS)    0  1  2  3
     seq in the child             0  1  2  3
     seq in the parent            4  5  6  3
     folio F:  on folios[0], counted in nr_pages[3]
     child:    folios[0] holds min_seq at 0
     parent:   folios[3] is empty, so min_seq goes from 3 to 4
     sum:      nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F

The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations in lruvec_evictable_size().

Quoted 6 lines
Fixes 163bc3d68c9f ("mm/mglru: restructure the reclaim loop")
[Barry: Rebased onto mm-new and added comments]

---

LGTM.

reviewer Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] mm/mglru: test PG_lru before taking a folio reference

In reply to Barry Song (Xiaomi)
Quoted 34 lines · Barry Song (Xiaomi)

From: Chris Mason <[email protected]>

With MGLRU, reclaim that races with compaction for a folio can deadlock on the lruvec->lru_lock that it already holds.

isolate_folio() runs under the lru_lock. It takes a reference, and drops it again if another isolator has already cleared PG_lru. That folio_put() must not be the last one, since the free path takes the lru_lock if PG_lru is set. But compaction can release the lru_lock while the folio is still on the list with PG_lru clear. If the folio is truncated or unmapped meanwhile, the two isolators hold the only references:

     isolate_migratepages_block()  evict_folios()
     ============================  ==============
     folio_get_nontail_page()
     folio_test_clear_lru()
     goto isolate_abort
     lruvec_unlock_irqrestore()
                                   lruvec_lock_irq()
                                   isolate_folio()
                                     folio_try_get()
                                     folio_test_clear_lru() fails
     folio_set_lru()
     folio_put()
                                     folio_put()
                                       __page_cache_release()
                                         folio_lruvec_lock_irqsave()

The fix used here is to leave a folio alone if PG_lru is already clear, before a reference is taken, as isolate_lru_folios() does. An isolator that clears PG_lru after that test has to take the lru_lock before it drops its own reference.

Quoted 8 lines
Fixes ac35a4902374 ("mm: multi-gen LRU: minimal implementation")
[Kairui: Improved the comment]

---

LGTM.