Hello Guys,
Based on Christoph's bio based polling model[1], implement DM bio polling
with one very simple approach.
Patch 1 adds helper of blk_queue_poll().
Patch 2 adds .bio_poll() callback to block_device_operations, so bio
driver can implement its own logic for io polling.
Patch 3 implements bio polling for device mapper.
Any comments are welcome.
V2:
- drop patch to add new fields into bio
- support io polling for dm native bio splitting
- add comment
Ming Lei (3):
block: add helper of blk_queue_poll
block: add ->poll_bio to block_device_operations
dm: support bio polling
block/blk-core.c | 21 +++++---
block/blk-sysfs.c | 4 +-
block/genhd.c | 3 ++
drivers/md/dm-table.c | 24 +++++++++
drivers/md/dm.c | 111 +++++++++++++++++++++++++++++++++++++--
drivers/nvme/host/core.c | 2 +-
include/linux/blkdev.h | 3 ++
7 files changed, 155 insertions(+), 13 deletions(-)
--
2.31.1
There has been 3 users, and will be more, so add one such helper.
Reviewed-by: Chaitanya Kulkarni <redacted>
Reviewed-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Ming Lei <redacted>
---
block/blk-core.c | 5 ++---
block/blk-sysfs.c | 4 ++--
drivers/nvme/host/core.c | 2 +-
include/linux/blkdev.h | 1 +
4 files changed, 6 insertions(+), 6 deletions(-)
@@ -835,7 +835,7 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio)}}-if(!test_bit(QUEUE_FLAG_POLL,&q->queue_flags))+if(!blk_queue_poll(q))bio->bi_opf&=~REQ_POLLED;switch(bio_op(bio)){
@@ -1117,8 +1117,7 @@ int bio_poll(struct bio *bio, unsigned int flags)blk_qc_tcookie=READ_ONCE(bio->bi_cookie);intret;-if(cookie==BLK_QC_T_NONE||-!test_bit(QUEUE_FLAG_POLL,&q->queue_flags))+if(cookie==BLK_QC_T_NONE||!blk_queue_poll(q))return0;if(current->plug)
@@ -422,13 +422,13 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,staticssize_tqueue_poll_show(structrequest_queue*q,char*page){-returnqueue_var_show(test_bit(QUEUE_FLAG_POLL,&q->queue_flags),page);+returnqueue_var_show(blk_queue_poll(q),page);}staticssize_tqueue_poll_store(structrequest_queue*q,constchar*page,size_tcount){-if(!test_bit(QUEUE_FLAG_POLL,&q->queue_flags))+if(!blk_queue_poll(q))return-EINVAL;pr_info_ratelimited("writes to the poll attribute are ignored.\n");pr_info_ratelimited("please use driver specific parameters instead.\n");
From: Christoph Hellwig <hch@lst.de> Date: 2021-06-21 07:20:40
On Thu, Jun 17, 2021 at 06:35:47PM +0800, Ming Lei wrote:
There has been 3 users, and will be more, so add one such helper.
Reviewed-by: Chaitanya Kulkarni <redacted>
Reviewed-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Ming Lei <redacted>
I still don't like hiding a simple flag test like this, it just adds
another step to grepping what is going on.
On Mon, Jun 21, 2021 at 09:20:36AM +0200, Christoph Hellwig wrote:
On Thu, Jun 17, 2021 at 06:35:47PM +0800, Ming Lei wrote:
quoted
There has been 3 users, and will be more, so add one such helper.
Reviewed-by: Chaitanya Kulkarni <redacted>
Reviewed-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Ming Lei <redacted>
I still don't like hiding a simple flag test like this, it just adds
another step to grepping what is going on.
It is actually one pattern in block layer since there is so many such
macros of blk_queue_*. And it makes the check line shorter.
Thanks,
Ming
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.
Signed-off-by: Ming Lei <redacted>
---
block/blk-core.c | 18 +++++++++++++-----
block/genhd.c | 3 +++
include/linux/blkdev.h | 2 ++
3 files changed, 18 insertions(+), 5 deletions(-)
@@ -1125,10 +1127,16 @@ int bio_poll(struct bio *bio, unsigned int flags)if(blk_queue_enter(q,BLK_MQ_REQ_NOWAIT))return0;-if(WARN_ON_ONCE(!queue_is_mq(q)))-ret=0;/* not yet implemented, should not happen */-else+if(!queue_is_mq(q)){+if(disk->fops->poll_bio){+ret=disk->fops->poll_bio(bio,flags);+}else{+WARN_ON_ONCE(1);+ret=0;+}+}else{ret=blk_mq_poll(q,cookie,flags);+}blk_queue_exit(q);returnret;}
@@ -471,6 +471,9 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,{intret;+/* ->poll_bio is only for bio based driver */+WARN_ON_ONCE(queue_is_mq(disk->queue)&&disk->fops->poll_bio);+/**Thediskqueueshouldnowbeallsetwithenoughinformationabout*thedevicefortheelevatorcodetopickanadequatedefault
@@ -1858,6 +1858,8 @@ static inline void blk_ksm_unregister(struct request_queue *q) { }structblock_device_operations{void(*submit_bio)(structbio*bio);+/* ->poll_bio is for bio driver only */+int(*poll_bio)(structbio*bio,unsignedintflags);int(*open)(structblock_device*,fmode_t);void(*release)(structgendisk*,fmode_t);int(*rw_page)(structblock_device*,sector_t,structpage*,unsignedint);
How does polling for a bio without a cookie make sense even when
polling bio based?
But if we come up for a good rationale for this I'd really
split the conditions to make them more readable:
if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
return 0;
if (queue_is_mq(q) && cookie == BLK_QC_T_NONE)
return 0;
+ if (!queue_is_mq(q)) {
+ if (disk->fops->poll_bio) {
+ ret = disk->fops->poll_bio(bio, flags);
+ } else {
+ WARN_ON_ONCE(1);
+ ret = 0;
+ }
+ } else {
ret = blk_mq_poll(q, cookie, flags);
I'd go for someting like:
if (queue_is_mq(q))
ret = blk_mq_poll(q, cookie, flags);
else if (disk->fops->poll_bio)
ret = disk->fops->poll_bio(bio, flags);
else
WARN_ON_ONCE(1);
with ret initialized to 0 at declaration time.
struct block_device_operations {
void (*submit_bio)(struct bio *bio);
+ /* ->poll_bio is for bio driver only */
I'd drop the comment, this is already nicely documented in add_disk
together with the actual check. We also don't note this for submit_bio
here.
How does polling for a bio without a cookie make sense even when
polling bio based?
It isn't necessary to use bio->bi_cookie, that is why I doesn't use it,
which actually provides one free 32bit in bio for bio based driver.
But if we come up for a good rationale for this I'd really
split the conditions to make them more readable:
if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
return 0;
if (queue_is_mq(q) && cookie == BLK_QC_T_NONE)
return 0;
OK.
quoted
+ if (!queue_is_mq(q)) {
+ if (disk->fops->poll_bio) {
+ ret = disk->fops->poll_bio(bio, flags);
+ } else {
+ WARN_ON_ONCE(1);
+ ret = 0;
+ }
+ } else {
ret = blk_mq_poll(q, cookie, flags);
I'd go for someting like:
if (queue_is_mq(q))
ret = blk_mq_poll(q, cookie, flags);
else if (disk->fops->poll_bio)
ret = disk->fops->poll_bio(bio, flags);
else
WARN_ON_ONCE(1);
with ret initialized to 0 at declaration time.
Fine.
quoted
struct block_device_operations {
void (*submit_bio)(struct bio *bio);
+ /* ->poll_bio is for bio driver only */
I'd drop the comment, this is already nicely documented in add_disk
together with the actual check. We also don't note this for submit_bio
here.
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
drivers/md/dm-table.c | 24 +++++++++
drivers/md/dm.c | 111 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 132 insertions(+), 3 deletions(-)
@@ -938,8 +945,12 @@ static void dec_pending(struct dm_io *io, blk_status_t error)end_io_acct(io);free_io(md,io);-if(io_error==BLK_STS_DM_REQUEUE)+if(io_error==BLK_STS_DM_REQUEUE){+/* not poll any more in case of requeue */+if(bio->bi_opf&REQ_POLLED)+bio->bi_opf&=~REQ_POLLED;return;+}if((bio->bi_opf&REQ_PREFLUSH)&&bio->bi_iter.bi_size){/*
@@ -1590,6 +1601,12 @@ static int __split_and_process_non_flush(struct clone_info *ci)if(__process_abnormal_io(ci,ti,&r))returnr;+/*+*OnlysupportbiopollingfornormalIO,andthetargetiois+*exactlyinsidethedmioinstance+*/+ci->io->submit_as_polled=!!(ci->bio->bi_opf&REQ_POLLED);+len=min_t(sector_t,max_io_len(ti,ci->sector),ci->sector_count);r=__clone_and_map_data_bio(ci,ti,ci->sector,&len);
@@ -1666,8 +1699,19 @@ static void __split_and_process_bio(struct mapped_device *md,}}-/* drop the extra reference count */-dec_pending(ci.io,errno_to_blk_status(error));+/*+*Droptheextrareferencecountfornon-POLLEDbio,andholdone+*referenceforPOLLEDbio,whichwillbereleasedindm_poll_bio+*+*Addeverydm_ioinstanceintothehlist_headwhichisstoredin+*bio->bi_end_io,sothatdm_poll_biocanpollthemall.+*/+if(!ci.io->submit_as_polled)+dec_pending(ci.io,errno_to_blk_status(error));+else+hlist_add_head(&ci.io->node,+(structhlist_head*)&bio->bi_end_io);+}staticvoiddm_submit_bio(structbio*bio)
@@ -1707,6 +1751,66 @@ static void dm_submit_bio(struct bio *bio)dm_put_live_table(md,srcu_idx);}+staticintdm_poll_dm_io(structdm_io*io,unsignedintflags)+{+if(!io||!io->submit_as_polled)+return0;++WARN_ON_ONCE(!io->tio.inside_dm_io);+bio_poll(&io->tio.clone,flags);++/* bio_poll holds the last reference */+if(atomic_read(&io->io_count)==1)+return1;+return0;+}++staticintdm_poll_bio(structbio*bio,unsignedintflags)+{+structdm_io*io;+void*saved_bi_end_io=NULL;+structhlist_headtmp=HLIST_HEAD_INIT;+structhlist_head*head=(structhlist_head*)&bio->bi_end_io;+structhlist_node*next;++/*+*ThisbiocanbesubmittedfromFSasPOLLEDsothatFSmaykeep+*pollingeventhoughtheflagisclearedbybiosplittingor+*requeue,soreturnimmediately.+*/+if(!(bio->bi_opf&REQ_POLLED))+return0;++hlist_move_list(head,&tmp);++hlist_for_each_entry(io,&tmp,node){+if(io->saved_bio_end_io&&!saved_bi_end_io){+saved_bi_end_io=io->saved_bio_end_io;+break;+}+}++/* restore .bi_end_io before completing dm io */+WARN_ON_ONCE(!saved_bi_end_io);+bio->bi_end_io=saved_bi_end_io;++hlist_for_each_entry_safe(io,next,&tmp,node){+if(dm_poll_dm_io(io,flags)){+hlist_del_init(&io->node);+dec_pending(io,0);+}+}++/* Not done, make sure at least one dm_io stores the .bi_end_io*/+if(!hlist_empty(&tmp)){+io=hlist_entry(tmp.first,structdm_io,node);+io->saved_bio_end_io=saved_bi_end_io;+hlist_move_list(&tmp,head);+return0;+}+return1;+}+/*-----------------------------------------------------------------*AnIDRisusedtokeeptrackofallocatedminornumbers.*---------------------------------------------------------------*/
On Thu, Jun 17, 2021 at 06:35:49PM +0800, Ming Lei wrote:
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
...
quoted hunk
@@ -938,8 +945,12 @@ static void dec_pending(struct dm_io *io, blk_status_t error) end_io_acct(io); free_io(md, io);- if (io_error == BLK_STS_DM_REQUEUE)+ if (io_error == BLK_STS_DM_REQUEUE) {+ /* not poll any more in case of requeue */+ if (bio->bi_opf & REQ_POLLED)+ bio->bi_opf &= ~REQ_POLLED;
It becomes not necessary to clear REQ_POLLED before requeuing since
every dm_io is added into the hlist_head which is reused from
bio->bi_end_io, so all dm-io(include the one to be requeued) will be
polled.
Thanks,
Ming
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
drivers/md/dm-table.c | 24 +++++++++
drivers/md/dm.c | 111 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 132 insertions(+), 3 deletions(-)
@@ -938,8 +945,12 @@ static void dec_pending(struct dm_io *io, blk_status_t error)end_io_acct(io);free_io(md,io);-if(io_error==BLK_STS_DM_REQUEUE)+if(io_error==BLK_STS_DM_REQUEUE){+/* not poll any more in case of requeue */+if(bio->bi_opf&REQ_POLLED)+bio->bi_opf&=~REQ_POLLED;return;+}
Actually I'm not sure why REQ_POLLED should be cleared here.
Besides, there's one corner case where bio is submitted when dm device
is suspended.
staticblk_qc_tdm_submit_bio(structbio*bio)/* If suspended, queue this IO for later */if(unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND,&md->flags))){if(bio->bi_opf&REQ_NOWAIT)bio_wouldblock_error(bio);elseif(bio->bi_opf&REQ_RAHEAD)bio_io_error(bio);elsequeue_io(md,bio);gotoout;}
When the dm device is suspended with DMF_BLOCK_IO_FOR_SUSPEND, the
submitted bio is inserted into @md->deferred list by calling queue_io().
Then the following bio_poll() calling will trigger the
'WARN_ON_ONCE(!saved_bi_end_io)' in dm_poll_bio(), if the previously
submitted bio is still buffered in @md->deferred list.
if ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size) {
/*
@@ -1590,6 +1601,12 @@ static int __split_and_process_non_flush(struct clone_info *ci) if (__process_abnormal_io(ci, ti, &r)) return r;+ /*+ * Only support bio polling for normal IO, and the target io is+ * exactly inside the dm io instance+ */+ ci->io->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);+ len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); r = __clone_and_map_data_bio(ci, ti, ci->sector, &len);
@@ -1608,6 +1625,22 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md, ci->map = map; ci->io = alloc_io(md, bio); ci->sector = bio->bi_iter.bi_sector;++ if (bio->bi_opf & REQ_POLLED) {+ INIT_HLIST_NODE(&ci->io->node);++ /*+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io+ * for storing dm_io list+ */+ if (bio->bi_opf & REQ_SAVED_END_IO) {+ ci->io->saved_bio_end_io = NULL;+ } else {+ ci->io->saved_bio_end_io = bio->bi_end_io;+ INIT_HLIST_HEAD((struct hlist_head *)&bio->bi_end_io);+ bio->bi_opf |= REQ_SAVED_END_IO;+ }+ } } #define __dm_part_stat_sub(part, field, subnd) \
@@ -1666,8 +1699,19 @@ static void __split_and_process_bio(struct mapped_device *md, } }- /* drop the extra reference count */- dec_pending(ci.io, errno_to_blk_status(error));+ /*+ * Drop the extra reference count for non-POLLED bio, and hold one+ * reference for POLLED bio, which will be released in dm_poll_bio+ *+ * Add every dm_io instance into the hlist_head which is stored in+ * bio->bi_end_io, so that dm_poll_bio can poll them all.+ */+ if (!ci.io->submit_as_polled)+ dec_pending(ci.io, errno_to_blk_status(error));+ else+ hlist_add_head(&ci.io->node,+ (struct hlist_head *)&bio->bi_end_io);+ } static void dm_submit_bio(struct bio *bio)
@@ -1707,6 +1751,66 @@ static void dm_submit_bio(struct bio *bio) dm_put_live_table(md, srcu_idx); }+static int dm_poll_dm_io(struct dm_io *io, unsigned int flags)+{+ if (!io || !io->submit_as_polled)+ return 0;
Wondering if '!io->submit_as_polled' is necessary here. dm_io will be
added into the hash list only when 'io->submit_as_polled' is true in
__split_and_process_bio.
+
+ WARN_ON_ONCE(!io->tio.inside_dm_io);
+ bio_poll(&io->tio.clone, flags);
+
+ /* bio_poll holds the last reference */
+ if (atomic_read(&io->io_count) == 1)
+ return 1;
+ return 0;
+}
+
+static int dm_poll_bio(struct bio *bio, unsigned int flags)
+{
+ struct dm_io *io;
+ void *saved_bi_end_io = NULL;
+ struct hlist_head tmp = HLIST_HEAD_INIT;
+ struct hlist_head *head = (struct hlist_head *)&bio->bi_end_io;
+ struct hlist_node *next;
+
+ /*
+ * This bio can be submitted from FS as POLLED so that FS may keep
+ * polling even though the flag is cleared by bio splitting or
+ * requeue, so return immediately.
+ */
+ if (!(bio->bi_opf & REQ_POLLED))
+ return 0;
+
+ hlist_move_list(head, &tmp);
+
+ hlist_for_each_entry(io, &tmp, node) {
+ if (io->saved_bio_end_io && !saved_bi_end_io) {
Seems that checking if saved_bi_end_io NULL here is not necessary, since
you will exit thte loop once saved_bi_end_io is assigned.
Hello Jeffle,
On Fri, Jun 18, 2021 at 04:19:10PM +0800, JeffleXu wrote:
On 6/17/21 6:35 PM, Ming Lei wrote:
quoted
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
drivers/md/dm-table.c | 24 +++++++++
drivers/md/dm.c | 111 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 132 insertions(+), 3 deletions(-)
@@ -938,8 +945,12 @@ static void dec_pending(struct dm_io *io, blk_status_t error)end_io_acct(io);free_io(md,io);-if(io_error==BLK_STS_DM_REQUEUE)+if(io_error==BLK_STS_DM_REQUEUE){+/* not poll any more in case of requeue */+if(bio->bi_opf&REQ_POLLED)+bio->bi_opf&=~REQ_POLLED;return;+}
Actually I'm not sure why REQ_POLLED should be cleared here.
It this is one dm native split bio(the one returned from bio_split() in
__split_and_process_bio()), we will never get chance to poll it after it
is requeued.
Besides, there's one corner case where bio is submitted when dm device
is suspended.
staticblk_qc_tdm_submit_bio(structbio*bio)/* If suspended, queue this IO for later */if(unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND,&md->flags))){if(bio->bi_opf&REQ_NOWAIT)bio_wouldblock_error(bio);elseif(bio->bi_opf&REQ_RAHEAD)bio_io_error(bio);elsequeue_io(md,bio);gotoout;}
When the dm device is suspended with DMF_BLOCK_IO_FOR_SUSPEND, the
submitted bio is inserted into @md->deferred list by calling queue_io().
Then the following bio_poll() calling will trigger the
'WARN_ON_ONCE(!saved_bi_end_io)' in dm_poll_bio(), if the previously
submitted bio is still buffered in @md->deferred list.
Good catch, bio_poll() shouldn't call on bio which isn't submitted
really, we can clear REQ_POLLED for avoiding the race.
if ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size) {
/*
@@ -1590,6 +1601,12 @@ static int __split_and_process_non_flush(struct clone_info *ci) if (__process_abnormal_io(ci, ti, &r)) return r;+ /*+ * Only support bio polling for normal IO, and the target io is+ * exactly inside the dm io instance+ */+ ci->io->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);+ len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); r = __clone_and_map_data_bio(ci, ti, ci->sector, &len);
@@ -1608,6 +1625,22 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md, ci->map = map; ci->io = alloc_io(md, bio); ci->sector = bio->bi_iter.bi_sector;++ if (bio->bi_opf & REQ_POLLED) {+ INIT_HLIST_NODE(&ci->io->node);++ /*+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io+ * for storing dm_io list+ */+ if (bio->bi_opf & REQ_SAVED_END_IO) {+ ci->io->saved_bio_end_io = NULL;+ } else {+ ci->io->saved_bio_end_io = bio->bi_end_io;+ INIT_HLIST_HEAD((struct hlist_head *)&bio->bi_end_io);+ bio->bi_opf |= REQ_SAVED_END_IO;+ }+ } } #define __dm_part_stat_sub(part, field, subnd) \
@@ -1666,8 +1699,19 @@ static void __split_and_process_bio(struct mapped_device *md, } }- /* drop the extra reference count */- dec_pending(ci.io, errno_to_blk_status(error));+ /*+ * Drop the extra reference count for non-POLLED bio, and hold one+ * reference for POLLED bio, which will be released in dm_poll_bio+ *+ * Add every dm_io instance into the hlist_head which is stored in+ * bio->bi_end_io, so that dm_poll_bio can poll them all.+ */+ if (!ci.io->submit_as_polled)+ dec_pending(ci.io, errno_to_blk_status(error));+ else+ hlist_add_head(&ci.io->node,+ (struct hlist_head *)&bio->bi_end_io);+ } static void dm_submit_bio(struct bio *bio)
@@ -1707,6 +1751,66 @@ static void dm_submit_bio(struct bio *bio) dm_put_live_table(md, srcu_idx); }+static int dm_poll_dm_io(struct dm_io *io, unsigned int flags)+{+ if (!io || !io->submit_as_polled)+ return 0;
Wondering if '!io->submit_as_polled' is necessary here. dm_io will be
added into the hash list only when 'io->submit_as_polled' is true in
__split_and_process_bio.
OK, we can kill the above check.
quoted
+
+ WARN_ON_ONCE(!io->tio.inside_dm_io);
+ bio_poll(&io->tio.clone, flags);
+
+ /* bio_poll holds the last reference */
+ if (atomic_read(&io->io_count) == 1)
+ return 1;
+ return 0;
+}
+
+static int dm_poll_bio(struct bio *bio, unsigned int flags)
+{
+ struct dm_io *io;
+ void *saved_bi_end_io = NULL;
+ struct hlist_head tmp = HLIST_HEAD_INIT;
+ struct hlist_head *head = (struct hlist_head *)&bio->bi_end_io;
+ struct hlist_node *next;
+
+ /*
+ * This bio can be submitted from FS as POLLED so that FS may keep
+ * polling even though the flag is cleared by bio splitting or
+ * requeue, so return immediately.
+ */
+ if (!(bio->bi_opf & REQ_POLLED))
+ return 0;
+
+ hlist_move_list(head, &tmp);
+
+ hlist_for_each_entry(io, &tmp, node) {
+ if (io->saved_bio_end_io && !saved_bi_end_io) {
Seems that checking if saved_bi_end_io NULL here is not necessary, since
you will exit thte loop once saved_bi_end_io is assigned.
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
drivers/md/dm-table.c | 24 ++++++++
drivers/md/dm.c | 127 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 147 insertions(+), 4 deletions(-)
@@ -1590,6 +1629,8 @@ static int __split_and_process_non_flush(struct clone_info *ci)if(__process_abnormal_io(ci,ti,&r))returnr;+dm_setup_polled_io(ci);+len=min_t(sector_t,max_io_len(ti,ci->sector),ci->sector_count);r=__clone_and_map_data_bio(ci,ti,ci->sector,&len);
@@ -1666,8 +1707,18 @@ static void __split_and_process_bio(struct mapped_device *md,}}-/* drop the extra reference count */-dec_pending(ci.io,errno_to_blk_status(error));+/*+*Droptheextrareferencecountfornon-POLLEDbio,andholdone+*referenceforPOLLEDbio,whichwillbereleasedindm_poll_bio+*+*Addeverydm_ioinstanceintothehlist_headwhichisstoredin+*bio->bi_end_io,sothatdm_poll_biocanpollthemall.+*/+if(!ci.submit_as_polled)+dec_pending(ci.io,errno_to_blk_status(error));+else+hlist_add_head(&ci.io->node,+(structhlist_head*)&bio->bi_end_io);}staticvoiddm_submit_bio(structbio*bio)
@@ -1690,8 +1741,11 @@ static void dm_submit_bio(struct bio *bio)bio_wouldblock_error(bio);elseif(bio->bi_opf&REQ_RAHEAD)bio_io_error(bio);-else+else{+/* Not ready for poll */+bio->bi_opf&=~REQ_POLLED;queue_io(md,bio);+}gotoout;}
@@ -1707,6 +1761,70 @@ static void dm_submit_bio(struct bio *bio)dm_put_live_table(md,srcu_idx);}+staticbooldm_poll_dm_io(structdm_io*io,unsignedintflags)+{+WARN_ON_ONCE(!io->tio.inside_dm_io);++bio_poll(&io->tio.clone,flags);++/* bio_poll holds the last reference */+returnatomic_read(&io->io_count)==1;+}++staticintdm_poll_bio(structbio*bio,unsignedintflags)+{+structdm_io*io;+void*saved_bi_end_io=NULL;+structhlist_headtmp=HLIST_HEAD_INIT;+structhlist_head*head=(structhlist_head*)&bio->bi_end_io;+structhlist_node*next;++/*+*ThisbiocanbesubmittedfromFSasPOLLEDsothatFSmaykeep+*pollingeventhoughtheflagisclearedbybiosplittingor+*requeue,soreturnimmediately.+*/+if(!(bio->bi_opf&REQ_POLLED))+return0;++/* We only poll normal bio which was marked as REQ_SAVED_END_IO */+if(!(bio->bi_opf&REQ_SAVED_END_IO))+return0;++WARN_ON_ONCE(hlist_empty(head));++hlist_move_list(head,&tmp);++hlist_for_each_entry(io,&tmp,node){+if(io->saved_bio_end_io){+saved_bi_end_io=io->saved_bio_end_io;+break;+}+}++/* restore .bi_end_io before completing dm io */+WARN_ON_ONCE(!saved_bi_end_io);+bio->bi_opf&=~REQ_SAVED_END_IO;+bio->bi_end_io=saved_bi_end_io;++hlist_for_each_entry_safe(io,next,&tmp,node){+if(dm_poll_dm_io(io,flags)){+hlist_del_init(&io->node);+dec_pending(io,0);+}+}++/* Not done, make sure at least one dm_io stores the .bi_end_io*/+if(!hlist_empty(&tmp)){+io=hlist_entry(tmp.first,structdm_io,node);+io->saved_bio_end_io=saved_bi_end_io;+bio->bi_opf|=REQ_SAVED_END_IO;+hlist_move_list(&tmp,head);+return0;+}+return1;+}+/*-----------------------------------------------------------------*AnIDRisusedtokeeptrackofallocatedminornumbers.*---------------------------------------------------------------*/
From: Mike Snitzer <hidden> Date: 2021-06-18 20:56:51
[you really should've changed the subject of this email to
"[RFC PATCH V3 3/3] dm: support bio polling"]
On Fri, Jun 18 2021 at 10:39P -0400,
Ming Lei [off-list ref] wrote:
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
^ nit: two "4)", last should be 5.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
Would really appreciate it if Jeffle could test these changes like he
did previous dm IO polling patchsets he implemented. Jeffle?
I'd need to check these changes with pahole, but have you looked
closely at whether these new members would be better placed (e.g. is
there an existing hole? does the new 'struct hlist_node' span a
cacheline? etc).
Also, a zoned dm-5.14 change moved this struct out to
drivers/md/dm-core.h, see:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-5.14&id=e2118b3c3d94289852417f70ec128c25f4833aad
So seems no matter what we'll have a merge conflict. But that's OK,
I'll just let Linus know when I send the linux-dm.git pull request for
the 5.14 merge window (assuming hch's bio polling changes land in time
with Jens).
@@ -1574,6 +1587,32 @@ static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti, return true; }+static void dm_setup_polled_io(struct clone_info *ci)+{+ struct bio *bio = ci->bio;++ /*+ * Only support bio polling for normal IO, and the target io is+ * exactly inside the dm io instance+ */
This comment should be clearer with:
+ /*
+ * Only support bio polling for normal IO that also
+ * hasn't been split or cloned further.
+ */
That way DM's use of 'inside_dm_io' flag isn't a factor.
(it just so happens 'inside_dm_io' reflects IO is first DM clone bio).
But wouldn't early return if !ci->io->tio.inside_dm_io also make sense
here? That way you could get rid of the WARN_ON_ONCE in dm_poll_dm_io?
quoted hunk
+ ci->submit_as_polled = !!(bio->bi_opf & REQ_POLLED);
+ if (!ci->submit_as_polled)
+ return;
+
+ INIT_HLIST_NODE(&ci->io->node);
+ /*
+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io
+ * for storing dm_io list
+ */
+ if (bio->bi_opf & REQ_SAVED_END_IO) {
+ ci->io->saved_bio_end_io = NULL;
+ } else {
+ ci->io->saved_bio_end_io = bio->bi_end_io;
+ INIT_HLIST_HEAD((struct hlist_head *)&bio->bi_end_io);
+ bio->bi_opf |= REQ_SAVED_END_IO;
+ }
+}
+
/*
* Select the correct strategy for processing a non-flush bio.
*/
@@ -1590,6 +1629,8 @@ static int __split_and_process_non_flush(struct clone_info *ci) if (__process_abnormal_io(ci, ti, &r)) return r;+ dm_setup_polled_io(ci);+ len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); r = __clone_and_map_data_bio(ci, ti, ci->sector, &len);
@@ -1666,8 +1707,18 @@ static void __split_and_process_bio(struct mapped_device *md, } }- /* drop the extra reference count */- dec_pending(ci.io, errno_to_blk_status(error));+ /*+ * Drop the extra reference count for non-POLLED bio, and hold one+ * reference for POLLED bio, which will be released in dm_poll_bio+ *+ * Add every dm_io instance into the hlist_head which is stored in+ * bio->bi_end_io, so that dm_poll_bio can poll them all.+ */+ if (!ci.submit_as_polled)+ dec_pending(ci.io, errno_to_blk_status(error));+ else+ hlist_add_head(&ci.io->node,+ (struct hlist_head *)&bio->bi_end_io); } static void dm_submit_bio(struct bio *bio)
@@ -1690,8 +1741,11 @@ static void dm_submit_bio(struct bio *bio) bio_wouldblock_error(bio); else if (bio->bi_opf & REQ_RAHEAD) bio_io_error(bio);- else+ else {+ /* Not ready for poll */+ bio->bi_opf &= ~REQ_POLLED; queue_io(md, bio);+ }
"Not ready for poll" isn't really a useful comment. Maybe?:
/* Cannot support polling once IO is queued */
But should you just bio_wouldblock_error() the IO if REQ_POLLED set?
Same as done for REQ_NOWAIT?
(thought I've seen a comparable response to REQ_POLLED before but not
finding one now that I look, maybe it was in Jeffle's earlier patchset?).
But all said, I'm missing why this particular instance of queue_io()
is a problem relative to polling. The bio will just block waiting to
be processed, if blocking is a problem then it really does seem like
bio_wouldblock_error() is appropriate.
And what about dm_io_dec_pending() should its use of queue_io() also
clear REQ_POLLED (so push clearing REQ_POLLED into queue_io?)?
Or is flush-with-data (via REQ_PREFLUSH) and REQ_POLLING mutually
exclussive?
quoted hunk
goto out;
}
@@ -1707,6 +1761,70 @@ static void dm_submit_bio(struct bio *bio) dm_put_live_table(md, srcu_idx); }+static bool dm_poll_dm_io(struct dm_io *io, unsigned int flags)+{+ WARN_ON_ONCE(!io->tio.inside_dm_io);++ bio_poll(&io->tio.clone, flags);++ /* bio_poll holds the last reference */+ return atomic_read(&io->io_count) == 1;+}++static int dm_poll_bio(struct bio *bio, unsigned int flags)+{+ struct dm_io *io;+ void *saved_bi_end_io = NULL;+ struct hlist_head tmp = HLIST_HEAD_INIT;+ struct hlist_head *head = (struct hlist_head *)&bio->bi_end_io;+ struct hlist_node *next;++ /*+ * This bio can be submitted from FS as POLLED so that FS may keep+ * polling even though the flag is cleared by bio splitting or+ * requeue, so return immediately.+ */+ if (!(bio->bi_opf & REQ_POLLED))+ return 0;++ /* We only poll normal bio which was marked as REQ_SAVED_END_IO */+ if (!(bio->bi_opf & REQ_SAVED_END_IO))+ return 0;++ WARN_ON_ONCE(hlist_empty(head));++ hlist_move_list(head, &tmp);++ hlist_for_each_entry(io, &tmp, node) {+ if (io->saved_bio_end_io) {+ saved_bi_end_io = io->saved_bio_end_io;+ break;+ }+ }++ /* restore .bi_end_io before completing dm io */+ WARN_ON_ONCE(!saved_bi_end_io);+ bio->bi_opf &= ~REQ_SAVED_END_IO;+ bio->bi_end_io = saved_bi_end_io;++ hlist_for_each_entry_safe(io, next, &tmp, node) {+ if (dm_poll_dm_io(io, flags)) {+ hlist_del_init(&io->node);+ dec_pending(io, 0);+ }+ }++ /* Not done, make sure at least one dm_io stores the .bi_end_io*/+ if (!hlist_empty(&tmp)) {+ io = hlist_entry(tmp.first, struct dm_io, node);+ io->saved_bio_end_io = saved_bi_end_io;+ bio->bi_opf |= REQ_SAVED_END_IO;+ hlist_move_list(&tmp, head);+ return 0;+ }+ return 1;+}+ /*----------------------------------------------------------------- * An IDR is used to keep track of allocated minor numbers. *---------------------------------------------------------------*/
On Fri, Jun 18, 2021 at 04:56:45PM -0400, Mike Snitzer wrote:
[you really should've changed the subject of this email to
"[RFC PATCH V3 3/3] dm: support bio polling"]
On Fri, Jun 18 2021 at 10:39P -0400,
Ming Lei [off-list ref] wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
^ nit: two "4)", last should be 5.
quoted
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
Would really appreciate it if Jeffle could test these changes like he
did previous dm IO polling patchsets he implemented. Jeffle?
Yeah, I am looking forward to Jeffle's test too, :-)
I'd need to check these changes with pahole, but have you looked
closely at whether these new members would be better placed (e.g. is
there an existing hole? does the new 'struct hlist_node' span a
cacheline? etc).
'hlist_node' won't span a cacheline, and there isn't hole in 'dm_io'
available for the new two fields too.
But looks we have to add one extra cacheline for holding the two new
fields. Originally all fields except for the last one(dm_target_io)
can be held in single cacheline.
@@ -938,8 +945,14 @@ static void dec_pending(struct dm_io *io, blk_status_t error) end_io_acct(io); free_io(md, io);- if (io_error == BLK_STS_DM_REQUEUE)+ if (io_error == BLK_STS_DM_REQUEUE) {+ /*+ * Upper layer won't help us poll split bio, so+ * clear REQ_POLLED in case of requeue+ */
This comment isn't very clear. Meaning block core cannot handle
preserving old bio (which is poll cookie) across requeue?
bio->bi_cookie isn't used by dm queue yet, and we simply clear
POLLED if it isn't submitted directly or needs requeue. So in future,
bio->bi_cookie can be reused for other purpose.
The upper layer(FS) can only call bio_poll() on the bio which is submitted
via submit_bio() from upper layer code. And bio_poll() won't be called on
split bio originated from block layer or dm driver.
The above commit means that this bio may be split bio from bio_split()
in __split_and_process_bio(). And if it is requeued, we will handle it
in 'IRQ' mode, so it can be completed.
@@ -1574,6 +1587,32 @@ static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti, return true; }+static void dm_setup_polled_io(struct clone_info *ci)+{+ struct bio *bio = ci->bio;++ /*+ * Only support bio polling for normal IO, and the target io is+ * exactly inside the dm io instance+ */
This comment should be clearer with:
quoted
+ /*
+ * Only support bio polling for normal IO that also
+ * hasn't been split or cloned further.
+ */
This bio could have been split in __split_and_process_bio() already and
re-submitted via submit_bio_noacct(), and we still can support poll on it
because it is always the bio originated from FS layer. All split bios(dm io)
from this bio are added into hlist which head is stored in this FS bio's bi_end_io().
That way DM's use of 'inside_dm_io' flag isn't a factor.
(it just so happens 'inside_dm_io' reflects IO is first DM clone bio).
But wouldn't early return if !ci->io->tio.inside_dm_io also make sense
here? That way you could get rid of the WARN_ON_ONCE in dm_poll_dm_io?
inside_dm_io is always true here, and it will be updated in alloc_tio()
which isn't run yet.
quoted
+ ci->submit_as_polled = !!(bio->bi_opf & REQ_POLLED);
+ if (!ci->submit_as_polled)
+ return;
+
+ INIT_HLIST_NODE(&ci->io->node);
+ /*
+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io
+ * for storing dm_io list
+ */
+ if (bio->bi_opf & REQ_SAVED_END_IO) {
+ ci->io->saved_bio_end_io = NULL;
+ } else {
+ ci->io->saved_bio_end_io = bio->bi_end_io;
+ INIT_HLIST_HEAD((struct hlist_head *)&bio->bi_end_io);
+ bio->bi_opf |= REQ_SAVED_END_IO;
+ }
+}
+
/*
* Select the correct strategy for processing a non-flush bio.
*/
@@ -1590,6 +1629,8 @@ static int __split_and_process_non_flush(struct clone_info *ci) if (__process_abnormal_io(ci, ti, &r)) return r;+ dm_setup_polled_io(ci);+ len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count); r = __clone_and_map_data_bio(ci, ti, ci->sector, &len);
@@ -1666,8 +1707,18 @@ static void __split_and_process_bio(struct mapped_device *md, } }- /* drop the extra reference count */- dec_pending(ci.io, errno_to_blk_status(error));+ /*+ * Drop the extra reference count for non-POLLED bio, and hold one+ * reference for POLLED bio, which will be released in dm_poll_bio+ *+ * Add every dm_io instance into the hlist_head which is stored in+ * bio->bi_end_io, so that dm_poll_bio can poll them all.+ */+ if (!ci.submit_as_polled)+ dec_pending(ci.io, errno_to_blk_status(error));+ else+ hlist_add_head(&ci.io->node,+ (struct hlist_head *)&bio->bi_end_io); } static void dm_submit_bio(struct bio *bio)
@@ -1690,8 +1741,11 @@ static void dm_submit_bio(struct bio *bio) bio_wouldblock_error(bio); else if (bio->bi_opf & REQ_RAHEAD) bio_io_error(bio);- else+ else {+ /* Not ready for poll */+ bio->bi_opf &= ~REQ_POLLED; queue_io(md, bio);+ }
"Not ready for poll" isn't really a useful comment. Maybe?:
/* Cannot support polling once IO is queued */
We setup dm bio polling mechanism only after __split_and_process_bio()
is called, so 'not ready for poll'.
But should you just bio_wouldblock_error() the IO if REQ_POLLED set?
Same as done for REQ_NOWAIT?
I guess we can't, because the two flags are independent.
(thought I've seen a comparable response to REQ_POLLED before but not
finding one now that I look, maybe it was in Jeffle's earlier patchset?).
But all said, I'm missing why this particular instance of queue_io()
is a problem relative to polling. The bio will just block waiting to
be processed, if blocking is a problem then it really does seem like
bio_wouldblock_error() is appropriate.
It was cleared because I thought we can't call dm_poll_bio() for this
bio queued via queue_io() here, because we don't call dm_setup_polled_io
yet.
But looks we needn't to clear REQ_POLLED here, since REQ_SAVED_END_IO
isn't set for this bio, and it won't be polled in dm_poll_bio()
really until they are submitted finally.
And what about dm_io_dec_pending() should its use of queue_io() also
clear REQ_POLLED (so push clearing REQ_POLLED into queue_io?)?
Or is flush-with-data (via REQ_PREFLUSH) and REQ_POLLING mutually
exclussive?
We only poll normal bio, and REQ_SAVED_END_IO isn't set for flush &
other abnormal bios, so they won't be polled via dm_poll_bio() really
and still rely on underlying's interrupt handler to complete.
Thanks,
Ming
[you really should've changed the subject of this email to
"[RFC PATCH V3 3/3] dm: support bio polling"]
On Fri, Jun 18 2021 at 10:39P -0400,
Ming Lei [off-list ref] wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
^ nit: two "4)", last should be 5.
quoted
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
Would really appreciate it if Jeffle could test these changes like he
did previous dm IO polling patchsets he implemented. Jeffle?
My pleasure. I would test it today and post the test result as soon as
possible.
--
Thanks,
Jeffle
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
On Mon, Jun 21, 2021 at 07:33:34PM +0800, JeffleXu wrote:
On 6/18/21 10:39 PM, Ming Lei wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
2. Performance Issue
I test both on x86 (with only one NVMe) and aarch64 (with multiple NVMes).
The result (IOPS) on x86 is as expected:
Type |IRQ | Polling
--------- | ---- | ----
dm-linear | 239k | 357k
- dm-linear built upon one NVMe,bs=4k, iopoll=1, iodepth=128,
numjobs=1, direct, randread, ioengine=io_uring
This data looks good.
While the result on aarch64 is a little confusing.
Type |IRQ | Polling
------------- | ---- | ----
dm-linear [1] | 208k | 230k
dm-linear [2] | 637k | 691k
dm-stripe | 310k | 354k
- dm-linear [1] built upon *one* NVMe,bs=4k, iopoll=1, iodepth=128,
*numjobs=1*, direct, randread, ioengine=io_uring
- dm-linear [2] built upon *three* NVMes,bs=4k, iopoll=1, iodepth=128,
*numjobs=3*, direct, randread, ioengine=io_uring
- dm-stripe built upon *three* NVMes,chunk_size=4k, bs=12k, iopoll=1,
iodepth=128, numjobs=3, direct, randread, ioengine=io_uring
Following is the corresponding test result of Leiming's last
implementation for bio-based polling on aarch64.
IRQ IOPOLL ratio
dm-linear [2] 639K 835K ~30%
dm-stripe 314K 408K ~30%
The previous version polls one hw queue once if bios are submitted to
same hw queue. We might improve it in future.
Thanks,
Ming
On Mon, Jun 21, 2021 at 07:33:34PM +0800, JeffleXu wrote:
quoted
On 6/18/21 10:39 PM, Ming Lei wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
It doesn't work in my test environment. Actually the following fix
should be applied.
@@ -1390,6 +1403,8 @@ static int clone_bio(struct dm_target_io *tio,
struct bio *bio,
if (bio_integrity(bio))
bio_integrity_trim(clone);
+ clone->bi_opf &= ~REQ_SAVED_END_IO;
+
return 0;
}
The rationale is that, REQ_SAVED_END_IO should be cleared once the bio
*passes through* the device stack layer. Or the cloned bio for next
layer will inherit REQ_SAVED_END_IO flag, in which case
'cloned_bio->bi_end_io' (actually acts as the hlist head) won't be
initialized in dm_setup_polled_io(), and thus it gets crashed when
trying to insert into this hash list in __split_and_process_bio().
--
Thanks,
Jeffle
On Tue, Jun 22, 2021 at 10:26:15AM +0800, JeffleXu wrote:
quoted hunk
On 6/21/21 10:04 PM, Ming Lei wrote:
quoted
On Mon, Jun 21, 2021 at 07:33:34PM +0800, JeffleXu wrote:
quoted
On 6/18/21 10:39 PM, Ming Lei wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
It doesn't work in my test environment. Actually the following fix
should be applied.
@@ -1390,6 +1403,8 @@ static int clone_bio(struct dm_target_io *tio,
struct bio *bio,
if (bio_integrity(bio))
bio_integrity_trim(clone);
+ clone->bi_opf &= ~REQ_SAVED_END_IO;
+
This change is good, but it shouldn't fix the panic except for nested
device map, I will fold into V3.
return 0;
}
The rationale is that, REQ_SAVED_END_IO should be cleared once the bio
*passes through* the device stack layer. Or the cloned bio for next
layer will inherit REQ_SAVED_END_IO flag, in which case
'cloned_bio->bi_end_io' (actually acts as the hlist head) won't be
initialized in dm_setup_polled_io(), and thus it gets crashed when
trying to insert into this hash list in __split_and_process_bio().
'cloned_bio' can't reach dm_submit_bio() if it isn't one DM bio.
Thanks,
Ming
On Tue, Jun 22, 2021 at 10:26:15AM +0800, JeffleXu wrote:
quoted
On 6/21/21 10:04 PM, Ming Lei wrote:
quoted
On Mon, Jun 21, 2021 at 07:33:34PM +0800, JeffleXu wrote:
quoted
On 6/18/21 10:39 PM, Ming Lei wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
It doesn't work in my test environment. Actually the following fix
should be applied.
@@ -1390,6 +1403,8 @@ static int clone_bio(struct dm_target_io *tio,
struct bio *bio,
if (bio_integrity(bio))
bio_integrity_trim(clone);
+ clone->bi_opf &= ~REQ_SAVED_END_IO;
+
This change is good, but it shouldn't fix the panic except for nested
device map, I will fold into V3.
The panic I posted exactly happen for nested device map.
quoted
The rationale is that, REQ_SAVED_END_IO should be cleared once the bio
*passes through* the device stack layer. Or the cloned bio for next
layer will inherit REQ_SAVED_END_IO flag, in which case
'cloned_bio->bi_end_io' (actually acts as the hlist head) won't be
initialized in dm_setup_polled_io(), and thus it gets crashed when
trying to insert into this hash list in __split_and_process_bio().
'cloned_bio' can't reach dm_submit_bio() if it isn't one DM bio.
'cloned_bio' actually refers to dm_io.tio.clone, i.e., the cloned bio
used to submit to the device of the next level.
dm1
/\
dm2 NVMe1
/\
NVMe2 NVMe3
For the above example, 'cloned_bio' refers to dm_io.tio.clone, where
this dm_io is to be submitted to dm2.
@bi_private
split bio ------------------> original bio (for dm1)
^ ^
| @orig_bio | @orig_bio
| |
dm_io(for dm2) dm_io(for NVME1)
struct dm_target_io tio
struct bio clone
(...following omitted for NVMe2 and NVMe3)
I mean, for above 'struct bio clone', REQ_SAVED_END_IO shall be cleared.
--
Thanks,
Jeffle
On Mon, Jun 21, 2021 at 07:33:34PM +0800, JeffleXu wrote:
On 6/18/21 10:39 PM, Ming Lei wrote:
quoted
From 47e523b9ee988317369eaadb96826323cd86819e Mon Sep 17 00:00:00 2001
From: Ming Lei <redacted>
Date: Wed, 16 Jun 2021 16:13:46 +0800
Subject: [RFC PATCH V3 3/3] dm: support bio polling
Support bio(REQ_POLLED) polling in the following approach:
1) only support io polling on normal READ/WRITE, and other abnormal IOs
still fallback on 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
dec_pending() after the target io is done in .poll_bio()
4) enable QUEUE_FLAG_POLL if all underlying queues enable QUEUE_FLAG_POLL,
which is based on Jeffle's previous patch.
Signed-off-by: Ming Lei <redacted>
---
V3:
- covers all comments from Jeffle
- fix corner cases when polling on abnormal ios
...
One bug and one performance issue, though I haven't investigated deep
for both.
kernel base: based on Jens' for-next, applying Christoph and Leiming's
patchset.
1. One bug when there's DM device stack, e.g., dm-linear upon another
dm-linear. Can be reproduced by following steps:
From: Christoph Hellwig <hch@lst.de> Date: 2021-06-21 07:37:00
On Thu, Jun 17, 2021 at 06:35:49PM +0800, Ming Lei wrote:
+ /*
+ * Only support bio polling for normal IO, and the target io is
+ * exactly inside the dm io instance
+ */
+ ci->io->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);
Nit: the !! is not needed.
quoted hunk
@@ -1608,6 +1625,22 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md, ci->map = map; ci->io = alloc_io(md, bio); ci->sector = bio->bi_iter.bi_sector;++ if (bio->bi_opf & REQ_POLLED) {+ INIT_HLIST_NODE(&ci->io->node);++ /*+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io+ * for storing dm_io list+ */+ if (bio->bi_opf & REQ_SAVED_END_IO) {+ ci->io->saved_bio_end_io = NULL;
So if it already was saved the list gets cleared here? Can you explain
this logic a little more?
I think you want to hide these casts in helpers that clearly document
why this is safe rather than sprinkling the casts all over the code.
I also wonder if there is any better way to structur this.
+static int dm_poll_bio(struct bio *bio, unsigned int flags)
+{
+ struct dm_io *io;
+ void *saved_bi_end_io = NULL;
+ struct hlist_head tmp = HLIST_HEAD_INIT;
+ struct hlist_head *head = (struct hlist_head *)&bio->bi_end_io;
+ struct hlist_node *next;
+
+ /*
+ * This bio can be submitted from FS as POLLED so that FS may keep
+ * polling even though the flag is cleared by bio splitting or
+ * requeue, so return immediately.
+ */
+ if (!(bio->bi_opf & REQ_POLLED))
+ return 0;
I can't really parse the comment, can you explain this a little more?
But if we need this check, shouldn't it move to bio_poll()?
On Mon, Jun 21, 2021 at 09:36:56AM +0200, Christoph Hellwig wrote:
On Thu, Jun 17, 2021 at 06:35:49PM +0800, Ming Lei wrote:
quoted
+ /*
+ * Only support bio polling for normal IO, and the target io is
+ * exactly inside the dm io instance
+ */
+ ci->io->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);
Nit: the !! is not needed.
OK.
quoted
@@ -1608,6 +1625,22 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md, ci->map = map; ci->io = alloc_io(md, bio); ci->sector = bio->bi_iter.bi_sector;++ if (bio->bi_opf & REQ_POLLED) {+ INIT_HLIST_NODE(&ci->io->node);++ /*+ * Save .bi_end_io into dm_io, so that we can reuse .bi_end_io+ * for storing dm_io list+ */+ if (bio->bi_opf & REQ_SAVED_END_IO) {+ ci->io->saved_bio_end_io = NULL;
So if it already was saved the list gets cleared here? Can you explain
this logic a little more?
Inside dm_poll_bio() we recognize non-NULL ->saved_bio_end_io as
valid, so it has to be initialized it here.
I think you want to hide these casts in helpers that clearly document
why this is safe rather than sprinkling the casts all over the code.
I also wonder if there is any better way to structur this.
OK, I will add a helper of dm_get_bio_hlist_head() with comment.
quoted
+static int dm_poll_bio(struct bio *bio, unsigned int flags)
+{
+ struct dm_io *io;
+ void *saved_bi_end_io = NULL;
+ struct hlist_head tmp = HLIST_HEAD_INIT;
+ struct hlist_head *head = (struct hlist_head *)&bio->bi_end_io;
+ struct hlist_node *next;
+
+ /*
+ * This bio can be submitted from FS as POLLED so that FS may keep
+ * polling even though the flag is cleared by bio splitting or
+ * requeue, so return immediately.
+ */
+ if (!(bio->bi_opf & REQ_POLLED))
+ return 0;
I can't really parse the comment, can you explain this a little more?
But if we need this check, shouldn't it move to bio_poll()?
Upper layer keeps to poll one bio with POLLED, but the flag can be
cleared by driver or block layer. Once it is cleared, we should return
immediately.
Yeah, we can move it to bio_poll().