[PATCH V3] writeback: Fix wakeup and logging timeouts for !DETECT_HUNG_TASK

Huacai Chen posted 1 patch 5 days, 5 hours ago
fs/fs-writeback.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH V3] writeback: Fix wakeup and logging timeouts for !DETECT_HUNG_TASK
Posted by Huacai Chen 5 days, 5 hours ago
Recent changes of fs-writeback cause such warnings if DETECT_HUNG_TASK
is not enabled:

INFO: The task sync:1342 has been waiting for writeback completion for more than 1 seconds.

The reason is sysctl_hung_task_timeout_secs is 0 when DETECT_HUNG_TASK
is not enabled, then it causes the warning message even if the writeback
lasts for only one second.

Guard the wakeup and logging with "#ifdef CONFIG_DETECT_HUNG_TASK" can
eliminate the warning messages. But on the other hand, it is possible
that sysctl_hung_task_timeout_secs be also 0 when DETECT_HUNG_TASK is
enabled. So let's just check the value of sysctl_hung_task_timeout_secs
to decide whether do wakeup and logging.

Fixes: 1888635532fb ("writeback: Wake up waiting tasks when finishing the writeback of a chunk.")
Fixes: d6e621590764 ("writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)")
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
V2: Disable wakeup and logging for !DETECT_HUNG_TASK.
V3: Also handle the case for DETECT_HUNG_TASK if sysctl_hung_task_timeout_secs is 0.

 fs/fs-writeback.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 5444fc706ac7..79b02ac66ac6 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -198,10 +198,11 @@ static void wb_queue_work(struct bdi_writeback *wb,
 
 static bool wb_wait_for_completion_cb(struct wb_completion *done)
 {
+	unsigned long timeout = sysctl_hung_task_timeout_secs;
 	unsigned long waited_secs = (jiffies - done->wait_start) / HZ;
 
 	done->progress_stamp = jiffies;
-	if (waited_secs > sysctl_hung_task_timeout_secs)
+	if (timeout && (waited_secs > timeout))
 		pr_info("INFO: The task %s:%d has been waiting for writeback "
 			"completion for more than %lu seconds.",
 			current->comm, current->pid, waited_secs);
@@ -1944,6 +1945,7 @@ static long writeback_sb_inodes(struct super_block *sb,
 		.range_end		= LLONG_MAX,
 	};
 	unsigned long start_time = jiffies;
+	unsigned long timeout = sysctl_hung_task_timeout_secs;
 	long write_chunk;
 	long total_wrote = 0;  /* count both pages and inodes */
 	unsigned long dirtied_before = jiffies;
@@ -2030,9 +2032,8 @@ static long writeback_sb_inodes(struct super_block *sb,
 		__writeback_single_inode(inode, &wbc);
 
 		/* Report progress to inform the hung task detector of the progress. */
-		if (work->done && work->done->progress_stamp &&
-		   (jiffies - work->done->progress_stamp) > HZ *
-		   sysctl_hung_task_timeout_secs / 2)
+		if (work->done && work->done->progress_stamp && timeout &&
+		   (jiffies - work->done->progress_stamp) > HZ * timeout / 2)
 			wake_up_all(work->done->waitq);
 
 		wbc_detach_inode(&wbc);
-- 
2.47.3
Re: [PATCH V3] writeback: Fix wakeup and logging timeouts for !DETECT_HUNG_TASK
Posted by Pankaj Raghav (Samsung) 5 days ago
On Tue, Feb 03, 2026 at 05:40:14PM +0800, Huacai Chen wrote:
> Recent changes of fs-writeback cause such warnings if DETECT_HUNG_TASK
> is not enabled:
> 
> INFO: The task sync:1342 has been waiting for writeback completion for more than 1 seconds.
> 
> The reason is sysctl_hung_task_timeout_secs is 0 when DETECT_HUNG_TASK
> is not enabled, then it causes the warning message even if the writeback
> lasts for only one second.
> 
> Guard the wakeup and logging with "#ifdef CONFIG_DETECT_HUNG_TASK" can
> eliminate the warning messages. But on the other hand, it is possible
> that sysctl_hung_task_timeout_secs be also 0 when DETECT_HUNG_TASK is
> enabled. So let's just check the value of sysctl_hung_task_timeout_secs
> to decide whether do wakeup and logging.
> 
> Fixes: 1888635532fb ("writeback: Wake up waiting tasks when finishing the writeback of a chunk.")
> Fixes: d6e621590764 ("writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)")
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> V2: Disable wakeup and logging for !DETECT_HUNG_TASK.
> V3: Also handle the case for DETECT_HUNG_TASK if sysctl_hung_task_timeout_secs is 0.

Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
-- 
Pankaj
Re: [PATCH V3] writeback: Fix wakeup and logging timeouts for !DETECT_HUNG_TASK
Posted by Jan Kara 5 days, 4 hours ago
On Tue 03-02-26 17:40:14, Huacai Chen wrote:
> Recent changes of fs-writeback cause such warnings if DETECT_HUNG_TASK
> is not enabled:
> 
> INFO: The task sync:1342 has been waiting for writeback completion for more than 1 seconds.
> 
> The reason is sysctl_hung_task_timeout_secs is 0 when DETECT_HUNG_TASK
> is not enabled, then it causes the warning message even if the writeback
> lasts for only one second.
> 
> Guard the wakeup and logging with "#ifdef CONFIG_DETECT_HUNG_TASK" can
> eliminate the warning messages. But on the other hand, it is possible
> that sysctl_hung_task_timeout_secs be also 0 when DETECT_HUNG_TASK is
> enabled. So let's just check the value of sysctl_hung_task_timeout_secs
> to decide whether do wakeup and logging.
> 
> Fixes: 1888635532fb ("writeback: Wake up waiting tasks when finishing the writeback of a chunk.")
> Fixes: d6e621590764 ("writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)")
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

> ---
> V2: Disable wakeup and logging for !DETECT_HUNG_TASK.
> V3: Also handle the case for DETECT_HUNG_TASK if sysctl_hung_task_timeout_secs is 0.

Good catch!

								Honza

> 
>  fs/fs-writeback.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
> index 5444fc706ac7..79b02ac66ac6 100644
> --- a/fs/fs-writeback.c
> +++ b/fs/fs-writeback.c
> @@ -198,10 +198,11 @@ static void wb_queue_work(struct bdi_writeback *wb,
>  
>  static bool wb_wait_for_completion_cb(struct wb_completion *done)
>  {
> +	unsigned long timeout = sysctl_hung_task_timeout_secs;
>  	unsigned long waited_secs = (jiffies - done->wait_start) / HZ;
>  
>  	done->progress_stamp = jiffies;
> -	if (waited_secs > sysctl_hung_task_timeout_secs)
> +	if (timeout && (waited_secs > timeout))
>  		pr_info("INFO: The task %s:%d has been waiting for writeback "
>  			"completion for more than %lu seconds.",
>  			current->comm, current->pid, waited_secs);
> @@ -1944,6 +1945,7 @@ static long writeback_sb_inodes(struct super_block *sb,
>  		.range_end		= LLONG_MAX,
>  	};
>  	unsigned long start_time = jiffies;
> +	unsigned long timeout = sysctl_hung_task_timeout_secs;
>  	long write_chunk;
>  	long total_wrote = 0;  /* count both pages and inodes */
>  	unsigned long dirtied_before = jiffies;
> @@ -2030,9 +2032,8 @@ static long writeback_sb_inodes(struct super_block *sb,
>  		__writeback_single_inode(inode, &wbc);
>  
>  		/* Report progress to inform the hung task detector of the progress. */
> -		if (work->done && work->done->progress_stamp &&
> -		   (jiffies - work->done->progress_stamp) > HZ *
> -		   sysctl_hung_task_timeout_secs / 2)
> +		if (work->done && work->done->progress_stamp && timeout &&
> +		   (jiffies - work->done->progress_stamp) > HZ * timeout / 2)
>  			wake_up_all(work->done->waitq);
>  
>  		wbc_detach_inode(&wbc);
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR