writeback: Wake up waiting tasks when finishing the writeback of a chunk.
PATCH v3 1/2 writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.
This patch has passed the xfstests 'check -g quick' test based on ext4, with no additional failures introduced.
---
Changes in v2:
* remove code in finish_writeback_work()
* rename stamp to progress_stamp
* only report progress if there's any task waiting
fs/fs-writeback.c | 11 ++++++++++- include/linux/backing-dev-defs.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
fs/fs-writeback.c +10 -1
@@ -14,6 +14,7 @@* Additions for address_space-based writeback */ +#include <linux/sched/sysctl.h> #include <linux/kernel.h> #include <linux/export.h> #include <linux/spinlock.h>
@@ -213,7 +214,8 @@ static void wb_queue_work(struct bdi_writeback *wb,void wb_wait_for_completion (struct wb_completion *done) {atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq, !atomic_read (&done->cnt)); +wait_event (*done->waitq, + ({ done->progress_stamp = jiffies; !atomic_read (&done->cnt); })); }#ifdef CONFIG_CGROUP_WRITEBACK
@@ -1893,6 +1895,7 @@ static long writeback_sb_inodes(struct super_block *sb,long write_chunk;long total_wrote =0 ;/* count both pages and inodes */ unsigned long dirtied_before = jiffies; +unsigned long progress_stamp;if (work->for_kupdate) dirtied_before = jiffies -
@@ -1975,6 +1978,12 @@ 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. */ + progress_stamp = work->done->progress_stamp; +if (work->done && progress_stamp && (jiffies - progress_stamp) > +HZ * sysctl_hung_task_timeout_secs /2 ) +wake_up_all (work->done->waitq); +wbc_detach_inode (&wbc); work->nr_pages -= write_chunk - wbc.nr_to_write; wrote = write_chunk - wbc.nr_to_write - wbc.pages_skipped;
include/linux/backing-dev-defs.h +1 -0
@@ -63,6 +63,7 @@ enum wb_reason {struct wb_completion {atomic_t cnt;wait_queue_head_t *waitq; +unsigned long progress_stamp;/* The jiffies when slow progress is detected */ };#define __WB_COMPLETION_INIT (_waitq) \
Signature · 1 line
2.39.5
PATCH v3 1/2 writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.
This patch has passed the xfstests 'check -g quick' test based on ext4, with no additional failures introduced.
---
Hi, the previous patch sent unupdated code due to an mistake; this version is the genuine v3.
Changes in v3:
* Fix null-ptr-deref issue.
Changes in v2:
* remove code in finish_writeback_work()
* rename stamp to progress_stamp
* only report progress if there's any task waiting
fs/fs-writeback.c | 10 +++++++++- include/linux/backing-dev-defs.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-)
fs/fs-writeback.c +9 -1
@@ -14,6 +14,7 @@* Additions for address_space-based writeback */ +#include <linux/sched/sysctl.h> #include <linux/kernel.h> #include <linux/export.h> #include <linux/spinlock.h>
@@ -213,7 +214,8 @@ static void wb_queue_work(struct bdi_writeback *wb,void wb_wait_for_completion (struct wb_completion *done) {atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq, !atomic_read (&done->cnt)); +wait_event (*done->waitq, + ({ done->progress_stamp = jiffies; !atomic_read (&done->cnt); })); }#ifdef CONFIG_CGROUP_WRITEBACK
@@ -1975,6 +1977,12 @@ 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 ) +wake_up_all (work->done->waitq); +wbc_detach_inode (&wbc); work->nr_pages -= write_chunk - wbc.nr_to_write; wrote = write_chunk - wbc.nr_to_write - wbc.pages_skipped;
include/linux/backing-dev-defs.h +1 -0
@@ -63,6 +63,7 @@ enum wb_reason {struct wb_completion {atomic_t cnt;wait_queue_head_t *waitq; +unsigned long progress_stamp;/* The jiffies when slow progress is detected */ };#define __WB_COMPLETION_INIT (_waitq) \
Signature · 1 line
2.39.5
Quoted 11 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.
Quoted 5 lines
This patch has passed the xfstests 'check -g quick' test based on ext4, with no additional failures introduced.
Signed-off-by Julian Sun <[email protected]>Suggested-by Peter Zijlstra <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 67 lines
---
Hi, the previous patch sent unupdated code due to an mistake; this version is the genuine v3.Changes in v3:
* Fix null-ptr-deref issue.Changes in v2:
* remove code infinish_writeback_work()
* rename stamp toprogress_stamp
* only report progress if there's any task waitingfs/fs-writeback.c | 10 +++++++++- include/linux/backing-dev-defs.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-)fs/fs-writeback.c +9
-1@@ -14,6 +14,7 @@* Additions for address_space-based writeback */ +#include <linux/sched/sysctl.h> #include <linux/kernel.h> #include <linux/export.h> #include <linux/spinlock.h> @@ -213,7 +214,8 @@ static void wb_queue_work(struct bdi_writeback *wb,void wb_wait_for_completion (struct wb_completion *done) {atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq, !atomic_read (&done->cnt)); +wait_event (*done->waitq, + ({ done->progress_stamp = jiffies; !atomic_read (&done->cnt); })); }#ifdef CONFIG_CGROUP_WRITEBACK @@ -1975,6 +1977,12 @@ 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 ) +wake_up_all (work->done->waitq); +wbc_detach_inode (&wbc); work->nr_pages -= write_chunk - wbc.nr_to_write; wrote = write_chunk - wbc.nr_to_write - wbc.pages_skipped;include/linux/backing-dev-defs.h +1
-0@@ -63,6 +63,7 @@ enum wb_reason {struct wb_completion {atomic_t cnt;wait_queue_head_t *waitq; +unsigned long progress_stamp;/* The jiffies when slow progress is detected */ };#define __WB_COMPLETION_INIT (_waitq) \Signature · 1 line
2.39.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 2/2 writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)
In reply to Julian SunWhen a writeback work lasts for sysctl_hung_task_timeout_secs, we want to identify that there are tasks waiting for a long time-this helps us pinpoint potential issues.
Additionally, recording the starting jiffies is useful when debugging a crashed vmcore.
---
Changes in v3:
* Show blocked task info instead of BDI info as Jan suggested.
Changes in v2:
* rename start to wait_stamp
* init wait_stamp in wb_wait_for_completion()
fs/fs-writeback.c | 17 +++++++++++++++-- include/linux/backing-dev-defs.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-)
fs/fs-writeback.c +15 -2
@@ -201,6 +201,19 @@ 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) +{ +unsigned long waited_secs = (jiffies - done->wait_start) /HZ ; + + done->progress_stamp = jiffies; +if (waited_secs > sysctl_hung_task_timeout_secs) +pr_info ("INFO: The task %s:%d has been waiting for writeback " +"completion for more than %lu seconds." , + current->comm, current->pid, waited_secs); + +return !atomic_read (&done->cnt); +} +/** * wb_wait_for_completion - wait for completion of bdi_writeback_works * @done: target wb_completion
@@ -213,9 +226,9 @@ static void wb_queue_work(struct bdi_writeback *wb,*/ void wb_wait_for_completion (struct wb_completion *done) { + done->wait_start = jiffies;atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq, - ({ done->progress_stamp = jiffies; !atomic_read (&done->cnt); })); +wait_event (*done->waitq,wb_wait_for_completion_cb (done)); }#ifdef CONFIG_CGROUP_WRITEBACK
include/linux/backing-dev-defs.h +1 -0
@@ -64,6 +64,7 @@ struct wb_completion {atomic_t cnt;wait_queue_head_t *waitq;unsigned long progress_stamp;/* The jiffies when slow progress is detected */ +unsigned long wait_start;/* The jiffies when waiting for the writeback work to finish */ };#define __WB_COMPLETION_INIT (_waitq) \
Signature · 1 line
2.39.5
Jan Kara
reviewerRe: [PATCH v3 2/2] writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)
Quoted 8 lines · Julian Sun
When a writeback work lasts for
sysctl_hung_task_timeout_secs, we want to identify that there are tasks waiting for a long time-this helps us pinpoint potential issues.Additionally, recording the starting jiffies is useful when debugging a crashed vmcore.
Signed-off-by Julian Sun <[email protected]>
Looks good.
Honza
Quoted 63 lines
---
Changes in v3:
* Show blocked task info instead of BDI info as Jan suggested.Changes in v2:
* rename start towait_stamp
* initwait_stampinwb_wait_for_completion()fs/fs-writeback.c | 17 +++++++++++++++-- include/linux/backing-dev-defs.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-)fs/fs-writeback.c +15
-2@@ -201,6 +201,19 @@ 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) +{ +unsigned long waited_secs = (jiffies - done->wait_start) /HZ ; + + done->progress_stamp = jiffies; +if (waited_secs > sysctl_hung_task_timeout_secs) +pr_info ("INFO: The task %s:%d has been waiting for writeback " +"completion for more than %lu seconds." , + current->comm, current->pid, waited_secs); + +return !atomic_read (&done->cnt); +} +/** * wb_wait_for_completion - wait for completion of bdi_writeback_works * @done: target wb_completion @@ -213,9 +226,9 @@ static void wb_queue_work(struct bdi_writeback *wb,*/ void wb_wait_for_completion (struct wb_completion *done) { + done->wait_start = jiffies;atomic_dec (&done->cnt);/* put down the initial count */ -wait_event (*done->waitq, - ({ done->progress_stamp = jiffies; !atomic_read (&done->cnt); })); +wait_event (*done->waitq,wb_wait_for_completion_cb (done)); }#ifdef CONFIG_CGROUP_WRITEBACK include/linux/backing-dev-defs.h +1
-0@@ -64,6 +64,7 @@ struct wb_completion {atomic_t cnt;wait_queue_head_t *waitq;unsigned long progress_stamp;/* The jiffies when slow progress is detected */ +unsigned long wait_start;/* The jiffies when waiting for the writeback work to finish */ };#define __WB_COMPLETION_INIT (_waitq) \Signature · 1 line
2.39.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: (subset) [PATCH v3 2/2] writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)
In reply to Julian SunQuoted 8 lines · Julian Sun
When a writeback work lasts for
sysctl_hung_task_timeout_secs, we want to identify that there are tasks waiting for a long time-this helps us pinpoint potential issues.Additionally, recording the starting jiffies is useful when debugging a crashed vmcore.
[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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-6.19.writeback
[2/2] writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)
https://git.kernel.org/vfs/vfs/c/51d8f1c7919e
Re: (subset) [PATCH v3 1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
In reply to Julian SunQuoted 5 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
Quoted 7 lines
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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-6.19.writeback
[1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
https://git.kernel.org/vfs/vfs/c/334b83b3ed81
Re: [External] Re: (subset) [PATCH v3 1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Hi Christian,
It looks like an earlier version of my patch was merged, which may cause a null pointer dereference issue. The latest and correct version can be found here:
https://lore.kernel.org/linux-fsdevel/[email protected]/.
Sorry for the confusion, and thank you for your time and help!
Best,
Quoted 32 lines · Christian Brauner
Quoted 5 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
Quoted 7 lines
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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-6.19.writeback[1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
https://git.kernel.org/vfs/vfs/c/334b83b3ed81
Signature · 1 line
Julian Sun <[email protected]>
Re: (subset) [PATCH v3 1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Kindly ping..
Quoted 51 lines · Julian Sun
Hi Christian,
It looks like an earlier version of my patch was merged, which may cause a null pointer dereference issue. The latest and correct version can be found here:
https://lore.kernel.org/linux-fsdevel/[email protected]/.Sorry for the confusion, and thank you for your time and help!
Best,
Quoted 24 lines · Christian Brauner
Quoted 5 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
Quoted 7 lines
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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.
Quoted 8 lines
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-6.19.writeback[1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
https://git.kernel.org/vfs/vfs/c/334b83b3ed81--
Julian Sun <[email protected]>
Signature · 1 line
Julian Sun <[email protected]>
Christian Brauner
maintainerRe: (subset) [PATCH v3 1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Quoted 1 line · Julian Sun
Kindly ping..
Please check vfs-6.19.writeback again.
Your patch numbering is broken btw. This should've been v4 with both patches resent. This confuses the tooling and reviewers. ;)
Quoted 58 lines · Julian Sun
Quoted 51 lines
Hi Christian,
It looks like an earlier version of my patch was merged, which may cause a null pointer dereference issue. The latest and correct version can be found here:
https://lore.kernel.org/linux-fsdevel/[email protected]/.Sorry for the confusion, and thank you for your time and help!
Best,
Quoted 24 lines · Christian Brauner
Quoted 5 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
Quoted 7 lines
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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.
Quoted 8 lines
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-6.19.writeback[1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
https://git.kernel.org/vfs/vfs/c/334b83b3ed81--
Julian Sun <[email protected]>Signature · 1 line
Julian Sun <[email protected]>
Re: (subset) [PATCH v3 1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
Quoted 4 lines · Christian Brauner
Quoted 1 line · Julian Sun
Kindly ping..
Please check vfs-6.19.writeback again.
Looks good to me now.>
Quoted 2 lines
Your patch numbering is broken btw. This should've been v4 with both patches resent. This confuses the tooling and reviewers. ;)
Ah, yeah.. Sorry for the confusion, and thanks for your time.>
Quoted 51 lines
Quoted 51 lines · Julian Sun
Quoted 49 lines
Hi Christian,
It looks like an earlier version of my patch was merged, which may cause a null pointer dereference issue. The latest and correct version can be found here:
https://lore.kernel.org/linux-fsdevel/[email protected]/.Sorry for the confusion, and thank you for your time and help!
Best,
Quoted 32 lines · Christian Brauner
Quoted 5 lines · Julian Sun
Writing back a large number of pages can take a lots of time. This issue is exacerbated when the underlying device is slow or subject to block layer rate limiting, which in turn triggers unexpected hung task warnings.
Quoted 7 lines
We can trigger a wake-up once a chunk has been written back and the waiting time for writeback exceeds half of
sysctl_hung_task_timeout_secs.
This action allows the hung task detector to be aware of the writeback progress, thereby eliminating these unexpected hung task warnings.[...]
Applied to the vfs-6.19.writeback branch of the vfs/vfs.git tree. Patches in the vfs-6.19.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-6.19.writeback[1/2] writeback: Wake up waiting tasks when finishing the writeback of a chunk.
https://git.kernel.org/vfs/vfs/c/334b83b3ed81
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
--
Julian Sun <[email protected]>Signature · 1 line
Julian Sun <[email protected]>
Best,
Signature · 1 line
Julian Sun <[email protected]>