[PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
CC: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx>
CC: Daero Lee <skseofh@xxxxxxxxx>

---
The original thread is
https://lkml.kernel.org/lkml/20220106094650.GX3366@xxxxxxxxxxxxxxxxxxx/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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux