public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] block: Add a workaround for the miss wakeup problem
@ 2025-06-23 11:10 Fengnan Chang
  2025-06-23 14:16 ` Christoph Hellwig
  2025-06-23 15:08 ` Keith Busch
  0 siblings, 2 replies; 5+ messages in thread
From: Fengnan Chang @ 2025-06-23 11:10 UTC (permalink / raw)
  To: axboe, linux-block; +Cc: Fengnan Chang

Some io hang problems are caused by miss wakeup, and these cases could
be mitigated if io_schedule could be replaced with io_schedule_timeout.
By default, the io_schedule is still executed, and in the case of
problems, a workaround solution can be turned on by
modify io_schedule_timeout_msecs.

Signed-off-by: Fengnan Chang <changfengnan@bytedance.com>
---
 block/blk-core.c       | 33 +++++++++++++++++++++++++++++++++
 block/blk-iocost.c     |  2 +-
 block/blk-mq-tag.c     |  2 +-
 block/blk-rq-qos.c     |  2 +-
 include/linux/blkdev.h |  2 ++
 5 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index fdac48aec5ef..722a32f98b95 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -62,6 +62,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_insert);
 
 static DEFINE_IDA(blk_queue_ida);
 
+static unsigned long __read_mostly sysctl_io_schedule_timeout_msecs;
+
 /*
  * For queue allocation
  */
@@ -72,6 +74,18 @@ static struct kmem_cache *blk_requestq_cachep;
  */
 static struct workqueue_struct *kblockd_workqueue;
 
+#ifdef CONFIG_SYSCTL
+static const struct ctl_table kernel_io_schedule_timeout_table[] = {
+	{
+		.procname	= "io_schedule_timeout_msecs",
+		.data		= &sysctl_io_schedule_timeout_msecs,
+		.maxlen		= sizeof(sysctl_io_schedule_timeout_msecs),
+		.mode		= 0644,
+		.proc_handler	= proc_doulongvec_minmax,
+	},
+};
+#endif
+
 /**
  * blk_queue_flag_set - atomically set a queue flag
  * @flag: flag to be set
@@ -1250,6 +1264,21 @@ void blk_finish_plug(struct blk_plug *plug)
 }
 EXPORT_SYMBOL(blk_finish_plug);
 
+/**
+ * Maybe it can be integrated into blk_io_schedule?
+ */
+void blk_io_schedule_timeout(void)
+{
+	/* Prevent hang_check timer from firing at us during very long I/O */
+	unsigned long timeout = msecs_to_jiffies(sysctl_io_schedule_timeout_msecs);
+
+	if (timeout)
+		io_schedule_timeout(timeout);
+	else
+		io_schedule();
+}
+EXPORT_SYMBOL_GPL(blk_io_schedule_timeout);
+
 void blk_io_schedule(void)
 {
 	/* Prevent hang_check timer from firing at us during very long I/O */
@@ -1280,5 +1309,9 @@ int __init blk_dev_init(void)
 
 	blk_debugfs_root = debugfs_create_dir("block", NULL);
 
+#ifdef CONFIG_SYSCTL
+	register_sysctl_init("kernel", kernel_io_schedule_timeout_table);
+#endif
+
 	return 0;
 }
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 5bfd70311359..56aac7ac7a71 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -2732,7 +2732,7 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		if (wait.committed)
 			break;
-		io_schedule();
+		blk_io_schedule_timeout();
 	}
 
 	/* waker already committed us, proceed */
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index d880c50629d6..892704292005 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -185,7 +185,7 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
 			break;
 
 		bt_prev = bt;
-		io_schedule();
+		blk_io_schedule_timeout();
 
 		sbitmap_finish_wait(bt, ws, &wait);
 
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 848591fb3c57..5c81e863c092 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -306,7 +306,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
 	do {
 		if (data.got_token)
 			break;
-		io_schedule();
+		blk_io_schedule_timeout();
 		set_current_state(TASK_UNINTERRUPTIBLE);
 	} while (1);
 	finish_wait(&rqw->wait, &data.wq);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index a59880c809c7..e58353c8523e 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1170,6 +1170,8 @@ static inline long nr_blockdev_pages(void)
 
 extern void blk_io_schedule(void);
 
