linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hao Ge <gehao@kylinos.cn>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Hao Ge <gehao@kylinos.cn>
Subject: [PATCH] mm/vmscan: Change the calculation of the number of can reclaim anon pages in zone_reclaimable_pages
Date: Tue, 30 Jan 2024 17:17:55 +0800	[thread overview]
Message-ID: <20240130091755.21363-1-gehao@kylinos.cn> (raw)

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(-)

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



                 reply	other threads:[~2024-01-30  9:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240130091755.21363-1-gehao@kylinos.cn \
    --to=gehao@kylinos.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).