writeback: make slow writeback report more actionable
Subsystems (5)
v2 cover writeback: make slow writeback report more actionable
Since v6.19, writeback waiters are woken while their writeback makes progress, so a slow sync no longer trips the hung task detector. Instead, a waiter past hung_task_timeout_secs logs:
INFO: The task sync:180 has been waiting for writeback completion for more than 28 seconds.
Across the Meta fleet, this line is logged about 19,000 times a day (the median over 40 days), and up to 82,000 times on a busy day.
Over one day, 194 hosts logged 16,858 of these lines for only about 2,000 waits, half of them longer than 160 seconds. Most reports were printed twice, and a wait logged a median of 7 lines.
Going through these reports, a few things made them hard to use and quickly act on:
1. The message has no trailing newline, so it only shows up once the next message is logged. Patch 1 fixes that, for stable.
2. It does not say which device is slow. Patch 2 adds the bdi and the number of work items left.
3. The end of the wait is logged as one more "has been waiting" line. Patch 3 logs the total wait instead.
4. It is printed every half timeout, often twice. Patch 4 wakes the waiter and prints it once per timeout.
With the series, a sync of files dirtied from two cgroups, on a null_blk device throttled to 4 MB/s and with hung_task_timeout_secs set to 5, logs:
[ 9.262814] INFO: The task sync:276 has been waiting for writeback completion for more than 5 seconds (bdi 252:0, work items left: 2). [ 14.683024] INFO: The task sync:276 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2). [ 20.103027] INFO: The task sync:276 has been waiting for writeback completion for more than 16 seconds (bdi 252:0, work items left: 2). [ 25.222884] INFO: The task sync:276 has been waiting for writeback completion for more than 21 seconds (bdi 252:0, work items left: 2). [ 30.542836] INFO: The task sync:276 has been waiting for writeback completion for more than 26 seconds (bdi 252:0, work items left: 2). [ 33.562975] The task sync:276 waited 29 seconds for writeback completion on bdi 252:0
Without patch 4, the same test logs 18 reports.
---
Changes in v2:
- Print the bdi and the work items left on the report line itself (Jan)
- Patch 4: wake the waiter once per timeout instead of adding
report_stamp (Jan); its changelog shows the hung task warnings that
this can bring back
- Patch 4: the doubled reports come from wait_event() checking the
condition twice per wakeup, not from the two flushers
- Collect Jan's Reviewed-by on patches 1 and 3 (patch 3 rebased on the
one-line report)
- Link to v1: https://patch.msgid.link/[email protected]
---
Breno Leitao (4):
writeback: add the missing newline to the slow writeback report
writeback: name the bdi in the slow writeback report
writeback: log the end of a slow writeback wait
writeback: report a slow writeback wait once per timeout
fs/fs-writeback.c | 40 ++++++++++++++++++++++++++++------------ include/linux/backing-dev.h | 3 ++- mm/memcontrol.c | 2 +- 3 files changed, 31 insertions(+), 14 deletions(-)
---
base-commit: 8b7179210b22f8e48a82c5ceacb9d56a9c4cfec4
change-id: 20261105-writeback_stall_report-170750a69946
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH v2 1/4 writeback: add the missing newline to the slow writeback report
wb_wait_for_completion_cb() reports a writeback wait that exceeds hung_task_timeout_secs with a pr_info() that has no trailing newline. printk() keeps such a record open for a continuation and does not finalize it, so dmesg, the consoles and netconsole only see the report once the next message is logged.
Terminate the message with a newline.
--- fs/fs-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs-writeback.c +1 -1
@@ -204,7 +204,7 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done) done->progress_stamp = jiffies;if (timeout && (waited_secs > timeout))pr_info ("INFO: The task %s:%d has been waiting for writeback " -"completion for more than %lu seconds." , +"completion for more than %lu seconds.\n" , current->comm, current->pid, waited_secs);return !atomic_read (&done->cnt);
Signature · 1 line
2.53.0-Meta
PATCH v2 2/4 writeback: name the bdi in the slow writeback report
In reply to Breno LeitaoThe slow writeback report names the waiting task and how long it has waited, but not what it is waiting on. On a machine with several filesystems there is no way to tell which device is slow.
Pass the bdi to wb_wait_for_completion() and add its name to the report, together with the number of work items still outstanding. A sync issues one work item per cgroup wb with dirty inodes, so the count also shows whether a single cgroup is holding up the others.
wb_wait_for_completion() took the bdi until commit 5b9cce4c7eb0 ("writeback: Generalize and expose wb_completion") made it usable for the memcg foreign flushes. memcg tracks those by bdi id only and passes NULL, which bdi_dev_name() prints as "(unknown)".
A sync of files dirtied from two cgroups, on a throttled null_blk device, now reports:
[ 10.043698] INFO: The task sync:276 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).
--- fs/fs-writeback.c | 20 ++++++++++++-------- include/linux/backing-dev.h | 3 ++- mm/memcontrol.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-)
fs/fs-writeback.c +12 -8
@@ -196,7 +196,8 @@ static void wb_queue_work(struct bdi_writeback *wb,spin_unlock_irq (&wb->work_lock); } -static bool wb_wait_for_completion_cb (struct wb_completion *done) +static bool wb_wait_for_completion_cb (struct wb_completion *done, +struct backing_dev_info *bdi) {unsigned long timeout = sysctl_hung_task_timeout_secs;unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;
@@ -204,8 +205,9 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done) done->progress_stamp = jiffies;if (timeout && (waited_secs > timeout))pr_info ("INFO: The task %s:%d has been waiting for writeback " -"completion for more than %lu seconds.\n" , - current->comm, current->pid, waited_secs); +"completion for more than %lu seconds (bdi %s, work items left: %d).\n" , + current->comm, current->pid, waited_secs, +bdi_dev_name (bdi),atomic_read (&done->cnt));return !atomic_read (&done->cnt); }
@@ -213,6 +215,7 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done)/** * wb_wait_for_completion - wait for completion of bdi_writeback_works * @done: target wb_completion +* @bdi: bdi work items were issued to, NULL for the memcg foreign flushes * * Wait for one or more work items issued to @bdi with their ->done field * set to @done, which should have been initialized with
@@ -220,11 +223,12 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done)* are completed. Work items which are waited upon aren't freed * automatically on completion. */ -void wb_wait_for_completion (struct wb_completion *done) +void wb_wait_for_completion (struct wb_completion *done, +struct backing_dev_info *bdi) { done->wait_start = jiffies;atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq,wb_wait_for_completion_cb (done)); +wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi)); }#ifdef CONFIG_CGROUP_WRITEBACK
@@ -1164,7 +1168,7 @@ static void bdi_split_work_to_wbs(struct backing_dev_info *bdi, last_wb = wb;rcu_read_unlock (); -wb_wait_for_completion (&fallback_work_done); +wb_wait_for_completion (&fallback_work_done, bdi); goto restart; }rcu_read_unlock ();
@@ -2972,7 +2976,7 @@ static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,WARN_ON (!rwsem_is_locked (&sb->s_umount));bdi_split_work_to_wbs (sb->s_bdi, &work, skip_if_busy); -wb_wait_for_completion (&done); +wb_wait_for_completion (&done, bdi); }/**
@@ -3069,7 +3073,7 @@ void sync_inodes_sb(struct super_block *sb)/* protect against inode wb switch, see inode_switch_wbs_work_fn() */ bdi_down_write_wb_switch_rwsem (bdi);bdi_split_work_to_wbs (bdi, &work, false); -wb_wait_for_completion (&done); +wb_wait_for_completion (&done, bdi);bdi_up_write_wb_switch_rwsem (bdi);wait_sb_inodes (sb);
include/linux/backing-dev.h +2 -1
@@ -39,7 +39,8 @@ struct backing_dev_info *bdi_alloc(int node_id);void wb_start_background_writeback (struct bdi_writeback *wb);void wb_workfn (struct work_struct *work); -void wb_wait_for_completion (struct wb_completion *done); +void wb_wait_for_completion (struct wb_completion *done, +struct backing_dev_info *bdi);extern spinlock_t bdi_lock;extern struct list_head bdi_list;
mm/memcontrol.c +1 -1
@@ -4525,7 +4525,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)#ifdef CONFIG_CGROUP_WRITEBACK for (i =0 ; i <MEMCG_CGWB_FRN_CNT ; i++) -wb_wait_for_completion (&memcg->cgwb_frn[i].done); +wb_wait_for_completion (&memcg->cgwb_frn[i].done,NULL );#endif if (cgroup_subsys_on_dfl (memory_cgrp_subsys) && !cgroup_memory_nosocket)static_branch_dec (&memcg_sockets_enabled_key);
Signature · 1 line
2.53.0-Meta
Re: [PATCH v2 2/4] writeback: name the bdi in the slow writeback report
Quoted 14 lines · Breno Leitao
The slow writeback report names the waiting task and how long it has waited, but not what it is waiting on. On a machine with several filesystems there is no way to tell which device is slow.
Pass the bdi to
wb_wait_for_completion()and add its name to the report, together with the number of work items still outstanding. A sync issues one work item per cgroup wb with dirty inodes, so the count also shows whether a single cgroup is holding up the others.
wb_wait_for_completion()took the bdi until commit5b9cce4c7eb0("writeback: Generalize and exposewb_completion") made it usable for the memcg foreign flushes. memcg tracks those by bdi id only and passes NULL, whichbdi_dev_name()prints as "(unknown)".
Quoted 6 lines
A sync of files dirtied from two cgroups, on a throttled
null_blkdevice, now reports:[ 10.043698] INFO: The task sync:276 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).Signed-off-by Breno Leitao <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 113 lines
--- fs/fs-writeback.c | 20 ++++++++++++-------- include/linux/backing-dev.h | 3 ++- mm/memcontrol.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-)fs/fs-writeback.c +12
-8@@ -196,7 +196,8 @@ static void wb_queue_work(struct bdi_writeback *wb,spin_unlock_irq (&wb->work_lock); } -static bool wb_wait_for_completion_cb (struct wb_completion *done) +static bool wb_wait_for_completion_cb (struct wb_completion *done, +struct backing_dev_info *bdi) {unsigned long timeout = sysctl_hung_task_timeout_secs;unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;@@ -204,8 +205,9 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done) done->progress_stamp = jiffies;if (timeout && (waited_secs > timeout))pr_info ("INFO: The task %s:%d has been waiting for writeback " -"completion for more than %lu seconds.\n" , - current->comm, current->pid, waited_secs); +"completion for more than %lu seconds (bdi %s, work items left: %d).\n" , + current->comm, current->pid, waited_secs, +bdi_dev_name (bdi),atomic_read (&done->cnt));return !atomic_read (&done->cnt); }@@ -213,6 +215,7 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done)/** * wb_wait_for_completion - wait for completion of bdi_writeback_works * @done: target wb_completion +* @bdi: bdi work items were issued to, NULL for the memcg foreign flushes * * Wait for one or more work items issued to @bdi with their ->done field * set to @done, which should have been initialized with @@ -220,11 +223,12 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done)* are completed. Work items which are waited upon aren't freed * automatically on completion. */ -void wb_wait_for_completion (struct wb_completion *done) +void wb_wait_for_completion (struct wb_completion *done, +struct backing_dev_info *bdi) { done->wait_start = jiffies;atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq,wb_wait_for_completion_cb (done)); +wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi)); }#ifdef CONFIG_CGROUP_WRITEBACK @@ -1164,7 +1168,7 @@ static void bdi_split_work_to_wbs(struct backing_dev_info *bdi, last_wb = wb;rcu_read_unlock (); -wb_wait_for_completion (&fallback_work_done); +wb_wait_for_completion (&fallback_work_done, bdi); goto restart; }rcu_read_unlock ();@@ -2972,7 +2976,7 @@ static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,WARN_ON (!rwsem_is_locked (&sb->s_umount));bdi_split_work_to_wbs (sb->s_bdi, &work, skip_if_busy); -wb_wait_for_completion (&done); +wb_wait_for_completion (&done, bdi); }/** @@ -3069,7 +3073,7 @@ void sync_inodes_sb(struct super_block *sb)/* protect against inode wb switch, see inode_switch_wbs_work_fn() */ bdi_down_write_wb_switch_rwsem (bdi);bdi_split_work_to_wbs (bdi, &work, false); -wb_wait_for_completion (&done); +wb_wait_for_completion (&done, bdi);bdi_up_write_wb_switch_rwsem (bdi);wait_sb_inodes (sb);include/linux/backing-dev.h +2
-1@@ -39,7 +39,8 @@ struct backing_dev_info *bdi_alloc(int node_id);void wb_start_background_writeback (struct bdi_writeback *wb);void wb_workfn (struct work_struct *work); -void wb_wait_for_completion (struct wb_completion *done); +void wb_wait_for_completion (struct wb_completion *done, +struct backing_dev_info *bdi);extern spinlock_t bdi_lock;extern struct list_head bdi_list;mm/memcontrol.c +1
-1@@ -4525,7 +4525,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)#ifdef CONFIG_CGROUP_WRITEBACK for (i =0 ; i <MEMCG_CGWB_FRN_CNT ; i++) -wb_wait_for_completion (&memcg->cgwb_frn[i].done); +wb_wait_for_completion (&memcg->cgwb_frn[i].done,NULL );#endif if (cgroup_subsys_on_dfl (memory_cgrp_subsys) && !cgroup_memory_nosocket)static_branch_dec (&memcg_sockets_enabled_key);Signature · 2 lines
-- 2.53.0-Meta
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v2 3/4 writeback: log the end of a slow writeback wait
In reply to Breno LeitaoA slow writeback wait ends with one more "has been waiting" report, printed by the wakeup that sees the last work item complete:
[ 31.763963] INFO: The task sync:276 has been waiting for writeback completion for more than 29 seconds (bdi 252:0, work items left: 0).
That line reads as if the task were still waiting. To tell a slow writeback from a stuck one, the reader has to notice that the reports stopped, which is easy to miss in a busy log.
Report only while work items are outstanding, and log how long the wait took once it is over:
[ 31.807879] The task sync:275 waited 29 seconds for writeback completion on bdi 252:0
--- fs/fs-writeback.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
fs/fs-writeback.c +13 -3
@@ -201,15 +201,16 @@ 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 ; +int left =atomic_read (&done->cnt); done->progress_stamp = jiffies; -if (timeout && (waited_secs > timeout)) +if (left && timeout && (waited_secs > timeout))pr_info ("INFO: The task %s:%d has been waiting for writeback " "completion for more than %lu seconds (bdi %s, work items left: %d).\n" , current->comm, current->pid, waited_secs, -bdi_dev_name (bdi),atomic_read (&done->cnt)); +bdi_dev_name (bdi), left); -return !atomic_read (&done->cnt); +return !left; }/**
@@ -226,9 +227,18 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done,void wb_wait_for_completion (struct wb_completion *done,struct backing_dev_info *bdi) { +unsigned long timeout, waited; + done->wait_start = jiffies;atomic_dec (&done->cnt);/* put down the initial count */ wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi)); + + timeout = sysctl_hung_task_timeout_secs; + waited = jiffies - done->wait_start; +if (timeout && waited > timeout *HZ ) +pr_info ("The task %s:%d waited %lu seconds for writeback completion on bdi %s\n" , + current->comm, current->pid, waited /HZ , +bdi_dev_name (bdi)); }#ifdef CONFIG_CGROUP_WRITEBACK
Signature · 1 line
2.53.0-Meta
PATCH v2 4/4 writeback: report a slow writeback wait once per timeout
In reply to Breno LeitaoThe slow writeback report is printed on every wakeup of the waiter past hung_task_timeout_secs, and twice each time.
Each flusher working for the waiter wakes it once it has not run for half the timeout, so the hung task detector sees it make progress.
Since commit 84654c7f4730 ("wait: avoid spurious calls to prepare_to_wait_event() in ___wait_event()"), wait_event() checks the condition right after schedule() and again after prepare_to_wait_event(), so each of those wakeups reports twice.
A sync of files dirtied from two cgroups, on a throttled null_blk device with the timeout set to 5 seconds, gets 18 reports for a 29 second wait:
INFO: The task sync:275 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
...
Set ->progress_stamp when the wait starts, so the first check does not take a zero stamp for a timeout. The same test now prints 5 reports:
INFO: The task sync:276 has been waiting for writeback completion for more than 5 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:276 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
...
The task sync:276 waited 29 seconds for writeback completion on bdi 252:0
The flusher only checks for progress between inodes, so the wakeups now land on the first inode boundary past the timeout, a bit more than a timeout apart. The hung task detector scans once per timeout, so it can catch the waiter between two wakeups.
--- fs/fs-writeback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/fs-writeback.c +5 -3
@@ -203,12 +203,13 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done,unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;int left =atomic_read (&done->cnt); - done->progress_stamp = jiffies; -if (left && timeout && (waited_secs > timeout)) +if (left && timeout && +time_after (jiffies, done->progress_stamp + timeout *HZ ))pr_info ("INFO: The task %s:%d has been waiting for writeback " "completion for more than %lu seconds (bdi %s, work items left: %d).\n" , current->comm, current->pid, waited_secs,bdi_dev_name (bdi), left); + done->progress_stamp = jiffies;return !left; }
@@ -230,6 +231,7 @@ void wb_wait_for_completion(struct wb_completion *done,unsigned long timeout, waited; done->wait_start = jiffies; + done->progress_stamp = done->wait_start;atomic_dec (&done->cnt);/* put down the initial count */ wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi));
@@ -2135,7 +2137,7 @@ static long writeback_sb_inodes(struct super_block *sb,/* Report progress to inform the hung task detector of the progress. */ if (work->done && work->done->progress_stamp && timeout && - (jiffies - work->done->progress_stamp) >HZ * timeout /2 ) + (jiffies - work->done->progress_stamp) >HZ * timeout)wake_up_all (work->done->waitq);wbc_detach_inode (&wbc);
Signature · 1 line
2.53.0-Meta
Re: [PATCH v2 4/4] writeback: report a slow writeback wait once per timeout
Quoted 28 lines · Breno Leitao
The slow writeback report is printed on every wakeup of the waiter past
hung_task_timeout_secs, and twice each time.Each flusher working for the waiter wakes it once it has not run for half the timeout, so the hung task detector sees it make progress.
Since commit
84654c7f4730("wait: avoid spurious calls toprepare_to_wait_event()in___wait_event()"),wait_event()checks the condition right afterschedule()and again afterprepare_to_wait_event(), so each of those wakeups reports twice.A sync of files dirtied from two cgroups, on a throttled
null_blkdevice with the timeout set to 5 seconds, gets 18 reports for a 29 second wait:INFO: The task sync:275 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 7 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:275 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
...Set ->progress_stamp when the wait starts, so the first check does not take a zero stamp for a timeout. The same test now prints 5 reports:
INFO: The task sync:276 has been waiting for writeback completion for more than 5 seconds (bdi 252:0, work items left: 2).
INFO: The task sync:276 has been waiting for writeback completion for more than 10 seconds (bdi 252:0, work items left: 2).
...
The task sync:276 waited 29 seconds for writeback completion on bdi 252:0
Quoted 7 lines
The flusher only checks for progress between inodes, so the wakeups now land on the first inode boundary past the timeout, a bit more than a timeout apart. The hung task detector scans once per timeout, so it can catch the waiter between two wakeups.
Suggested-by Jan Kara <[email protected]>Signed-off-by Breno Leitao <[email protected]>
Looks good to me! Feel free to add:
Honza
Quoted 45 lines
--- fs/fs-writeback.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)fs/fs-writeback.c +5
-3@@ -203,12 +203,13 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done,unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;int left =atomic_read (&done->cnt); - done->progress_stamp = jiffies; -if (left && timeout && (waited_secs > timeout)) +if (left && timeout && +time_after (jiffies, done->progress_stamp + timeout *HZ ))pr_info ("INFO: The task %s:%d has been waiting for writeback " "completion for more than %lu seconds (bdi %s, work items left: %d).\n" , current->comm, current->pid, waited_secs,bdi_dev_name (bdi), left); + done->progress_stamp = jiffies;return !left; }@@ -230,6 +231,7 @@ void wb_wait_for_completion(struct wb_completion *done,unsigned long timeout, waited; done->wait_start = jiffies; + done->progress_stamp = done->wait_start;atomic_dec (&done->cnt);/* put down the initial count */ wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi));@@ -2135,7 +2137,7 @@ static long writeback_sb_inodes(struct super_block *sb,/* Report progress to inform the hung task detector of the progress. */ if (work->done && work->done->progress_stamp && timeout && - (jiffies - work->done->progress_stamp) >HZ * timeout /2 ) + (jiffies - work->done->progress_stamp) >HZ * timeout)wake_up_all (work->done->waitq);wbc_detach_inode (&wbc);Signature · 2 lines
-- 2.53.0-Meta
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
[email protected]
AI reviewRe: [PATCH v2 4/4] writeback: report a slow writeback wait once per timeout
In reply to Breno LeitaoThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] writeback: hung task wakeup interval exceeds timeout in writeback_sb_inodes() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] writeback: hung task wakeup interval exceeds timeout in writeback_sb_inodes()
--
commit f3edfd7b6ff429943317ab66c7dd1c29f9226156
Author: Breno Leitao <[email protected]>
writeback: report a slow writeback wait once per timeout
This commit rate-limits the slow writeback report in wb_wait_for_completion_cb() to once per hung_task_timeout_secs, initializes done->progress_stamp when waiting starts, and increases the progress wakeup interval in writeback_sb_inodes() from half the timeout to the full timeout.
Quoted 29 lines
fs/fs-writeback.c +4
-2@@ -203,12 +203,13 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done,unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;int left =atomic_read (&done->cnt); - done->progress_stamp = jiffies; -if (left && timeout && (waited_secs > timeout)) +if (left && timeout && +time_after (jiffies, done->progress_stamp + timeout *HZ ))pr_info ("INFO: The task %s:%d has been waiting for writeback " "completion for more than %lu seconds (bdi %s, work items left: %d).\n" , current->comm, current->pid, waited_secs,bdi_dev_name (bdi), left); + done->progress_stamp = jiffies;return !left; }@@ -230,6 +231,7 @@ void wb_wait_for_completion(struct wb_completion *done,unsigned long timeout, waited; done->wait_start = jiffies; + done->progress_stamp = done->wait_start;atomic_dec (&done->cnt);/* put down the initial count */ wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi));
fs/fs-writeback.c static long writeback_sb_inodes(struct super_block *sb, · line 2141
Quoted 6 lines
fs/fs-writeback.c +1
-1@@ -2135,7 +2137,7 @@ static long writeback_sb_inodes(struct super_block *sb,/* Report progress to inform the hung task detector of the progress. */ if (work->done && work->done->progress_stamp && timeout && - (jiffies - work->done->progress_stamp) >HZ * timeout /2 ) + (jiffies - work->done->progress_stamp) >HZ * timeout)wake_up_all (work->done->waitq);
[Severity: High]
Does raising the wakeup threshold from HZ * timeout / 2 to HZ * timeout cause khungtaskd to report false-positive hung tasks (or panic when sysctl_hung_task_panic is set) during slow writeback?
In kernel/hung_task.c, task_is_hung() stamps t->last_switch_time with the time of the scan that first notices a new switch_count, not the time the task actually scheduled:
kernel/hung_task.c:task_is_hung() {
...
if (switch_count != t->last_switch_count) {
t->last_switch_count = switch_count;
t->last_switch_time = jiffies;
return false;
}
if (time_is_after_jiffies(t->last_switch_time + timeout * HZ))
return false;
return true;
}Because writeback_sb_inodes() only checks the threshold after __writeback_single_inode() finishes, consecutive wakeups are spaced by HZ * timeout plus the time spent writing the next inode. That wakeup period is strictly longer than khungtaskd's timeout * HZ detection window, so a scan that runs right after a wakeup can be followed by the next scan at last_switch_time + timeout * HZ before the next wakeup happens, defeating 1888635532fb ("writeback: Wake up waiting tasks when finishing the writeback of a chunk.").
Keeping the wakeup threshold at HZ * timeout / 2 while tracking the last pr_info() timestamp separately from done->progress_stamp (or only updating done->progress_stamp when logging) would avoid waking the waiter late.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jan Kara
reviewerRe: [PATCH v2 4/4] writeback: report a slow writeback wait once per timeout
Quoted 4 lines · On Wed 11-11-26 11:47:37, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] writeback: hung task wakeup interval exceeds timeout inwriteback_sb_inodes()
Aha! Indeed this was the reason why we chose half the hang check interval. So we really have to go below that. So maybe just fix the duplicated messages and put up with report twice per hang check interval? Or we could use 3/4 here if you think it would be better.
Honza
Quoted 85 lines
--
commit
f3edfd7b6ff429943317ab66c7dd1c29f9226156
Author: Breno Leitao <[email protected]>writeback: report a slow writeback wait once per timeout
This commit rate-limits the slow writeback report in
wb_wait_for_completion_cb()to once perhung_task_timeout_secs, initializesdone->progress_stampwhen waiting starts, and increases the progress wakeup interval inwriteback_sb_inodes()from half the timeout to the full timeout.Quoted 29 lines
fs/fs-writeback.c +4
-2@@ -203,12 +203,13 @@ static bool wb_wait_for_completion_cb(struct wb_completion *done,unsigned long waited_secs = (jiffies - done->wait_start) /HZ ;int left =atomic_read (&done->cnt); - done->progress_stamp = jiffies; -if (left && timeout && (waited_secs > timeout)) +if (left && timeout && +time_after (jiffies, done->progress_stamp + timeout *HZ ))pr_info ("INFO: The task %s:%d has been waiting for writeback " "completion for more than %lu seconds (bdi %s, work items left: %d).\n" , current->comm, current->pid, waited_secs,bdi_dev_name (bdi), left); + done->progress_stamp = jiffies;return !left; }@@ -230,6 +231,7 @@ void wb_wait_for_completion(struct wb_completion *done,unsigned long timeout, waited; done->wait_start = jiffies; + done->progress_stamp = done->wait_start;atomic_dec (&done->cnt);/* put down the initial count */ wait_event (*done->waitq,wb_wait_for_completion_cb (done, bdi));fs/fs-writeback.c static long writeback_sb_inodes(struct super_block *sb, · line 2141
Quoted 6 lines
fs/fs-writeback.c +1
-1@@ -2135,7 +2137,7 @@ static long writeback_sb_inodes(struct super_block *sb,/* Report progress to inform the hung task detector of the progress. */ if (work->done && work->done->progress_stamp && timeout && - (jiffies - work->done->progress_stamp) >HZ * timeout /2 ) + (jiffies - work->done->progress_stamp) >HZ * timeout)wake_up_all (work->done->waitq);[Severity: High]
Does raising the wakeup threshold from HZ * timeout / 2 to HZ * timeout cause khungtaskd to report false-positive hung tasks (or panic whensysctl_hung_task_panicis set) during slow writeback?In
kernel/hung_task.c,task_is_hung()stampst->last_switch_timewith the time of the scan that first notices a newswitch_count, not the time the task actually scheduled:kernel/hung_task.c:task_is_hung() { ... if (switch_count != t->last_switch_count) { t->last_switch_count = switch_count; t->last_switch_time = jiffies; return false; } if (time_is_after_jiffies(t->last_switch_time + timeout * HZ)) return false; return true; }Because
writeback_sb_inodes()only checks the threshold after__writeback_single_inode()finishes, consecutive wakeups are spaced by HZ * timeout plus the time spent writing the next inode. That wakeup period is strictly longer than khungtaskd's timeout * HZ detection window, so a scan that runs right after a wakeup can be followed by the next scan atlast_switch_time+ timeout * HZ before the next wakeup happens, defeating1888635532fb("writeback: Wake up waiting tasks when finishing the writeback of a chunk.").Keeping the wakeup threshold at HZ * timeout / 2 while tracking the last
pr_info()timestamp separately fromdone->progress_stamp(or only updatingdone->progress_stampwhen logging) would avoid waking the waiter late.Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v2 4/4] writeback: report a slow writeback wait once per timeout
In reply to Breno LeitaoHi Breno,
Quoted 4 lines · Breno Leitao
The flusher only checks for progress between inodes, so the wakeups now land on the first inode boundary past the timeout, a bit more than a timeout apart. The hung task detector scans once per timeout, so it can catch the waiter between two wakeups.
This does happen in practice. With your null_blk setup and the timeout at 5 seconds, the waiter gets woken every 5.0 to 6.1 seconds. khungtaskd reported sync as "blocked for more than 5 seconds" in one of five 40 second syncs with the default check interval, and twice in a single sync with hung_task_check_interval_secs=1. With hung_task_panic set, that panics a machine whose writeback is making progress. Stopping these warnings is what 1888635532fb ("writeback: Wake up waiting tasks when finishing the writeback of a chunk.") was for, so as Jan said, the wakeups have to stay below the timeout.
fs/fs-writeback.c static bool wb_wait_for_completion_cb(struct wb_completion *done, · line 207
Quoted 4 lines
fs/fs-writeback.c +2
-2- done->progress_stamp = jiffies; -if (left && timeout && (waited_secs > timeout)) +if (left && timeout && +time_after (jiffies, done->progress_stamp + timeout *HZ ))
But this check can't stay as it is once that's done. progress_stamp is reset on every wakeup, so if the flusher wakes the waiter every half timeout, this is only true when a single inode holds up the flusher for more than the other half. With the threshold in writeback_sb_inodes() put back to timeout / 2 and the rest of this patch kept, the same test prints no "has been waiting" reports at all, only the "waited N seconds" line from patch 3. Going by the code, three quarters of the timeout would mostly have the same problem.
The report_stamp you had in v1 keeps the reports apart without touching the wakeups, so maybe go back to that and leave writeback_sb_inodes() alone? That also gets rid of the duplicate from wait_event() checking twice. With v1's report_stamp on top of patches 1-3, I get one report per timeout and no hung task warnings.
Thanks!
Chris
Re: (subset) [PATCH v2 0/4] writeback: make slow writeback report more actionable
In reply to Breno LeitaoQuoted 10 lines · Breno Leitao
Since v6.19, writeback waiters are woken while their writeback makes progress, so a slow sync no longer trips the hung task detector. Instead, a waiter past
hung_task_timeout_secslogs:INFO: The task sync:180 has been waiting for writeback completion for more than 28 seconds.
Across the Meta fleet, this line is logged about 19,000 times a day (the median over 40 days), and up to 82,000 times on a busy day.
[...]
I took 1-3 as they're fairly separate fixes. Please rework 4 as agreed on the thread and send it.
---
Applied to the vfs-7.5.writeback branch of the vfs/vfs.git tree. Patches in the vfs-7.5.writeback branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.5.writeback
[1/4] writeback: add the missing newline to the slow writeback report
https://git.kernel.org/vfs/vfs/c/82da6ca38c26 [2/4] writeback: name the bdi in the slow writeback report https://git.kernel.org/vfs/vfs/c/8dd5775aab52 [3/4] writeback: log the end of a slow writeback wait https://git.kernel.org/vfs/vfs/c/26286f60c266