linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep
@ 2022-10-23  8:04 Wei Yang
  2022-10-23 13:11 ` Wei Yang
  2022-10-24  7:04 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Wei Yang @ 2022-10-23  8:04 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, Wei Yang, Mel Gorman, Daero Lee

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-24  8:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-23  8:04 [PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep Wei Yang
2022-10-23 13:11 ` Wei Yang
2022-10-24  7:04 ` Dan Carpenter
2022-10-24  8:32   ` Wei Yang

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