mm/vmscan: Change the calculation of the number of can reclaim anon pages in zone_reclaimable_pages
Commit Message
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(-)
@@ -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;
}
/**