From: Ming Lei Date: Wed, 18 Mar 2020 03:43:36 +0000 (+0800) Subject: block: Prevent hung_check firing during long sync IO X-Git-Tag: Ubuntu-5.13.0-19.19~6432^2~51 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=de6a78b601c529398ad1448e3bffcade1fcf5a70;p=mirror_ubuntu-jammy-kernel.git block: Prevent hung_check firing during long sync IO submit_bio_wait() can be called from ioctl(BLKSECDISCARD), which may take long time to complete, as Salman mentioned, 4K BLKSECDISCARD takes up to 100 second on some devices. Also any block I/O operation that occurs after the BLKSECDISCARD is submitted will also potentially be affected by the hung task timeouts. Another report is that task hang can be observed when running mkfs over raid10 which takes a small max discard sectors limit because of chunk size. So prevent hung_check from firing by taking same approach used in blk_execute_rq(), and the wake-up interval is set as half the hung_check timer period, which keeps overhead low enough. Cc: Salman Qazi Cc: Jesse Barnes Cc: Bart Van Assche Link: https://lkml.org/lkml/2020/2/12/1193 Reported-by: Salman Qazi Reviewed-by: Jesse Barnes Reviewed-by: Salman Qazi Signed-off-by: Ming Lei Signed-off-by: Jens Axboe --- diff --git a/block/bio.c b/block/bio.c index 94d697217887..0985f3422556 100644 --- a/block/bio.c +++ b/block/bio.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "blk.h" @@ -1019,12 +1020,21 @@ static void submit_bio_wait_endio(struct bio *bio) int submit_bio_wait(struct bio *bio) { DECLARE_COMPLETION_ONSTACK_MAP(done, bio->bi_disk->lockdep_map); + unsigned long hang_check; bio->bi_private = &done; bio->bi_end_io = submit_bio_wait_endio; bio->bi_opf |= REQ_SYNC; submit_bio(bio); - wait_for_completion_io(&done); + + /* Prevent hang_check timer from firing at us during very long I/O */ + hang_check = sysctl_hung_task_timeout_secs; + if (hang_check) + while (!wait_for_completion_io_timeout(&done, + hang_check * (HZ/2))) + ; + else + wait_for_completion_io(&done); return blk_status_to_errno(bio->bi_status); }