kswapd: replace try_to_freeze() with kthread_freezable_should_stop()
authorLevi Yun <ppbuk5246@gmail.com>
Fri, 26 Jan 2024 15:25:54 +0000 (15:25 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 22 Feb 2024 18:24:41 +0000 (10:24 -0800)
Instead of using try_to_freeze, use kthread_freezable_should_stop in
kswapd.  By this, we can avoid unnecessary freezing when kswapd should
stop.

Link: https://lkml.kernel.org/r/20240126152556.58791-1-ppbuk5246@gmail.com
Signed-off-by: Levi Yun <ppbuk5246@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/vmscan.c

index 4f9c854ce6cc66c2d971767a8f00e51eeab8a65e..1f139830b26f6cf8c21ae408550fdfe4b6a7dfbb 100644 (file)
@@ -6796,6 +6796,7 @@ restart:
                bool raise_priority = true;
                bool balanced;
                bool ret;
+               bool was_frozen;
 
                sc.reclaim_idx = highest_zoneidx;
 
@@ -6894,9 +6895,9 @@ restart:
 
                /* Check if kswapd should be suspending */
                __fs_reclaim_release(_THIS_IP_);
-               ret = try_to_freeze();
+               ret = kthread_freezable_should_stop(&was_frozen);
                __fs_reclaim_acquire(_THIS_IP_);
-               if (ret || kthread_should_stop())
+               if (was_frozen || ret)
                        break;
 
                /*
@@ -7102,7 +7103,7 @@ static int kswapd(void *p)
        WRITE_ONCE(pgdat->kswapd_highest_zoneidx, MAX_NR_ZONES);
        atomic_set(&pgdat->nr_writeback_throttled, 0);
        for ( ; ; ) {
-               bool ret;
+               bool was_frozen;
 
                alloc_order = reclaim_order = READ_ONCE(pgdat->kswapd_order);
                highest_zoneidx = kswapd_highest_zoneidx(pgdat,
@@ -7119,15 +7120,14 @@ kswapd_try_sleep:
                WRITE_ONCE(pgdat->kswapd_order, 0);
                WRITE_ONCE(pgdat->kswapd_highest_zoneidx, MAX_NR_ZONES);
 
-               ret = try_to_freeze();
-               if (kthread_should_stop())
+               if (kthread_freezable_should_stop(&was_frozen))
                        break;
 
                /*
                 * We can speed up thawing tasks if we don't call balance_pgdat
                 * after returning from the refrigerator
                 */
-               if (ret)
+               if (was_frozen)
                        continue;
 
                /*