Re: [PATCH v3] dm-io: don't warn if flush takes too long time

From: Christoph Hellwig
Date: Wed Apr 17 2024 - 10:52:20 EST


> --- linux-2.6.orig/include/linux/completion.h 2024-04-15 15:54:22.000000000 +0200
> +++ linux-2.6/include/linux/completion.h 2024-04-15 15:57:14.000000000 +0200
> @@ -10,6 +10,7 @@
> */
>
> #include <linux/swait.h>
> +#include <linux/sched/sysctl.h>

If you're touching completion.h you need to CC lkml and the people
who wrote/maintain it even if we don't have a proper maintainer.

I don't think adding yet another include into it is a good idea.

As is this whole hack here. Pleas just add the proper TASK_STATE for
task that can legitimately sleep for very long times instead of
extending this hack again and again, just like I told Kent when he messed with the timeout.

>
> /*
> * struct completion - structure used to maintain state for a "completion"
> @@ -119,4 +120,20 @@ extern void complete(struct completion *
> extern void complete_on_current_cpu(struct completion *x);
> extern void complete_all(struct completion *);
>
> +/**
> + * wait_for_completion_long_io - this is like wait_for_completion_io,
> + * but it doesn't warn if the wait takes too long.
> + */
> +static inline void wait_for_completion_long_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);
> +}
> +
> #endif
> Index: linux-2.6/block/bio.c
> ===================================================================
> --- linux-2.6.orig/block/bio.c 2024-03-30 20:07:03.000000000 +0100
> +++ linux-2.6/block/bio.c 2024-04-15 15:55:13.000000000 +0200
> @@ -1378,7 +1378,7 @@ int submit_bio_wait(struct bio *bio)
> bio->bi_end_io = submit_bio_wait_endio;
> bio->bi_opf |= REQ_SYNC;
> submit_bio(bio);
> - blk_wait_io(&done);
> + wait_for_completion_long_io(&done);
>
> return blk_status_to_errno(bio->bi_status);
> }
> Index: linux-2.6/block/blk-mq.c
> ===================================================================
> --- linux-2.6.orig/block/blk-mq.c 2024-03-30 20:07:03.000000000 +0100
> +++ linux-2.6/block/blk-mq.c 2024-04-15 15:55:05.000000000 +0200
> @@ -1407,7 +1407,7 @@ blk_status_t blk_execute_rq(struct reque
> if (blk_rq_is_poll(rq))
> blk_rq_poll_completion(rq, &wait.done);
> else
> - blk_wait_io(&wait.done);
> + wait_for_completion_long_io(&wait.done);
>
> return wait.ret;
> }
>
>
---end quoted text---