[PATCH] mm/vmscan: Change the calculation of the number of can reclaim anon pages in zone_reclaimable_pages

From: Hao Ge
Date: Tue Jan 30 2024 - 04:24:54 EST


The spaces of swap devices that can be set by the user
are unpredictable values, so we take the minimum value between
the anonymous page in the specified zone and the spaces of swap devices.

Signed-off-by: Hao Ge <gehao@xxxxxxxxxx>
---
mm/vmscan.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 4f9c854ce6cc..2deae4232b83 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -341,14 +341,21 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg,
unsigned long zone_reclaimable_pages(struct zone *zone)
{
unsigned long nr;
-
+ unsigned long can_reclaim_anon = 0;
nr = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_FILE) +
zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_FILE);
- if (can_reclaim_anon_pages(NULL, zone_to_nid(zone), NULL))
- nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) +
+ if (can_reclaim_anon_pages(NULL, zone_to_nid(zone), NULL)) {
+ can_reclaim_anon = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) +
zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON);
-
- return nr;
+ /*
+ * The spaces of swap devices that can be set by the user are unpredictable values,
+ * so we take the minimum value between the anonymous page in the specified zone and
+ * the spaces of swap devices
+ */
+ if (!can_demote(zone_to_nid(zone), NULL))
+ can_reclaim_anon = min_t(unsigned long, can_reclaim_anon, get_nr_swap_pages());
+ }
+ return nr + can_reclaim_anon;
}

/**
--
2.25.1