* [PATCH 1/2] gfs2: Add missing set_freezable() for freezable kthread
@ 2023-12-18 5:35 Kevin Hao
2023-12-18 5:35 ` [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() " Kevin Hao
2023-12-21 14:10 ` [PATCH 1/2] gfs2: Add missing set_freezable() " Andreas Gruenbacher
0 siblings, 2 replies; 4+ messages in thread
From: Kevin Hao @ 2023-12-18 5:35 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: gfs2, Rafael J. Wysocki, Pavel Machek
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.
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
fs/gfs2/log.c | 1 +
fs/gfs2/quota.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index e5271ae87d1c..a268b69bb636 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -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;
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index fa47824acf13..173581736a6e 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -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;
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() for freezable kthread
2023-12-18 5:35 [PATCH 1/2] gfs2: Add missing set_freezable() for freezable kthread Kevin Hao
@ 2023-12-18 5:35 ` Kevin Hao
2023-12-21 14:11 ` Andreas Gruenbacher
2023-12-21 14:10 ` [PATCH 1/2] gfs2: Add missing set_freezable() " Andreas Gruenbacher
1 sibling, 1 reply; 4+ messages in thread
From: Kevin Hao @ 2023-12-18 5:35 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: gfs2, Rafael J. Wysocki, Pavel Machek
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.
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
fs/gfs2/log.c | 4 +---
fs/gfs2/quota.c | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index a268b69bb636..20059fc913e7 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -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) ||
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 173581736a6e..05ef8409b614 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -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(),
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] gfs2: Add missing set_freezable() for freezable kthread
2023-12-18 5:35 [PATCH 1/2] gfs2: Add missing set_freezable() for freezable kthread Kevin Hao
2023-12-18 5:35 ` [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() " Kevin Hao
@ 2023-12-21 14:10 ` Andreas Gruenbacher
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2023-12-21 14:10 UTC (permalink / raw)
To: Kevin Hao; +Cc: gfs2, Rafael J. Wysocki, Pavel Machek
Kevin,
On Mon, Dec 18, 2023 at 6:36 AM Kevin Hao <haokexin@gmail.com> wrote:
> 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.
>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
> fs/gfs2/log.c | 1 +
> fs/gfs2/quota.c | 1 +
> 2 files changed, 2 insertions(+)
>
> diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
> index e5271ae87d1c..a268b69bb636 100644
> --- a/fs/gfs2/log.c
> +++ b/fs/gfs2/log.c
> @@ -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;
> diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
> index fa47824acf13..173581736a6e 100644
> --- a/fs/gfs2/quota.c
> +++ b/fs/gfs2/quota.c
> @@ -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;
> --
> 2.39.2
>
This is looking good, thank you. I've applied it to our for-next branch.
Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() for freezable kthread
2023-12-18 5:35 ` [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() " Kevin Hao
@ 2023-12-21 14:11 ` Andreas Gruenbacher
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2023-12-21 14:11 UTC (permalink / raw)
To: Kevin Hao; +Cc: gfs2, Rafael J. Wysocki, Pavel Machek
Kevin,
On Mon, Dec 18, 2023 at 6:36 AM Kevin Hao <haokexin@gmail.com> wrote:
> 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.
>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
> fs/gfs2/log.c | 4 +---
> fs/gfs2/quota.c | 4 +---
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
> index a268b69bb636..20059fc913e7 100644
> --- a/fs/gfs2/log.c
> +++ b/fs/gfs2/log.c
> @@ -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) ||
> diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
> index 173581736a6e..05ef8409b614 100644
> --- a/fs/gfs2/quota.c
> +++ b/fs/gfs2/quota.c
> @@ -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(),
> --
> 2.39.2
>
This also is looking good; applied as well.
Thank you,
Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-21 14:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-18 5:35 [PATCH 1/2] gfs2: Add missing set_freezable() for freezable kthread Kevin Hao
2023-12-18 5:35 ` [PATCH 2/2] gfs2: Use wait_event_freezable_timeout() " Kevin Hao
2023-12-21 14:11 ` Andreas Gruenbacher
2023-12-21 14:10 ` [PATCH 1/2] gfs2: Add missing set_freezable() " Andreas Gruenbacher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox