Skip to contentSkip to conversation

block: allow REQ_NOWAIT to some bio-based/stacked devices

RFC PATCH In review Konstantin Khlebnikov 2 participants 6 messages Jun 1, 2020 – Jun 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover block: allow REQ_NOWAIT to some bio-based/stacked devices

Here is pretty straight forward attempt of handling REQ_NOWAIT for bio-based and stacked devices.

They are marked with flag queue->limits.nowait_requests which tells that queue method make_request() handles REQ_NOWAIT or doesn't delay requests, and all backend devices do the same.

As a example second/third patches add support into md-raid0 and dm-linear.

---

Konstantin Khlebnikov (3):
block: add flag 'nowait_requests' into queue limits md/raid0: enable REQ_NOWAIT
dm: add support for REQ_NOWAIT and enable for target dm-linear

 drivers/md/dm-linear.c        | 5 +++--
 drivers/md/dm-table.c         | 3 +++
 drivers/md/dm.c               | 4 +++-
 drivers/md/raid0.c            | 3 +++
 include/linux/device-mapper.h | 6 ++++++
 5 files changed, 18 insertions(+), 3 deletions(-)

--
Signature

#1 lore raw

RFC PATCH 1/3 block: add flag 'nowait_requests' into queue limits

Add flag for marking bio-based queues which support REQ_NOWAIT. Set for all request based (mq) devices.

Stacking device should set it after blk_set_stacking_limits() if method make_request() itself doesn't delay requests or handles REQ_NOWAIT.

---
 block/blk-core.c       |    4 ++--
 block/blk-mq.c         |    3 +++
 block/blk-settings.c   |    3 +++
 include/linux/blkdev.h |    1 +
 4 files changed, 9 insertions(+), 2 deletions(-)
block/blk-core.c +2 -2
index c4b015004796..9139a316e6d4 100644
@@ -892,9 +892,9 @@ generic_make_request_checks(struct bio *bio)
 
 	/*
 	 * For a REQ_NOWAIT based request, return -EOPNOTSUPP
-	 * if queue is not a request based queue.
+	 * if queue does not support this flag.
 	 */
-	if ((bio->bi_opf & REQ_NOWAIT) && !queue_is_mq(q))
+	if ((bio->bi_opf & REQ_NOWAIT) && !q->limits.nowait_requests)
 		goto not_supported;
 
 	if (should_fail_bio(bio))
block/blk-mq.c +3 -0
index a7785df2c944..0c3daa0cda87 100644
@@ -2952,6 +2952,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 	 */
 	q->poll_nsec = BLK_MQ_POLL_CLASSIC;
 
+	/* Request based queue always supports REQ_NOWAIT */
+	q->limits.nowait_requests = 1;
+
 	blk_mq_init_cpu_queues(q, set->nr_hw_queues);
 	blk_mq_add_queue_tag_set(set, q);
 	blk_mq_map_swqueue(q);
block/blk-settings.c +3 -0
index 14397b4c4b53..8f96c7324497 100644
@@ -59,6 +59,7 @@ void blk_set_default_limits(struct queue_limits *lim)
 	lim->io_opt = 0;
 	lim->misaligned = 0;
 	lim->zoned = BLK_ZONED_NONE;
+	lim->nowait_requests = 0;
 }
 EXPORT_SYMBOL(blk_set_default_limits);
 
@@ -486,6 +487,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
 	t->max_segment_size = min_not_zero(t->max_segment_size,
 					   b->max_segment_size);
 
+	t->nowait_requests &= b->nowait_requests;
+
 	t->misaligned |= b->misaligned;
 
 	alignment = queue_limit_alignment_offset(b, start);
include/linux/blkdev.h +1 -0
index 32868fbedc9e..5f612dda34c2 100644
@@ -346,6 +346,7 @@ struct queue_limits {
 	unsigned char		misaligned;
 	unsigned char		discard_misaligned;
 	unsigned char		raid_partial_stripes_expensive;
+	unsigned char		nowait_requests;
 	enum blk_zoned_model	zoned;
 };
 
#2 lore raw

Re: [PATCH RFC 1/3] block: add flag 'nowait_requests' into queue limits

Quoted 5 lines · Konstantin Khlebnikov

Add flag for marking bio-based queues which support REQ_NOWAIT. Set for all request based (mq) devices.

Stacking device should set it after blk_set_stacking_limits() if method make_request() itself doesn't delay requests or handles REQ_NOWAIT.

I don't think this belongs into the queue limits. For example a stacking driver that always defers requests to a workqueue can support REQ_NOWAIT entirely independent of the underlying devices. I think this just needs to be a simple queue flag.

#3 lore raw

Re: [PATCH RFC 1/3] block: add flag 'nowait_requests' into queue limits

Quoted 4 lines · Christoph Hellwig
Quoted 3 lines · Konstantin Khlebnikov

Add flag for marking bio-based queues which support REQ_NOWAIT. Set for all request based (mq) devices.

Quoted 8 lines
Quoted 2 lines

