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

Message ID 20240130091755.21363-1-gehao@kylinos.cn
State New
Headers
Series mm/vmscan: Change the calculation of the number of can reclaim anon pages in zone_reclaimable_pages |

Commit Message

Hao Ge Jan. 30, 2024, 9:17 a.m. UTC
  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@kylinos.cn>
---
 mm/vmscan.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
  

Patch

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;
 }
 
 /**