block: io wait hang check helper
authorKeith Busch <kbusch@kernel.org>
Fri, 23 Feb 2024 15:59:09 +0000 (07:59 -0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 24 Feb 2024 19:46:46 +0000 (12:46 -0700)
This is the same in two places, and another will be added soon. Create a
helper for it.

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20240223155910.3622666-4-kbusch@meta.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
block/blk-mq.c
block/blk.h

index 00847ff1415c322c58b370d85ac528624ad85db5..496867b51609f7a9dbca22f333fc66ab09fc249a 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/workqueue.h>
 #include <linux/cgroup.h>
 #include <linux/highmem.h>
-#include <linux/sched/sysctl.h>
 #include <linux/blk-crypto.h>
 #include <linux/xarray.h>
 
@@ -1371,21 +1370,12 @@ int submit_bio_wait(struct bio *bio)
 {
        DECLARE_COMPLETION_ONSTACK_MAP(done,
                        bio->bi_bdev->bd_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);
-
-       /* 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);
+       blk_wait_io(&done);
 
        return blk_status_to_errno(bio->bi_status);
 }
index 6abb4ce46baa1ee20118d227084cee9169964805..45f994c100446ca6c5df00e8737989a9563ddc5c 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/llist.h>
 #include <linux/cpu.h>
 #include <linux/cache.h>
-#include <linux/sched/sysctl.h>
 #include <linux/sched/topology.h>
 #include <linux/sched/signal.h>
 #include <linux/delay.h>
@@ -1409,22 +1408,10 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head)
        blk_mq_insert_request(rq, at_head ? BLK_MQ_INSERT_AT_HEAD : 0);
        blk_mq_run_hw_queue(hctx, false);
 
-       if (blk_rq_is_poll(rq)) {
+       if (blk_rq_is_poll(rq))
                blk_rq_poll_completion(rq, &wait.done);
-       } else {
-               /*
-                * Prevent hang_check timer from firing at us during very long
-                * I/O
-                */
-               unsigned long hang_check = sysctl_hung_task_timeout_secs;
-
-               if (hang_check)
-                       while (!wait_for_completion_io_timeout(&wait.done,
-                                       hang_check * (HZ/2)))
-                               ;
-               else
-                       wait_for_completion_io(&wait.done);
-       }
+       else
+               blk_wait_io(&wait.done);
 
        return wait.ret;
 }
index 7c30e2ac8ebcd3df91add2353e7d793b02e0a4c9..6c2749d122ab542e026f505f36dc9607e1627d6c 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <linux/blk-crypto.h>
 #include <linux/memblock.h>    /* for max_pfn/max_low_pfn */
+#include <linux/sched/sysctl.h>
 #include <linux/timekeeping.h>
 #include <xen/xen.h>
 #include "blk-crypto-internal.h"
@@ -71,6 +72,18 @@ static inline int bio_queue_enter(struct bio *bio)
        return __bio_queue_enter(q, bio);
 }
 
+static inline void blk_wait_io(struct completion *done)
+{
+       /* 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)
+               while (!wait_for_completion_io_timeout(done, timeout))
+                       ;
+       else
+               wait_for_completion_io(done);
+}
+
 #define BIO_INLINE_VECS 4
 struct bio_vec *bvec_alloc(mempool_t *pool, unsigned short *nr_vecs,
                gfp_t gfp_mask);