+extern void blk_io_schedule_timeout(void);
+
 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		sector_t nr_sects, gfp_t gfp_mask);
 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] block: Add a workaround for the miss wakeup problem
  2025-06-23 11:10 [RFC PATCH] block: Add a workaround for the miss wakeup problem Fengnan Chang
@ 2025-06-23 14:16 ` Christoph Hellwig
  2025-06-23 15:08 ` Keith Busch
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2025-06-23 14:16 UTC (permalink / raw)
  To: Fengnan Chang; +Cc: axboe, linux-block

On Mon, Jun 23, 2025 at 07:10:21PM +0800, Fengnan Chang wrote:
> Some io hang problems are caused by miss wakeup,

Please fix the missing wakeup instead.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] block: Add a workaround for the miss wakeup problem
  2025-06-23 11:10 [RFC PATCH] block: Add a workaround for the miss wakeup problem Fengnan Chang
  2025-06-23 14:16 ` Christoph Hellwig
@ 2025-06-23 15:08 ` Keith Busch
  2025-06-23 15:16   ` Bart Van Assche
  1 sibling, 1 reply; 5+ messages in thread
From: Keith Busch @ 2025-06-23 15:08 UTC (permalink / raw)
  To: Fengnan Chang; +Cc: axboe, linux-block

On Mon, Jun 23, 2025 at 07:10:21PM +0800, Fengnan Chang wrote:
> Some io hang problems are caused by miss wakeup, and these cases could

Wait a second, what's the cause of the missed wakeup? I don't think that
should ever happen, so let's get the details on that first.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] block: Add a workaround for the miss wakeup problem
  2025-06-23 15:08 ` Keith Busch
@ 2025-06-23 15:16   ` Bart Van Assche
  2025-06-24  9:33     ` [External] " Fengnan Chang
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2025-06-23 15:16 UTC (permalink / raw)
  To: Keith Busch, Fengnan Chang; +Cc: axboe, linux-block

On 6/23/25 8:08 AM, Keith Busch wrote:
> On Mon, Jun 23, 2025 at 07:10:21PM +0800, Fengnan Chang wrote:
>> Some io hang problems are caused by miss wakeup, and these cases could
> 
> Wait a second, what's the cause of the missed wakeup? I don't think that
> should ever happen, so let's get the details on that first.

+1

Additionally, there is not enough information in the patch description
to conclude whether the root cause is in the block layer core or in an
(out-of-tree?) block driver.

Bart.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [External] Re: [RFC PATCH] block: Add a workaround for the miss wakeup problem
  2025-06-23 15:16   ` Bart Van Assche
@ 2025-06-24  9:33     ` Fengnan Chang
  0 siblings, 0 replies; 5+ messages in thread
From: Fengnan Chang @ 2025-06-24  9:33 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Keith Busch, axboe, linux-block

Sorry, I didn't explain clearly that this patch is not meant to solve a known
problem, but to have a workaround in case something like miss wakeup
comes up in the future.

There have been some miss wakeup issues in the past, and I wanted to
provide a way to alleviate the problem.

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/block?h=linux-6.15.y&id=5266caaf5660529e3da53004b8b7174cab6374ed
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/block?h=linux-6.15.y&id=abab13b5c4fd1fec4f9a61622548012d93dc2831
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/block?h=linux-6.15.y&id=98b99e9412d0cde8c7b442bf5efb09528a2ede8b

Bart Van Assche <bvanassche@acm.org> 于2025年6月23日周一 23:16写道:
>
> On 6/23/25 8:08 AM, Keith Busch wrote:
> > On Mon, Jun 23, 2025 at 07:10:21PM +0800, Fengnan Chang wrote:
> >> Some io hang problems are caused by miss wakeup, and these cases could
> >
> > Wait a second, what's the cause of the missed wakeup? I don't think that
> > should ever happen, so let's get the details on that first.
>
> +1
>
> Additionally, there is not enough information in the patch description
> to conclude whether the root cause is in the block layer core or in an
> (out-of-tree?) block driver.
>
> Bart.
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-24  9:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 11:10 [RFC PATCH] block: Add a workaround for the miss wakeup problem Fengnan Chang
2025-06-23 14:16 ` Christoph Hellwig
2025-06-23 15:08 ` Keith Busch
2025-06-23 15:16   ` Bart Van Assche
2025-06-24  9:33     ` [External] " Fengnan Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox