block/dm: support bio polling
Subsystems (2)
v4 cover block/dm: support bio polling
Hi,
I've rebased Ming's latest [1] ontop of dm-5.18 [2] (which is based on for-5.18/block). End result available in dm-5.18-biopoll branch [3]
These changes add bio polling support to DM. Tested with linear and striped DM targets.
IOPS improvement was ~5% on my baremetal system with a single Intel Optane NVMe device (555K hipri=1 vs 525K hipri=0).
Ming has seen better improvement while testing within a VM:
dm-linear: hipri=1 vs hipri=0 15~20% iops improvement
dm-stripe: hipri=1 vs hipri=0 ~30% iops improvement
I'd like to merge these changes via the DM tree when the 5.18 merge window opens. The first block patch that adds ->poll_bio to block_device_operations will need review so that I can take it through the DM tree. Reason for going through the DM tree is there have been some fairly extensive changes queued in dm-5.18 that build on for-5.18/block. So I think it easiest to just add the block depenency via DM tree since DM is first consumer of ->poll_bio
FYI, Ming does have another DM patch [4] that looks to avoid using hlist but I only just saw it. bio_split() _is_ involved (see dm_split_and_process_bio) so I'm not exactly sure where he is going with that change. But that is DM-implementation detail that we'll sort out. Big thing is we need approval for the first block patch to go to Linus with the DM tree ;)
Thanks,
Mike
[1] https://github.com/ming1/linux/commits/my_v5.18-dm-bio-poll
[2] https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/log/?h=dm-5.18
[3] https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/log/?h=dm-5.18-biopoll
[4] https://github.com/ming1/linux/commit/c107c30e15041ac1ce672f56809961406e2a3e52
Ming Lei (2):
block: add ->poll_bio to block_device_operations
dm: support bio polling
block/blk-core.c | 12 +++- block/genhd.c | 2 + drivers/md/dm-core.h | 2 + drivers/md/dm-table.c | 27 +++++++++ drivers/md/dm.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++- include/linux/blkdev.h | 2 + 6 files changed, 189 insertions(+), 6 deletions(-)
Signature · 1 line
2.15.0
PATCH v4 1/2 block: add ->poll_bio to block_device_operations
From: Ming Lei <[email protected]>
Prepare for supporting IO polling for bio based driver.
Add ->poll_bio callback so that bio driver can provide their own logic for polling bio.
--- block/blk-core.c | 12 +++++++++--- block/genhd.c | 2 ++ include/linux/blkdev.h | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-)
block/blk-core.c +9 -3
@@ -985,10 +985,16 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)if (blk_queue_enter (q,BLK_MQ_REQ_NOWAIT ))return 0 ; -if (WARN_ON_ONCE (!queue_is_mq (q))) - ret =0 ;/* not yet implemented, should not happen */ -else +if (queue_is_mq (q)) { ret =blk_mq_poll (q, cookie, iob, flags); + }else { +struct gendisk *disk = q->disk; + +if (disk && disk->fops->poll_bio) + ret = disk->fops->poll_bio (bio, iob, flags); +else + ret = !WARN_ON_ONCE (1 ); + }blk_queue_exit (q);return ret; }
block/genhd.c +2 -0
@@ -410,6 +410,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,struct device *ddev =disk_to_dev (disk);int ret; +WARN_ON_ONCE (queue_is_mq (disk->queue) && disk->fops->poll_bio); +/* * The disk queue should now be all set with enough information about * the device for the elevator code to pick an adequate default
include/linux/blkdev.h +2 -0
@@ -1455,6 +1455,8 @@ enum blk_unique_id {struct block_device_operations {void (*submit_bio)(struct bio *bio); +int (*poll_bio)(struct bio *bio,struct io_comp_batch *iob, +unsigned int flags);int (*open) (struct block_device *,fmode_t );void (*release) (struct gendisk *,fmode_t );int (*rw_page)(struct block_device *,sector_t ,struct page *,unsigned int );
Signature · 1 line
2.15.0
PATCH v4 2/2 dm: support bio polling
In reply to Mike SnitzerFrom: Ming Lei <[email protected]>
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs still fallback to IRQ mode, so the target io is exactly inside the dm io.
2) hold one refcnt on io->io_count after submitting this dm bio with REQ_POLLED
3) support dm native bio splitting, any dm io instance associated with current bio will be added into one list which head is bio->bi_end_io which will be recovered before ending this bio
4) implement .poll_bio() callback, call bio_poll() on the single target bio inside the dm io which is retrieved via bio->bi_bio_drv_data; call dm_io_dec_pending() after the target io is done in .poll_bio()
5) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL, which is based on Jeffle's previous patch.
--- drivers/md/dm-core.h | 2 + drivers/md/dm-table.c | 27 +++++++++ drivers/md/dm.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 3 deletions(-)
drivers/md/dm-core.h +2 -0
@@ -235,6 +235,8 @@ struct dm_io { bool start_io_acct:1;int was_accounted;unsigned long start_time; +void *saved_bio_end_io; +struct hlist_node node;spinlock_t endio_lock;struct dm_stats_aux stats_aux;/* last member of dm_target_io is 'struct bio' */
drivers/md/dm-table.c +27 -0
@@ -1481,6 +1481,14 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)return &t->targets[(KEYS_PER_NODE * n) + k]; } +static int device_not_poll_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 !test_bit (QUEUE_FLAG_POLL , &q->queue_flags); +} +/* * type->iterate_devices() should be called when the sanity check needs to * iterate and check all underlying data devices. iterate_devices() will
@@ -1531,6 +1539,11 @@ static int count_device(struct dm_target *ti, struct dm_dev *dev,return 0 ; } +static int dm_table_supports_poll (struct dm_table *t) +{ +return !dm_table_any_dev_attr (t, device_not_poll_capable,NULL ); +} +/* * Check whether a table has no data devices attached using each * target's iterate_devices method.
@@ -2067,6 +2080,20 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,dm_update_crypto_profile (q, t);disk_update_readahead (t->md->disk); +/* +* Check for request-based device is left to +* dm_mq_init_request_queue()->blk_mq_init_allocated_queue(). +* +* For bio-based device, only set QUEUE_FLAG_POLL when all +* underlying devices supporting polling. +*/ +if (__table_type_bio_based (t->type)) { +if (dm_table_supports_poll (t)) +blk_queue_flag_set (QUEUE_FLAG_POLL , q); +else +blk_queue_flag_clear (QUEUE_FLAG_POLL , q); + } +return 0 ; }
drivers/md/dm.c +147 -3
211 lines not on this page · raw message
Signature · 1 line
2.15.0
Jens Axboe
maintainerRe: [PATCH v4 1/2] block: add ->poll_bio to block_device_operations
In reply to Mike SnitzerQuoted 10 lines · Mike Snitzer
block/blk-core.c +0
-2@@ -985,10 +985,16 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)if (blk_queue_enter (q,BLK_MQ_REQ_NOWAIT ))return 0 ; -if (WARN_ON_ONCE (!queue_is_mq (q))) - ret =0 ;/* not yet implemented, should not happen */
block/blk-core.c int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags) · line 996
Quoted 10 lines
block/blk-core.c +8
-1-else +if (queue_is_mq (q)) { ret =blk_mq_poll (q, cookie, iob, flags); + }else { +struct gendisk *disk = q->disk; + +if (disk && disk->fops->poll_bio) + ret = disk->fops->poll_bio (bio, iob, flags); +else + ret = !WARN_ON_ONCE (1 );
This is an odd way to do it, would be a lot more readable as
ret = 0; WARN_ON_ONCE(1);
if we even need that WARN_ON?
block/genhd.c int __must_check device_add_disk(struct device *parent, struct gendisk *disk, · line 413
Quoted 9 lines
block/genhd.c +1
-0@@ -410,6 +410,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,struct device *ddev =disk_to_dev (disk);int ret; +WARN_ON_ONCE (queue_is_mq (disk->queue) && disk->fops->poll_bio);
Also seems kind of useless, maybe at least combine it with failing to add the disk. This is a "I'm developing some new driver or feature" failure, and would be more visible that way. And if you do that, then the WARN_ON_ONCE() seems pointless anyway, and I'd just do:
if (queue_is_mq(disk->queue) && disk->fops->poll_bio) return -EINVAL;
or something like that, with a comment saying why that doesn't make any sense.
Signature · 1 line
Jens Axboe
Re: [PATCH v4 1/2] block: add ->poll_bio to block_device_operations
Quoted 24 lines · Jens Axboe
Quoted 10 lines · Mike Snitzer
block/blk-core.c +0
-2@@ -985,10 +985,16 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)if (blk_queue_enter (q,BLK_MQ_REQ_NOWAIT ))return 0 ; -if (WARN_ON_ONCE (!queue_is_mq (q))) - ret =0 ;/* not yet implemented, should not happen */ block/blk-core.c int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags) · line 996
Quoted 10 lines
block/blk-core.c +8
-1-else +if (queue_is_mq (q)) { ret =blk_mq_poll (q, cookie, iob, flags); + }else { +struct gendisk *disk = q->disk; + +if (disk && disk->fops->poll_bio) + ret = disk->fops->poll_bio (bio, iob, flags); +else + ret = !WARN_ON_ONCE (1 );This is an odd way to do it, would be a lot more readable as
Quoted 4 lines
ret = 0; WARN_ON_ONCE(1);if we even need that
WARN_ON?
Would be a pretty glaring oversight for a bio-based driver developer to forget to define ->poll_bio but remember to clear BLK_QC_T_NONE in bio->bi_cookie and set QUEUE_FLAG_POLL in queue flags.
Silent failure it is! ;)
Quoted 15 lines
block/genhd.c int __must_check device_add_disk(struct device *parent, struct gendisk *disk, · line 413
Quoted 9 lines
block/genhd.c +1
-0@@ -410,6 +410,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,struct device *ddev =disk_to_dev (disk);int ret; +WARN_ON_ONCE (queue_is_mq (disk->queue) && disk->fops->poll_bio);Also seems kind of useless, maybe at least combine it with failing to add the disk. This is a "I'm developing some new driver or feature" failure, and would be more visible that way. And if you do that, then the
WARN_ON_ONCE()seems pointless anyway, and I'd just do:
Quoted 5 lines
if (queue_is_mq(disk->queue) && disk->fops->poll_bio) return -EINVAL;or something like that, with a comment saying why that doesn't make any sense.
Absolutely. The thought did cross my mind that it seemed WARN_ON heavy.
Will fix it up and send v5.
Quoted 23 lines · Mike Snitzer
Hi,
I've rebased Ming's latest [1] ontop of dm-5.18 [2] (which is based on for-5.18/block). End result available in dm-5.18-biopoll branch [3]
These changes add bio polling support to DM. Tested with linear and striped DM targets.
IOPS improvement was ~5% on my baremetal system with a single Intel Optane NVMe device (555K hipri=1 vs 525K hipri=0).
Ming has seen better improvement while testing within a VM:
dm-linear: hipri=1 vs hipri=0 15~20% iops improvement
dm-stripe: hipri=1 vs hipri=0 ~30% iops improvementI'd like to merge these changes via the DM tree when the 5.18 merge window opens. The first block patch that adds ->poll_bio to
block_device_operationswill need review so that I can take it through the DM tree. Reason for going through the DM tree is there have been some fairly extensive changes queued in dm-5.18 that build on for-5.18/block. So I think it easiest to just add the block depenency via DM tree since DM is first consumer of ->poll_bio
Quoted 4 lines
FYI, Ming does have another DM patch [4] that looks to avoid using hlist but I only just saw it.
bio_split()_is_ involved (seedm_split_and_process_bio) so I'm not exactly sure where he is going with that change.
io_uring(polling) workloads often cares latency, so big IO request isn't involved usually, I guess. Then bio_split() is seldom called in dm_split_and_process_bio(), such as if 4k random IO is run on dm-linear or dm-stripe via io_uring, bio_split() won't be run into.
Single list is enough here, and efficient than hlist, just need a little care to delete element from the list since linux kernel doesn't have generic single list implementation.
Quoted 2 lines
But that is DM-implementation detail that we'll
sort out.
Yeah, that patch also needs more test.
Thanks,
Ming
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 29 lines · Ming Lei
Quoted 23 lines · Mike Snitzer
Hi,
I've rebased Ming's latest [1] ontop of dm-5.18 [2] (which is based on for-5.18/block). End result available in dm-5.18-biopoll branch [3]
These changes add bio polling support to DM. Tested with linear and striped DM targets.
IOPS improvement was ~5% on my baremetal system with a single Intel Optane NVMe device (555K hipri=1 vs 525K hipri=0).
Ming has seen better improvement while testing within a VM:
dm-linear: hipri=1 vs hipri=0 15~20% iops improvement
dm-stripe: hipri=1 vs hipri=0 ~30% iops improvementI'd like to merge these changes via the DM tree when the 5.18 merge window opens. The first block patch that adds ->poll_bio to
block_device_operationswill need review so that I can take it through the DM tree. Reason for going through the DM tree is there have been some fairly extensive changes queued in dm-5.18 that build on for-5.18/block. So I think it easiest to just add the block depenency via DM tree since DM is first consumer of ->poll_bioQuoted 4 lines
FYI, Ming does have another DM patch [4] that looks to avoid using hlist but I only just saw it.
bio_split()_is_ involved (seedm_split_and_process_bio) so I'm not exactly sure where he is going with that change.
Quoted 8 lines
io_uring(polling)workloads often cares latency, so big IO request isn't involved usually, I guess. Thenbio_split()is seldom called indm_split_and_process_bio(), such as if 4k random IO is run on dm-linear or dm-stripe viaio_uring,bio_split()won't be run into.Single list is enough here, and efficient than hlist, just need a little care to delete element from the list since linux kernel doesn't have generic single list implementation.
OK, makes sense, thanks for clarifying. But yeah its a bit fiddley for sure.
Quoted 4 lines
Quoted 2 lines
But that is DM-implementation detail that we'll
sort out.Yeah, that patch also needs more test.
Yeap, sounds good.