Stacking device should set it after blk_set_stacking_limits() if method make_request() itself doesn't delay requests or handles REQ_NOWAIT.

I don't think this belongs into the queue limits. For example a stacking driver that always defers requests to a workqueue can support REQ_NOWAIT entirely independent of the underlying devices. I think this just needs to be a simple queue flag.

For O_DIRECT I/O REQ_NOWAIT not just about non-blocking submition. It also provides instant feedback about contention. Like ECN from network. This feedback is useful for rate-control and balancing load between replicas.

If upper layer simply remaps and forwards requests below then to forward contention all layers of stacked device should support this feature. That's why I've put it as flag into limits - to reuse limits stacking.

If any layer defers request, then it should somehow limit size of backlog at the same time to provide sane behaviour for REQ_NOWAIT regardless of behaviour lower devices. So, then it could simply set that flag in limits.

Also I want to add handing into blk-qos/throttler - never delay REQ_NOWAIT.

#4 lore raw

RFC PATCH 2/3 md/raid0: enable REQ_NOWAIT

In reply to Konstantin Khlebnikov

Set limits.nowait_requests = 1 before stacking limits. Raid itself does not delay bio in raid0_make_request().

---
 drivers/md/raid0.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/md/raid0.c +3 -0
index 322386ff5d22..e34292b05488 100644
@@ -406,6 +406,9 @@ static int raid0_run(struct mddev *mddev)
 		blk_queue_io_opt(mddev->queue,
 				 (mddev->chunk_sectors << 9) * mddev->raid_disks);
 
+		/* raid0_make_request() does not delay requests */
+		mddev->queue->limits.nowait_requests = 1;
+
 		rdev_for_each(rdev, mddev) {
 			disk_stack_limits(mddev->gendisk, rdev->bdev,
 					  rdev->data_offset << 9);
#5 lore raw

RFC PATCH 3/3 dm: add support for REQ_NOWAIT and enable for target dm-linear

In reply to Konstantin Khlebnikov

Add dm target feature flag DM_TARGET_NOWAIT which tells that target has no problem with REQ_NOWAIT.

Set limits.nowait_requests if all targets and backends handle REQ_NOWAIT.

---
 drivers/md/dm-linear.c        |    5 +++--
 drivers/md/dm-table.c         |    3 +++
 drivers/md/dm.c               |    4 +++-
 include/linux/device-mapper.h |    6 ++++++
 4 files changed, 15 insertions(+), 3 deletions(-)
drivers/md/dm-linear.c +3 -2
index e1db43446327..00774b5d7668 100644
@@ -228,10 +228,11 @@ static struct target_type linear_target = {
 	.name   = "linear",
 	.version = {1, 4, 0},
 #ifdef CONFIG_BLK_DEV_ZONED
-	.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_ZONED_HM,
+	.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
+		    DM_TARGET_ZONED_HM,
 	.report_zones = linear_report_zones,
 #else
-	.features = DM_TARGET_PASSES_INTEGRITY,
+	.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT,
 #endif
 	.module = THIS_MODULE,
 	.ctr    = linear_ctr,
drivers/md/dm-table.c +3 -0
index 0a2cc197f62b..f4610f79ebd6 100644
@@ -1500,12 +1500,15 @@ int dm_calculate_queue_limits(struct dm_table *table,
 	unsigned int zone_sectors = 0;
 
 	blk_set_stacking_limits(limits);
+	limits->nowait_requests = 1;
 
 	for (i = 0; i < dm_table_get_num_targets(table); i++) {
 		blk_set_stacking_limits(&ti_limits);
 
 		ti = dm_table_get_target(table, i);
 
+		ti_limits.nowait_requests = dm_target_supports_nowait(ti->type);
+
 		if (!ti->type->iterate_devices)
 			goto combine_limits;
 
drivers/md/dm.c +3 -1
index db9e46114653..767cd4d70341 100644
@@ -1794,7 +1794,9 @@ static blk_qc_t dm_make_request(struct request_queue *q, struct bio *bio)
 	if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) {
 		dm_put_live_table(md, srcu_idx);
 
-		if (!(bio->bi_opf & REQ_RAHEAD))
+		if (bio->bi_opf & REQ_NOWAIT)
+			bio_wouldblock_error(bio);
+		else if (!(bio->bi_opf & REQ_RAHEAD))
 			queue_io(md, bio);
 		else
 			bio_io_error(bio);
include/linux/device-mapper.h +6 -0
index af48d9da3916..4d4af1eeeba4 100644
@@ -252,6 +252,12 @@ struct target_type {
 #define DM_TARGET_ZONED_HM		0x00000040
 #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)
 
+/*
+ * A target handles REQ_NOWAIT
+ */
+#define DM_TARGET_NOWAIT		0x00000080
+#define dm_target_supports_nowait(type) (!!((type)->features & DM_TARGET_NOWAIT))
+
 struct dm_target {
 	struct dm_table *table;
 	struct target_type *type;