gfs2: Add missing set_freezable() for freezable kthread
PATCH 1/2 gfs2: Add missing set_freezable() for freezable kthread
The kernel thread function gfs2_logd() and gfs2_quotad() invoke the try_to_freeze() in its loop. But all the kernel threads are no-freezable by default. So if we want to make a kernel thread to be freezable, we have to invoke set_freezable() explicitly.
--- fs/gfs2/log.c | 1 + fs/gfs2/quota.c | 1 + 2 files changed, 2 insertions(+)
fs/gfs2/log.c +1 -0
@@ -1297,6 +1297,7 @@ int gfs2_logd(void *data)struct gfs2_sbd *sdp = data;unsigned long t =1 ; +set_freezable ();while (!kthread_should_stop ()) {if (gfs2_withdrawn (sdp))break ;
fs/gfs2/quota.c +1 -0
@@ -1583,6 +1583,7 @@ int gfs2_quotad(void *data)unsigned long quotad_timeo =0 ;unsigned long t =0 ; +set_freezable ();while (!kthread_should_stop ()) {if (gfs2_withdrawn (sdp))break ;
Signature · 1 line
2.39.2
PATCH 2/2 gfs2: Use wait_event_freezable_timeout() for freezable kthread
A freezable kernel thread can enter frozen state during freezing by either calling try_to_freeze() or using wait_event_freezable() and its variants. So for the following snippet of code in a kernel thread loop:
try_to_freeze();
wait_event_interruptible_timeout();
We can change it to a simple wait_event_freezable_timeout() and then eliminate a function call.
--- fs/gfs2/log.c | 4 +--- fs/gfs2/quota.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
fs/gfs2/log.c +1 -3
@@ -1331,9 +1331,7 @@ int gfs2_logd(void *data) t =gfs2_tune_get (sdp, gt_logd_secs) *HZ ; -try_to_freeze (); - - t = wait_event_interruptible_timeout(sdp->sd_logd_waitq, + t = wait_event_freezable_timeout(sdp->sd_logd_waitq, test_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags) || gfs2_ail_flush_reqd(sdp) || gfs2_jrnl_flush_reqd(sdp) ||
fs/gfs2/quota.c +1 -3
@@ -1603,11 +1603,9 @@ int gfs2_quotad(void *data)quotad_check_timeo (sdp,"sync" , gfs2_quota_sync, t, "ad_timeo, &tune->gt_quota_quantum); -try_to_freeze (); - t =min (quotad_timeo, statfs_timeo); - t = wait_event_interruptible_timeout(sdp->sd_quota_wait, + t = wait_event_freezable_timeout(sdp->sd_quota_wait, sdp->sd_statfs_force_sync || gfs2_withdrawn(sdp) || kthread_should_stop(),
Signature · 1 line
2.39.2
Andreas Gruenbacher
maintainerRe: [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() for freezable kthread
Kevin,
Quoted 48 lines · Kevin Hao
A freezable kernel thread can enter frozen state during freezing by either calling
try_to_freeze()or usingwait_event_freezable()and its variants. So for the following snippet of code in a kernel thread loop:
try_to_freeze();
wait_event_interruptible_timeout();We can change it to a simple
wait_event_freezable_timeout()and then eliminate a function call.Signed-off-by Kevin Hao <[email protected]>--- fs/gfs2/log.c | 4 +--- fs/gfs2/quota.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)fs/gfs2/log.c +1
-3@@ -1331,9 +1331,7 @@ int gfs2_logd(void *data) t =gfs2_tune_get (sdp, gt_logd_secs) *HZ ; -try_to_freeze (); - - t = wait_event_interruptible_timeout(sdp->sd_logd_waitq, + t = wait_event_freezable_timeout(sdp->sd_logd_waitq, test_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags) || gfs2_ail_flush_reqd(sdp) || gfs2_jrnl_flush_reqd(sdp) ||fs/gfs2/quota.c +1
-4@@ -1603,11 +1603,9 @@ int gfs2_quotad(void *data)quotad_check_timeo (sdp,"sync" , gfs2_quota_sync, t, "ad_timeo, &tune->gt_quota_quantum); -try_to_freeze (); - t =min (quotad_timeo, statfs_timeo); - t = wait_event_interruptible_timeout(sdp->sd_quota_wait, + t = wait_event_freezable_timeout(sdp->sd_quota_wait, sdp->sd_statfs_force_sync || gfs2_withdrawn(sdp) || kthread_should_stop(), --
Quoted 2 lines
2.39.2
This also is looking good; applied as well.
Thank you,
Andreas
Andreas Gruenbacher
maintainerKevin,
Quoted 36 lines · Kevin Hao
The kernel thread function
gfs2_logd()andgfs2_quotad()invoke thetry_to_freeze()in its loop. But all the kernel threads are no-freezable by default. So if we want to make a kernel thread to be freezable, we have to invokeset_freezable()explicitly.Signed-off-by Kevin Hao <[email protected]>--- fs/gfs2/log.c | 1 + fs/gfs2/quota.c | 1 + 2 files changed, 2 insertions(+)fs/gfs2/log.c +1
-0@@ -1297,6 +1297,7 @@ int gfs2_logd(void *data)struct gfs2_sbd *sdp = data;unsigned long t =1 ; +set_freezable ();while (!kthread_should_stop ()) {if (gfs2_withdrawn (sdp))break ;fs/gfs2/quota.c +1
-1@@ -1583,6 +1583,7 @@ int gfs2_quotad(void *data)unsigned long quotad_timeo =0 ;unsigned long t =0 ; +set_freezable ();while (!kthread_should_stop ()) {if (gfs2_withdrawn (sdp))break ; --
Quoted 2 lines
2.39.2
This is looking good, thank you. I've applied it to our for-next branch.
Andreas