block: add blk_io_schedule() for avoiding task hung in sync dio
Subsystems (3)
PATCH v2 1/1 block: add blk_io_schedule() for avoiding task hung in sync dio
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in submit_bio_wait() and blk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.
Add helper of blk_io_schedule() and use io_schedule_timeout() to prevent task hung warning.
---
V2:
- drop helper of blk_default_io_timeout()
fs/block_dev.c | 4 ++-- fs/direct-io.c | 2 +- fs/iomap/direct-io.c | 2 +- include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-)
fs/block_dev.c +2 -2
@@ -256,7 +256,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,break ;if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );
@@ -450,7 +450,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );
fs/direct-io.c +1 -1
@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)spin_unlock_irqrestore (&dio->bio_lock, flags);if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;
fs/iomap/direct-io.c +1 -1
@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, !dio->submit.last_queue || !blk_poll(dio->submit.last_queue, dio->submit.cookie, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING ); }
include/linux/blkdev.h +12 -0
@@ -27,6 +27,7 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> +#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;
@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter) wake_up_process(waiter); } +static inline void blk_io_schedule (void ) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +io_schedule_timeout (timeout); +else +io_schedule (); +} +#endif
Signature · 1 line
2.25.2
Quoted 8 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.
Quoted 92 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.Cc Salman Qazi <[email protected]>Cc Jesse Barnes <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Signed-off-by Ming Lei <[email protected]>---
V2:
- drop helper ofblk_default_io_timeout()fs/block_dev.c | 4 ++-- fs/direct-io.c | 2 +- fs/iomap/direct-io.c | 2 +- include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-)fs/block_dev.c +2
-2@@ -256,7 +256,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,break ;if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );@@ -450,7 +450,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );fs/direct-io.c +1
-1@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)spin_unlock_irqrestore (&dio->bio_lock, flags);if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;fs/iomap/direct-io.c +1
-1@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, !dio->submit.last_queue || !blk_poll(dio->submit.last_queue, dio->submit.cookie, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING ); }include/linux/blkdev.h +3
-0@@ -27,6 +27,7 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> +#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter)wake_up_process (waiter); } +static inline void blk_io_schedule (void ) +{
include/linux/blkdev.h static inline void blk_wake_io_task(struct task_struct *waiter) · line 1842
Quoted 10 lines
include/linux/blkdev.h +9
-0+/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +io_schedule_timeout (timeout); +else + io_schedule(); +} +#endif
Hi Jens and Guys,
Ping...
thanks,
Ming
Quoted 8 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.
Applied, thanks.
Signature · 1 line
Jens Axboe
Quoted 92 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.Cc Salman Qazi <[email protected]>Cc Jesse Barnes <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Signed-off-by Ming Lei <[email protected]>---
V2:
- drop helper ofblk_default_io_timeout()fs/block_dev.c | 4 ++-- fs/direct-io.c | 2 +- fs/iomap/direct-io.c | 2 +- include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-)fs/block_dev.c +2
-2@@ -256,7 +256,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,break ;if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );@@ -450,7 +450,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );fs/direct-io.c +1
-1@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)spin_unlock_irqrestore (&dio->bio_lock, flags);if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;fs/iomap/direct-io.c +1
-1@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, !dio->submit.last_queue || !blk_poll(dio->submit.last_queue, dio->submit.cookie, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING ); }include/linux/blkdev.h +3
-0@@ -27,6 +27,7 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> +#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter)wake_up_process (waiter); } +static inline void blk_io_schedule (void ) +{
include/linux/blkdev.h static inline void blk_wake_io_task(struct task_struct *waiter) · line 1842
Quoted 10 lines
include/linux/blkdev.h +9
-0+/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +io_schedule_timeout (timeout); +else + io_schedule(); +} +#endif
This won't compile without CONFIG_BLOCK, since this patch includes linux/sched/sysctl.h only inside the #ifdef CONFIG_BLOCK, while blk_io_schedule is declared outside the #ifdef CONFIG_BLOCK, but references sysctl_hung_task_timeout_secs defined in linux/sched/sysctl.h. Afaict, the function isn't needed without CONFIG_BLOCK, so maybe we should move the function into the #ifdef CONFIG_BLOCK too?
Quoted 3 lines
Signature · 1 line
2.25.2
Quoted 91 lines · Satya Tangirala
Quoted 90 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.Cc Salman Qazi <[email protected]>Cc Jesse Barnes <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Signed-off-by Ming Lei <[email protected]>---
V2:
- drop helper ofblk_default_io_timeout()fs/block_dev.c | 4 ++-- fs/direct-io.c | 2 +- fs/iomap/direct-io.c | 2 +- include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-)fs/block_dev.c +2
-2@@ -256,7 +256,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,break ;if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );@@ -450,7 +450,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );fs/direct-io.c +1
-1@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)spin_unlock_irqrestore (&dio->bio_lock, flags);if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;fs/iomap/direct-io.c +1
-1@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, !dio->submit.last_queue || !blk_poll(dio->submit.last_queue, dio->submit.cookie, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING ); }include/linux/blkdev.h +1
-0@@ -27,6 +27,7 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> +#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter)wake_up_process (waiter); }
Quoted 13 lines
include/linux/blkdev.h static inline void blk_wake_io_task(struct task_struct *waiter) · line 1842
Quoted 12 lines
include/linux/blkdev.h +11
-0+static inline void blk_io_schedule (void ) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +io_schedule_timeout (timeout); +else +io_schedule (); +} +#endif This won't compile without
CONFIG_BLOCK, since this patch includes
Thanks for the report.
Quoted 5 lines
linux/sched/sysctl.honly inside the #ifdefCONFIG_BLOCK, whileblk_io_scheduleis declared outside the #ifdefCONFIG_BLOCK, but referencessysctl_hung_task_timeout_secsdefined inlinux/sched/sysctl.h. Afaict, the function isn't needed withoutCONFIG_BLOCK, so maybe we should move the function into the #ifdefCONFIG_BLOCKtoo?
Given io_schedule() is always available, I'd suggest to move "#include <linux/sched/sysctl.h>" out of '#ifdef CONFIG_BLOCK', does the following patch fixes the issue?
include/linux/blkdev.h +1 -1
@@ -4,6 +4,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <linux/sched/sysctl.h> #ifdef CONFIG_BLOCK
@@ -27,7 +28,6 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> -#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;
thanks,
Ming
Quoted 114 lines · Ming Lei
Quoted 91 lines · Satya Tangirala
Quoted 90 lines · Ming Lei
Sync dio could be big, or may take long time in discard or in case of IO failure.
We have prevented task hung in
submit_bio_wait()andblk_execute_rq(), so apply the same trick for prevent task hung from happening in sync dio.Add helper of
blk_io_schedule()and useio_schedule_timeout()to prevent task hung warning.Cc Salman Qazi <[email protected]>Cc Jesse Barnes <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Signed-off-by Ming Lei <[email protected]>---
V2:
- drop helper ofblk_default_io_timeout()fs/block_dev.c | 4 ++-- fs/direct-io.c | 2 +- fs/iomap/direct-io.c | 2 +- include/linux/blkdev.h | 12 ++++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-)fs/block_dev.c +2
-2@@ -256,7 +256,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,break ;if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );@@ -450,7 +450,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)if (!(iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (bdev_get_queue (bdev), qc, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING );fs/direct-io.c +1
-1@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)spin_unlock_irqrestore (&dio->bio_lock, flags);if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;fs/iomap/direct-io.c +1
-1@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, !dio->submit.last_queue || !blk_poll(dio->submit.last_queue, dio->submit.cookie, true)) -io_schedule (); +blk_io_schedule (); }__set_current_state (TASK_RUNNING ); }include/linux/blkdev.h +1
-0@@ -27,6 +27,7 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> +#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter)wake_up_process (waiter); }Quoted 13 lines
include/linux/blkdev.h static inline void blk_wake_io_task(struct task_struct *waiter) · line 1842
Quoted 12 lines
include/linux/blkdev.h +11
-0+static inline void blk_io_schedule (void ) +{ +/* Prevent hang_check timer from firing at us during very long I/O */ +unsigned long timeout = sysctl_hung_task_timeout_secs *HZ /2 ; + +if (timeout) +io_schedule_timeout (timeout); +else +io_schedule (); +} +#endif This won't compile without
CONFIG_BLOCK, since this patch includesThanks for the report.
Quoted 5 lines
linux/sched/sysctl.honly inside the #ifdefCONFIG_BLOCK, whileblk_io_scheduleis declared outside the #ifdefCONFIG_BLOCK, but referencessysctl_hung_task_timeout_secsdefined inlinux/sched/sysctl.h. Afaict, the function isn't needed withoutCONFIG_BLOCK, so maybe we should move the function into the #ifdefCONFIG_BLOCKtoo?
Quoted 4 lines
Given
io_schedule()is always available, I'd suggest to move "#include <linux/sched/sysctl.h>" out of '#ifdefCONFIG_BLOCK', does the following patch fixes the issue?
Yeah sure, that works too :).
Quoted 24 lines
include/linux/blkdev.h +1
-1@@ -4,6 +4,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <linux/sched/sysctl.h> #ifdef CONFIG_BLOCK @@ -27,7 +28,6 @@#include <linux/percpu-refcount.h> #include <linux/scatterlist.h> #include <linux/blkzoned.h> -#include <linux/sched/sysctl.h> struct module ;struct scsi_ioctl_command ;thanks,
Ming