[RFC PATCH v5 06/14] mm/mglru: return for unavailable anon reclaim earlier
From: Barry Song (Xiaomi)
Date: Thu Oct 22 2026 - 18:03:01 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
No feature change, just shuffle some code, prepare for later commits.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
---
mm/vmscan.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index d3caed8aa789..0930bee5906e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5215,20 +5215,6 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,
struct mem_cgroup *memcg, int swappiness)
{
unsigned long nr_to_scan, evictable, sizes[ANON_AND_FILE];
- struct pglist_data *pgdat = lruvec_pgdat(lruvec);
-
- /*
- * Proactive reclaim initiated by userspace for anonymous memory only.
- * SWAPPINESS_ANON_ONLY is set only on the proactive reclaim path, so
- * warn if it shows up elsewhere. When anon cannot be reclaimed (e.g.
- * no swap), return 0 to skip the scan entirely, avoiding useless scan
- * work when there is nothing eligible to reclaim.
- */
- if (swappiness == SWAPPINESS_ANON_ONLY) {
- WARN_ON_ONCE(!sc->proactive);
- if (!can_reclaim_anon_pages(memcg, pgdat->node_id, sc))
- return 0;
- }
lruvec_evictable_size(lruvec, swappiness, sizes);
evictable = sizes[LRU_GEN_ANON] + sizes[LRU_GEN_FILE];
@@ -5285,6 +5271,19 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
int swappiness = get_swappiness(lruvec, sc);
struct mem_cgroup *memcg = lruvec_memcg(lruvec);
+ /*
+ * Proactive reclaim initiated by userspace for anonymous memory only.
+ * SWAPPINESS_ANON_ONLY is set only on the proactive reclaim path, so
+ * warn if it shows up elsewhere. When anon cannot be reclaimed (e.g.
+ * no swap), return 0 to skip the scan entirely, avoiding useless scan
+ * work when there is nothing eligible to reclaim.
+ */
+ if (swappiness == SWAPPINESS_ANON_ONLY) {
+ WARN_ON_ONCE(!sc->proactive);
+ if (!can_reclaim_anon_pages(memcg, lruvec_pgdat(lruvec)->node_id, sc))
+ return false;
+ }
+
nr_to_scan = get_nr_to_scan(lruvec, sc, memcg, swappiness);
while (nr_to_scan > 0) {
int delta;
--
2.34.1