linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Wei Yang <richard.weiyang@gmail.com>,
	Mel Gorman <mgorman@techsingularity.net>,
	Daero Lee <skseofh@gmail.com>
Subject: [PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep
Date: Sun, 23 Oct 2022 08:04:31 +0000	[thread overview]
Message-ID: <20221023080431.30893-1-richard.weiyang@gmail.com> (raw)

In function kswapd_try_to_sleep, there are two phases for kswapd to
sleep:

  * premature sleep
  * fully sleep

For each phase we need to check whether kswapd is fine to sleep.

While if it doesn't pass the check for first phase, it is not necessary
to do the check again.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Mel Gorman <mgorman@techsingularity.net>
CC: Daero Lee <skseofh@gmail.com>

---
The original thread is
https://lkml.kernel.org/lkml/20220106094650.GX3366@techsingularity.net/T/,
but seems no further following up.

So I pick it up.

Mel,

I just see your mail, sorry for the late reply :-(
---
 mm/vmscan.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 04d8b88e5216..5a50b5908c4c 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -7179,7 +7179,8 @@ static enum zone_type kswapd_highest_zoneidx(pg_data_t *pgdat,
 static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_order,
 				unsigned int highest_zoneidx)
 {
-	long remaining = 0;
+	long remaining;
+	bool can_sleep;
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
@@ -7194,7 +7195,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o
 	 * eligible zone balanced that it's also unlikely that compaction will
 	 * succeed.
 	 */
-	if (prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx)) {
+	can_sleep = prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx);
+	if (can_sleep) {
 		/*
 		 * Compaction records what page blocks it recently failed to
 		 * isolate pages from and skips them in the future scanning.
@@ -7223,6 +7225,10 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o
 
 			if (READ_ONCE(pgdat->kswapd_order) < reclaim_order)
 				WRITE_ONCE(pgdat->kswapd_order, reclaim_order);
+			can_sleep = false;
+		} else {
+			can_sleep = prepare_kswapd_sleep(pgdat, reclaim_order,
+							 highest_zoneidx);
 		}
 
 		finish_wait(&pgdat->kswapd_wait, &wait);
@@ -7230,11 +7236,11 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o
 	}
 
 	/*
-	 * After a short sleep, check if it was a premature sleep. If not, then
-	 * go fully to sleep until explicitly woken up.
+	 * If kswapd is fine to sleep, restore vmstat thresholds and kswapd
+	 * goes to sleep.
+	 * If not, account whether the low or high watermark was hit quickly.
 	 */
-	if (!remaining &&
-	    prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx)) {
+	if (can_sleep) {
 		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
 
 		/*
-- 
2.33.1



             reply	other threads:[~2022-10-23  8:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23  8:04 Wei Yang [this message]
2022-10-23 13:11 ` [PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep Wei Yang
2022-10-24  7:04 ` Dan Carpenter
2022-10-24  8:32   ` Wei Yang

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=20221023080431.30893-1-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=skseofh@gmail.com \
    /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).