block/dm: add REQ_NOWAIT support for bio-based
Subsystems (2)
cover block/dm: add REQ_NOWAIT support for bio-based
Hi,
I got guilted into this by this Twitter exchange:
https://twitter.com/axboe/status/1308778488011337728
Started with this patchset from June and revised it:
https://patchwork.kernel.org/project/dm-devel/list/?series=297693
(dropped MD patch while doing so_.
Tested these changes with this test Jens provided:
[mikes-test-job]
filename=/dev/dm-0
rw=randread
buffered=1
ioengine=io_uring
iodepth=16
norandommap
Jens, please feel free to pickup both patches, I don't have any conflicting DM changes for 5.10.
Thanks,
Mike
Konstantin Khlebnikov (1):
dm: add support for REQ_NOWAIT and enable it for linear target
Mike Snitzer (1):
block: add QUEUE_FLAG_NOWAIT
block/blk-core.c | 4 ++-- drivers/md/dm-linear.c | 5 +++-- drivers/md/dm-table.c | 32 ++++++++++++++++++++++++++++++++ drivers/md/dm.c | 4 +++- include/linux/blkdev.h | 7 +++++-- include/linux/device-mapper.h | 6 ++++++ 6 files changed, 51 insertions(+), 7 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/2 block: add QUEUE_FLAG_NOWAIT
Add QUEUE_FLAG_NOWAIT to allow a block device to advertise support for REQ_NOWAIT. Bio-based devices may set QUEUE_FLAG_NOWAIT where applicable.
Update QUEUE_FLAG_MQ_DEFAULT to include QUEUE_FLAG_NOWAIT. Also update submit_bio_checks() to verify it is set for REQ_NOWAIT bios.
--- block/blk-core.c | 4 ++-- include/linux/blkdev.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
block/blk-core.c +2 -2
@@ -817,9 +817,9 @@ static noinline_for_stack bool submit_bio_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 NOWAIT. */ -if ((bio->bi_opf &REQ_NOWAIT ) && !queue_is_mq (q)) +if ((bio->bi_opf &REQ_NOWAIT ) && !blk_queue_nowait (q)) goto not_supported;if (should_fail_bio (bio))
include/linux/blkdev.h +5 -2
@@ -618,10 +618,12 @@ struct request_queue {#define QUEUE_FLAG_PCI_P2PDMA 25/* device supports PCI p2p requests */ #define QUEUE_FLAG_ZONE_RESETALL 26/* supports Zone Reset All */ #define QUEUE_FLAG_RQ_ALLOC_TIME 27/* record rq->alloc_time_ns */ -#define QUEUE_FLAG_HCTX_ACTIVE 28/* at least one blk-mq hctx is active */ +#define QUEUE_FLAG_HCTX_ACTIVE 28/* at least one blk-mq hctx is active */ +#define QUEUE_FLAG_NOWAIT 29/* device supports NOWAIT */ #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ - (1 << QUEUE_FLAG_SAME_COMP)) + (1 << QUEUE_FLAG_SAME_COMP) | \ + (1 << QUEUE_FLAG_NOWAIT))void blk_queue_flag_set (unsigned int flag,struct request_queue *q);void blk_queue_flag_clear (unsigned int flag,struct request_queue *q);
@@ -661,6 +663,7 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);#define blk_queue_pm_only (q) atomic_read(&(q)->pm_only)#define blk_queue_fua (q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags)#define blk_queue_registered (q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags) +#define blk_queue_nowait (q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags)extern void blk_set_pm_only (struct request_queue *q);extern void blk_clear_pm_only (struct request_queue *q);
Signature · 1 line
2.15.0
Re: [PATCH 1/2] block: add QUEUE_FLAG_NOWAIT
Quoted 10 lines · Mike Snitzer
Add
QUEUE_FLAG_NOWAITto allow a block device to advertise support forREQ_NOWAIT. Bio-based devices may setQUEUE_FLAG_NOWAITwhere applicable.Update
QUEUE_FLAG_MQ_DEFAULTto includeQUEUE_FLAG_NOWAIT. Also updatesubmit_bio_checks()to verify it is set forREQ_NOWAITbios.Reported-by Konstantin Khlebnikov <[email protected]>Suggested-by Christoph Hellwig <[email protected]>Signed-off-by Mike Snitzer <[email protected]>
Looks good:
PATCH 2/2 dm: add support for REQ_NOWAIT and enable it for linear target
In reply to Mike SnitzerFrom: Konstantin Khlebnikov <[email protected]>
Add DM target feature flag DM_TARGET_NOWAIT which advertises that target works with REQ_NOWAIT bios.
Add dm_table_supports_nowait() and update dm_table_set_restrictions() to set/clear QUEUE_FLAG_NOWAIT accordingly.
--- drivers/md/dm-linear.c | 5 +++-- drivers/md/dm-table.c | 32 ++++++++++++++++++++++++++++++++ drivers/md/dm.c | 4 +++- include/linux/device-mapper.h | 6 ++++++ 4 files changed, 44 insertions(+), 3 deletions(-)
drivers/md/dm-linear.c +3 -2
@@ -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 +32 -0
@@ -1719,6 +1719,33 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t)return true; } +static int device_not_nowait_capable (struct dm_target *ti,struct dm_dev *dev, +sector_t start,sector_t len,void *data) +{ +struct request_queue *q =bdev_get_queue (dev->bdev); + +return q && !blk_queue_nowait (q); +} + +static bool dm_table_supports_nowait (struct dm_table *t) +{ +struct dm_target *ti; +unsigned i =0 ; + +while (i <dm_table_get_num_targets (t)) { + ti =dm_table_get_target (t, i++); + +if (!dm_target_supports_nowait (ti->type)) +return false; + +if (!ti->type->iterate_devices || + ti->type->iterate_devices (ti, device_not_nowait_capable,NULL )) +return false; + } + +return true; +} +static int device_not_discard_capable (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {
@@ -1821,6 +1848,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,*/ q->limits = *limits; +if (dm_table_supports_nowait (t)) +blk_queue_flag_set (QUEUE_FLAG_NOWAIT , q); +else +blk_queue_flag_clear (QUEUE_FLAG_NOWAIT , q); +if (!dm_table_supports_discards (t)) {blk_queue_flag_clear (QUEUE_FLAG_DISCARD , q);/* Must also clear discard limits... */
drivers/md/dm.c +3 -1
@@ -1733,7 +1733,9 @@ static blk_qc_t dm_submit_bio(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
@@ -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;
Signature · 1 line
2.15.0
Jens Axboe
maintainerQuoted 19 lines · Mike Snitzer
Hi,
I got guilted into this by this Twitter exchange:
https://twitter.com/axboe/status/1308778488011337728Started with this patchset from June and revised it:
https://patchwork.kernel.org/project/dm-devel/list/?series=297693
(dropped MD patch while doingso_.Tested these changes with this test Jens provided:
[mikes-test-job]
filename=/dev/dm-0
rw=randread
buffered=1
ioengine=io_uring
iodepth=16
norandommap
Quoted 2 lines
Jens, please feel free to pickup both patches, I don't have any conflicting DM changes for 5.10.
Thanks Mike! Applied.
Signature · 1 line
Jens Axboe