Skip to content

Commit e6249cd

Browse files
Ming Leiaxboe
authored andcommitted
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. Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> 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: Jens Axboe <[email protected]>
1 parent 27eb3af commit e6249cd

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

fs/block_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
255255
break;
256256
if (!(iocb->ki_flags & IOCB_HIPRI) ||
257257
!blk_poll(bdev_get_queue(bdev), qc, true))
258-
io_schedule();
258+
blk_io_schedule();
259259
}
260260
__set_current_state(TASK_RUNNING);
261261

@@ -449,7 +449,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)
449449

450450
if (!(iocb->ki_flags & IOCB_HIPRI) ||
451451
!blk_poll(bdev_get_queue(bdev), qc, true))
452-
io_schedule();
452+
blk_io_schedule();
453453
}
454454
__set_current_state(TASK_RUNNING);
455455

fs/direct-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static struct bio *dio_await_one(struct dio *dio)
500500
spin_unlock_irqrestore(&dio->bio_lock, flags);
501501
if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
502502
!blk_poll(dio->bio_disk->queue, dio->bio_cookie, true))
503-
io_schedule();
503+
blk_io_schedule();
504504
/* wake up sets us TASK_RUNNING */
505505
spin_lock_irqsave(&dio->bio_lock, flags);
506506
dio->waiter = NULL;

fs/iomap/direct-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
561561
!dio->submit.last_queue ||
562562
!blk_poll(dio->submit.last_queue,
563563
dio->submit.cookie, true))
564-
io_schedule();
564+
blk_io_schedule();
565565
}
566566
__set_current_state(TASK_RUNNING);
567567
}

include/linux/blkdev.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/percpu-refcount.h>
2828
#include <linux/scatterlist.h>
2929
#include <linux/blkzoned.h>
30+
#include <linux/sched/sysctl.h>
3031

3132
struct module;
3233
struct scsi_ioctl_command;
@@ -1827,4 +1828,15 @@ static inline void blk_wake_io_task(struct task_struct *waiter)
18271828
wake_up_process(waiter);
18281829
}
18291830

1831+
static inline void blk_io_schedule(void)
1832+
{
1833+
/* Prevent hang_check timer from firing at us during very long I/O */
1834+
unsigned long timeout = sysctl_hung_task_timeout_secs * HZ / 2;
1835+
1836+
if (timeout)
1837+
io_schedule_timeout(timeout);
1838+
else
1839+
io_schedule();
1840+
}
1841+
18301842
#endif

0 commit comments

Comments
 (0)