Skip to contentSkip to conversation

19999e479c2a ("mm: remove '!root_reclaim' checking in should_abort_scan()") for 6.12.y and 6.18.y

STABLE REQUEST New Eric Hagberg 2 participants 3 messages Nov 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

Please consider commit 19999e479c2a ("mm: remove '!root_reclaim' checking in should_abort_scan()") for 6.12.y and 6.18.y. The commit was merged for v7.1-rc1.

With MGLRU enabled, memcg (non-root) reclaim never bails out once nr_to_reclaim is met, so reclaim against memory.max/memory.high can over-reclaim by a large factor. That scales with lruvec size and hierarchy depth. On some large-memory machines this causes cgroup-limited workloads to fail under memory pressure. Disabling MGLRU avoids it, and applying this commit fixes a reproducer with MGLRU enabled.

The check being removed was needed for fairness before b82b530740b9 ("mm: vmscan: restore incremental cgroup iteration"), which landed in v6.11. Both 6.12.y and 6.18.y contain b82b530740b9, and the patch applies cleanly. It should NOT go to older stable branches that lack b82b530740b9.

Thanks,
Eric Hagberg

#1 lore raw

PATCH 1/1 mm: remove '!root_reclaim' checking in should_abort_scan()

From: Zhaoyang Huang <[email protected]>

[ Upstream commit 19999e479c2a38672789e66b4830f43c645ca1f2 ]

Android systems usually use memory.reclaim interface to implement user space memory management which expects that the requested reclaim target and actually reclaimed amount memory are not diverging by too much. With the current MGRLU implementation there is, however, no bail out when the reclaim target is reached and this could lead to an excessive reclaim that scales with the reclaim hierarchy size.For example, we can get a nr_reclaimed=394/nr_to_reclaim=32 proactive reclaim under a common 1-N cgroup hierarchy.

This defect arose from the goal of keeping fairness among memcgs that is, for try_to_free_mem_cgroup_pages -> shrink_node_memcgs -> shrink_lruvec -> lru_gen_shrink_lruvec -> try_to_shrink_lruvec, the !root_reclaim(sc) check was there for reclaim fairness, which was necessary before commit b82b530740b9 ("mm: vmscan: restore incremental cgroup iteration") because the fairness depended on attempted proportional reclaim from every memcg under the target memcg. However after commit b82b530740b9 there is no longer a need to visit every memcg to ensure fairness. Let's have try_to_shrink_lruvec bail out when the nr_reclaimed achieved.

---
 mm/vmscan.c | 4 ----
 1 file changed, 4 deletions(-)
mm/vmscan.c +0 -4
index f9b5fbd072db..333e3c800e78 100644
@@ -4752,10 +4752,6 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)
 	int i;
 	enum zone_watermarks mark;
 
-	/* don't abort memcg reclaim to ensure fairness */
-	if (!root_reclaim(sc))
-		return false;
-
 	if (sc->nr_reclaimed >= max(sc->nr_to_reclaim, compact_gap(sc->order)))
 		return true;
 
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
#2 lore raw

PATCH 1/1 mm: remove '!root_reclaim' checking in should_abort_scan()

In reply to Eric Hagberg

From: Zhaoyang Huang <[email protected]>

[ Upstream commit 19999e479c2a38672789e66b4830f43c645ca1f2 ]

Android systems usually use memory.reclaim interface to implement user space memory management which expects that the requested reclaim target and actually reclaimed amount memory are not diverging by too much. With the current MGRLU implementation there is, however, no bail out when the reclaim target is reached and this could lead to an excessive reclaim that scales with the reclaim hierarchy size.For example, we can get a nr_reclaimed=394/nr_to_reclaim=32 proactive reclaim under a common 1-N cgroup hierarchy.

This defect arose from the goal of keeping fairness among memcgs that is, for try_to_free_mem_cgroup_pages -> shrink_node_memcgs -> shrink_lruvec -> lru_gen_shrink_lruvec -> try_to_shrink_lruvec, the !root_reclaim(sc) check was there for reclaim fairness, which was necessary before commit b82b530740b9 ("mm: vmscan: restore incremental cgroup iteration") because the fairness depended on attempted proportional reclaim from every memcg under the target memcg. However after commit b82b530740b9 there is no longer a need to visit every memcg to ensure fairness. Let's have try_to_shrink_lruvec bail out when the nr_reclaimed achieved.

---
 mm/vmscan.c | 4 ----
 1 file changed, 4 deletions(-)
mm/vmscan.c +0 -4
index 2c66fbcd6e84..160481706b42 100644
@@ -4844,10 +4844,6 @@ static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc)
 	int i;
 	enum zone_watermarks mark;
 
-	/* don't abort memcg reclaim to ensure fairness */
-	if (!root_reclaim(sc))
-		return false;
-
 	if (sc->nr_reclaimed >= max(sc->nr_to_reclaim, compact_gap(sc->order)))
 		return true;
 
Signature · 1 line
2.56.0.455.g6c5a503b38-goog