Skip to contentSkip to conversation

kswapd: Replace try_to_freeze to kthread_freezable_should_stop.

PATCH Applied Levi Yun 2 participants 3 messages Jan 26, 2024 – May 4, 2024

Subsystems (4)
lore
Share & tools
lore

Levi Yun

author
#0 lore raw

PATCH 1/1 kswapd: Replace try_to_freeze to kthread_freezable_should_stop.

Instead of using try_to_freeze, use kthread_freezable_should_stop in kswapd.
By this, we can avoid unnecessary freezing when kswapd should stop.

---
 mm/vmscan.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/vmscan.c +6 -6
index 4f9c854ce6cc..1f139830b26f 100644
@@ -6796,6 +6796,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
 		bool raise_priority = true;
 		bool balanced;
 		bool ret;
+		bool was_frozen;
 
 		sc.reclaim_idx = highest_zoneidx;
 
@@ -6894,9 +6895,9 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
 
 		/* 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 @@ static int kswapd(void *p)
 		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;
 
 		/*

--
2.39.2

author
#1 lore raw

Gentle ping.

Quoted 63 lines · Levi Yun

Instead of using try_to_freeze, use kthread_freezable_should_stop in kswapd.
By this, we can avoid unnecessary freezing when kswapd should stop.

---
 mm/vmscan.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/vmscan.c +6 -7
index 4f9c854ce6cc..1f139830b26f 100644
@@ -6796,6 +6796,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
                bool raise_priority = true;
                bool balanced;
                bool ret;
+               bool was_frozen;
 
                sc.reclaim_idx = highest_zoneidx;
 
@@ -6894,9 +6895,9 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
 
                /* 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 @@ static int kswapd(void *p)
                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;
 
                /*
--

2.39.2

#2 lore raw
In reply to Levi Yun

Will an adjustment become relevant for the summary phrase? Would you like to append parentheses to mentioned function names?

Quoted 3 lines

Instead of using try_to_freeze, use kthread_freezable_should_stop in kswapd.
By this, we can avoid unnecessary freezing when kswapd should stop.

How do you think about to add the tag “Fixes”?

Regards,
Markus