switch block layer polling to a bio based model
Subsystems (26)
Christoph Hellwig
maintainerHi all,
This series clean up the block polling code a bit and changes the interface to poll for a specific bio instead of a request_queue and cookie pair.
Polling for the bio itself leads to a few advantages:
- the cookie construction can made entirely private in blk-mq.c
- the caller does not need to remember the request_queue and cookie separately and thus sidesteps their lifetime issues
- keeping the device and the cookie inside the bio allows to trivially support polling BIOs remapping by stacking drivers
- a lot of code to propagate the cookie back up the submission path can removed entirely
The one major caveat is that this requires RCU freeing polled BIOs to make sure the bio that contains the polling information is still alive when io_uring tries to poll it through the iocb. For synchronous polling all the callers have a bio reference anyway, so this is not an issue.
Git tree:
git://git.infradead.org/users/hch/block.git bio-poll
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/bio-poll
Diffstat:
arch/m68k/emu/nfblock.c | 3 arch/xtensa/platforms/iss/simdisk.c | 3 block/bio.c | 29 ++++-- block/blk-core.c | 105 ++++++++++++++++------- block/blk-merge.c | 2 block/blk-mq-debugfs.c | 2 block/blk-mq.c | 163 ++++++++++++++---------------------- block/blk-mq.h | 6 - block/blk-wbt.c | 4 drivers/block/brd.c | 12 +- drivers/block/drbd/drbd_int.h | 2 drivers/block/drbd/drbd_req.c | 3 drivers/block/n64cart.c | 12 +- drivers/block/null_blk/main.c | 3 drivers/block/pktcdvd.c | 7 - drivers/block/ps3vram.c | 6 - drivers/block/rsxx/dev.c | 7 - drivers/block/umem.c | 4 drivers/block/zram/zram_drv.c | 10 -- drivers/lightnvm/pblk-init.c | 6 - drivers/md/bcache/request.c | 13 +- drivers/md/bcache/request.h | 4 drivers/md/dm.c | 28 ++---- drivers/md/md.c | 10 -- drivers/nvdimm/blk.c | 5 - drivers/nvdimm/btt.c | 5 - drivers/nvdimm/pmem.c | 3 drivers/nvme/host/core.c | 4 drivers/nvme/host/multipath.c | 6 - drivers/nvme/host/nvme.h | 2 drivers/s390/block/dcssblk.c | 7 - drivers/s390/block/xpram.c | 5 - fs/block_dev.c | 54 +++-------- fs/btrfs/inode.c | 8 - fs/direct-io.c | 14 --- fs/ext4/file.c | 2 fs/gfs2/file.c | 4 fs/iomap/direct-io.c | 56 ++++++------ fs/xfs/xfs_file.c | 2 fs/zonefs/super.c | 2 include/linux/bio.h | 4 include/linux/blk-mq.h | 15 --- include/linux/blk_types.h | 40 ++------ include/linux/blkdev.h | 8 + include/linux/bvec.h | 2 include/linux/fs.h | 6 - include/linux/iomap.h | 3 mm/page_io.c | 10 -- 48 files changed, 318 insertions(+), 393 deletions(-)
Christoph Hellwig
maintainerPATCH 1/12 direct-io: remove blk_poll support
The polling support in the legacy direct-io support is a little crufty. It already doesn't support the asynchronous polling needed for io_uring polling, and is hard to adopt to upcoming changes in the polling interfaces. Given that all the major file systems already use the iomap direct I/O code, just drop the polling support.
--- fs/direct-io.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
fs/direct-io.c +4 -10
@@ -119,7 +119,6 @@ struct dio {int flags;/* doesn't change */ int op;int op_flags; -blk_qc_t bio_cookie;struct gendisk *bio_disk;struct inode *inode;loff_t i_size;/* i_size when submitted */
@@ -438,11 +437,10 @@ static inline void dio_bio_submit(struct dio *dio, struct dio_submit *sdio) dio->bio_disk = bio->bi_bdev->bd_disk; -if (sdio->submit_io) { +if (sdio->submit_io) sdio->submit_io (bio, dio->inode, sdio->logical_offset_in_bio); - dio->bio_cookie =BLK_QC_T_NONE ; - }else - dio->bio_cookie =submit_bio (bio); +else +submit_bio (bio); sdio->bio =NULL ; sdio->boundary =0 ;
@@ -481,9 +479,7 @@ static struct bio *dio_await_one(struct dio *dio)__set_current_state (TASK_UNINTERRUPTIBLE ); dio->waiter = current;spin_unlock_irqrestore (&dio->bio_lock, flags); -if (!(dio->iocb->ki_flags &IOCB_HIPRI ) || - !blk_poll (dio->bio_disk->queue, dio->bio_cookie, true)) -blk_io_schedule (); +blk_io_schedule ();/* wake up sets us TASK_RUNNING */ spin_lock_irqsave (&dio->bio_lock, flags); dio->waiter =NULL ;
@@ -1213,8 +1209,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, }else { dio->op =REQ_OP_READ ; } -if (iocb->ki_flags &IOCB_HIPRI ) - dio->op_flags |=REQ_HIPRI ;/* * For AIO O_(D)SYNC writes we need to defer completions to a workqueue
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 2/12 block: don't try to poll multi-bio I/Os in __blkdev_direct_IO
In reply to Christoph HellwigIf an iocb is split into multiple bios we can't poll for both. So don't bother to even try to poll in that case.
--- fs/block_dev.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
fs/block_dev.c +14 -23
@@ -373,7 +373,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,struct blk_plug plug;struct blkdev_dio *dio;struct bio *bio; -bool is_poll = (iocb->ki_flags &IOCB_HIPRI ) !=0 ; +bool is_poll = (iocb->ki_flags &IOCB_HIPRI ), do_poll = false;bool is_read = (iov_iter_rw (iter) ==READ ), is_sync;loff_t pos = iocb->ki_pos;blk_qc_t qc =BLK_QC_T_NONE ;
@@ -433,22 +433,9 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, pos += bio->bi_iter.bi_size; nr_pages =bio_iov_vecs_to_alloc (iter,BIO_MAX_VECS ); -if (!nr_pages) { -bool polled = false; - -if (iocb->ki_flags &IOCB_HIPRI ) { -bio_set_polled (bio, iocb); - polled = true; - } - - qc =submit_bio (bio); - -if (polled) -WRITE_ONCE (iocb->ki_cookie, qc); -break ; - } - -if (!dio->multi_bio) { +if (dio->multi_bio) { +atomic_inc (&dio->ref); + }else if (nr_pages) {/* * AIO needs an extra reference to ensure the dio * structure which is embedded into the first bio
@@ -458,11 +445,16 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_get (bio); dio->multi_bio = true;atomic_set (&dio->ref,2 ); - }else { -atomic_inc (&dio->ref); + }else if (is_poll) { +bio_set_polled (bio, iocb); + do_poll = true; + } + qc =submit_bio (bio); +if (!nr_pages) { +if (do_poll) +WRITE_ONCE (iocb->ki_cookie, qc); +break ; } - -submit_bio (bio); bio =bio_alloc (GFP_KERNEL , nr_pages); }
@@ -477,8 +469,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,if (!READ_ONCE (dio->waiter))break ; -if (!(iocb->ki_flags &IOCB_HIPRI ) || - !blk_poll (bdev_get_queue (bdev), qc, true)) +if (!do_poll || !blk_poll (bdev_get_queue (bdev), qc, true))blk_io_schedule (); }__set_current_state (TASK_RUNNING );
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 3/12 iomap: don't try to poll multi-bio I/Os in __iomap_dio_rw
In reply to Christoph HellwigIf an iocb is split into multiple bios we can't poll for both. So don't bother to even try to poll in that case.
--- fs/iomap/direct-io.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/iomap/direct-io.c +17 -0
@@ -282,6 +282,13 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,if (!iov_iter_count (dio->submit.iter)) goto out; +/* +* We can only poll for single bio I/Os. +*/ +if (need_zeroout || + ((dio->flags &IOMAP_DIO_WRITE ) && pos >=i_size_read (inode))) + dio->iocb->ki_flags &= ~IOCB_HIPRI ; +if (need_zeroout) {/* zero out from the start of the block to the write offset */ pad = pos & (fs_block_size -1 );
@@ -339,6 +346,11 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, nr_pages =bio_iov_vecs_to_alloc (dio->submit.iter,BIO_MAX_VECS ); +/* +* We can only poll for single bio I/Os. +*/ +if (nr_pages) + dio->iocb->ki_flags &= ~IOCB_HIPRI ;iomap_dio_submit_bio (dio, iomap, bio, pos); pos += n; }while (nr_pages);
@@ -571,6 +583,11 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,iov_iter_revert (iter, pos - dio->i_size);break ; } + +/* +* We can only poll for single bio I/Os. +*/ + iocb->ki_flags &= ~IOCB_HIPRI ; }while ((count =iov_iter_count (iter)) >0 );blk_finish_plug (&plug);
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 4/12 blk-mq: factor out a "classic" poll helper
In reply to Christoph HellwigFactor the code to do the classic full metal polling out of blk_poll into a separate blk_mq_poll_classic helper.
--- block/blk-mq.c | 63 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 29 deletions(-)
block/blk-mq.c +34 -29
@@ -3853,6 +3853,39 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,return blk_mq_poll_hybrid_sleep (q, rq); } +static int blk_mq_poll_classic (struct request_queue *q,blk_qc_t qc,bool spin) +{ +struct blk_mq_hw_ctx *hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num (qc)]; +long state = current->state; + + hctx->poll_considered++; + +do { +int ret; + + hctx->poll_invoked++; + + ret = q->mq_ops->poll (hctx); +if (ret >0 ) { + hctx->poll_success++; +__set_current_state (TASK_RUNNING ); +return ret; + } + +if (signal_pending_state (state, current)) +__set_current_state (TASK_RUNNING ); + +if (current->state ==TASK_RUNNING ) +return 1 ; +if (ret <0 || !spin) +break ; +cpu_relax (); + }while (!need_resched ()); + +__set_current_state (TASK_RUNNING ); +return 0 ; +} +/** * blk_poll - poll for IO completions * @q: the queue
@@ -3868,7 +3901,6 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,int blk_poll (struct request_queue *q,blk_qc_t cookie,bool spin) {struct blk_mq_hw_ctx *hctx; -long state;if (!blk_qc_t_valid (cookie) || !test_bit (QUEUE_FLAG_POLL , &q->queue_flags))
@@ -3889,34 +3921,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)*/ if (spin &&blk_mq_poll_hybrid (q, hctx, cookie))return 1 ; - - hctx->poll_considered++; - - state = current->state; -do { -int ret; - - hctx->poll_invoked++; - - ret = q->mq_ops->poll (hctx); -if (ret >0 ) { - hctx->poll_success++; -__set_current_state (TASK_RUNNING ); -return ret; - } - -if (signal_pending_state (state, current)) -__set_current_state (TASK_RUNNING ); - -if (current->state ==TASK_RUNNING ) -return 1 ; -if (ret <0 || !spin) -break ; -cpu_relax (); - }while (!need_resched ()); - -__set_current_state (TASK_RUNNING ); -return 0 ; +return blk_mq_poll_classic (q, cookie, spin); }EXPORT_SYMBOL_GPL (blk_poll);
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 5/12 blk-mq: factor out a blk_qc_to_hctx helper
In reply to Christoph HellwigAdd a helper to get the hctx from a request_queue and cookie, and fold the blk_qc_t_to_queue_num helper into it as no other callers are left.
--- block/blk-mq.c | 10 ++++++++-- include/linux/blk_types.h | 5 ----- 2 files changed, 8 insertions(+), 7 deletions(-)
block/blk-mq.c +8 -2
@@ -63,6 +63,12 @@ static int blk_mq_poll_stats_bkt(const struct request *rq)return bucket; } +static inline struct blk_mq_hw_ctx *blk_qc_to_hctx (struct request_queue *q, +blk_qc_t qc) +{ +return q->queue_hw_ctx[(qc & ~BLK_QC_T_INTERNAL ) >>BLK_QC_T_SHIFT ]; +} +/* * Check if any of the ctx, dispatch list or elevator * have pending work in this hardware queue.
@@ -3855,7 +3861,7 @@ static bool blk_mq_poll_hybrid(struct request_queue *q,static int blk_mq_poll_classic (struct request_queue *q,blk_qc_t qc,bool spin) { -struct blk_mq_hw_ctx *hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num (qc)]; +struct blk_mq_hw_ctx *hctx =blk_qc_to_hctx (q, qc);long state = current->state; hctx->poll_considered++;
@@ -3909,7 +3915,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)if (current->plug)blk_flush_plug_list (current->plug, false); - hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num (cookie)]; + hctx =blk_qc_to_hctx (q, cookie);/* * If we sleep, have the caller restart the poll loop to reset
include/linux/blk_types.h +0 -5
@@ -515,11 +515,6 @@ static inline bool blk_qc_t_valid(blk_qc_t cookie)return cookie !=BLK_QC_T_NONE ; } -static inline unsigned int blk_qc_t_to_queue_num (blk_qc_t cookie) -{ -return (cookie & ~BLK_QC_T_INTERNAL ) >>BLK_QC_T_SHIFT ; -} -static inline unsigned int blk_qc_t_to_tag (blk_qc_t cookie) {return cookie & ((1u <<BLK_QC_T_SHIFT ) -1 );
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 6/12 blk-mq: refactor hybrid polling
In reply to Christoph HellwigRefactor the hybrid polling logic by moving the request lookup into a helper, and the check if hybrid polling is enabled into blk_poll, and then merging blk_mq_poll_hybrid and blk_mq_poll_hybrid_sleep into a single function.
--- block/blk-mq.c | 65 +++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 40 deletions(-)
block/blk-mq.c +25 -40
@@ -69,6 +69,14 @@ static inline struct blk_mq_hw_ctx *blk_qc_to_hctx(struct request_queue *q,return q->queue_hw_ctx[(qc & ~BLK_QC_T_INTERNAL ) >>BLK_QC_T_SHIFT ]; } +static inline struct request *blk_qc_to_rq (struct blk_mq_hw_ctx *hctx, +blk_qc_t qc) +{ +if (blk_qc_t_is_internal (qc)) +return blk_mq_tag_to_rq (hctx->sched_tags,blk_qc_t_to_tag (qc)); +return blk_mq_tag_to_rq (hctx->tags,blk_qc_t_to_tag (qc)); +} +/* * Check if any of the ctx, dispatch list or elevator * have pending work in this hardware queue.
@@ -3781,15 +3789,20 @@ static unsigned long blk_mq_poll_nsecs(struct request_queue *q,return ret; } -static bool blk_mq_poll_hybrid_sleep (struct request_queue *q, -struct request *rq) +static bool blk_mq_poll_hybrid (struct request_queue *q,blk_qc_t qc) { +struct blk_mq_hw_ctx *hctx =blk_qc_to_hctx (q, qc); +struct request *rq =blk_qc_to_rq (hctx, qc);struct hrtimer_sleeper hs;enum hrtimer_mode mode;unsigned int nsecs;ktime_t kt; -if (rq->rq_flags &RQF_MQ_POLL_SLEPT ) +/* +* If a request has completed on queue that uses an I/O scheduler, we +* won't get back a request from blk_qc_to_rq. +*/ +if (!rq || (rq->rq_flags &RQF_MQ_POLL_SLEPT ))return false;/*
@@ -3834,31 +3847,6 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,return true; } -static bool blk_mq_poll_hybrid (struct request_queue *q, -struct blk_mq_hw_ctx *hctx,blk_qc_t cookie) -{ -struct request *rq; - -if (q->poll_nsec ==BLK_MQ_POLL_CLASSIC ) -return false; - -if (!blk_qc_t_is_internal (cookie)) - rq =blk_mq_tag_to_rq (hctx->tags,blk_qc_t_to_tag (cookie)); -else { - rq =blk_mq_tag_to_rq (hctx->sched_tags,blk_qc_t_to_tag (cookie)); -/* -* With scheduling, if the request has completed, we'll -* get a NULL return here, as we clear the sched tag when -* that happens. The request still remains valid, like always, -* so we should be safe with just the NULL check. -*/ -if (!rq) -return false; - } - -return blk_mq_poll_hybrid_sleep (q, rq); -} -static int blk_mq_poll_classic (struct request_queue *q,blk_qc_t qc,bool spin) {struct blk_mq_hw_ctx *hctx =blk_qc_to_hctx (q, qc);
@@ -3906,8 +3894,6 @@ static int blk_mq_poll_classic(struct request_queue *q, blk_qc_t qc, bool spin)*/ int blk_poll (struct request_queue *q,blk_qc_t cookie,bool spin) { -struct blk_mq_hw_ctx *hctx; -if (!blk_qc_t_valid (cookie) || !test_bit (QUEUE_FLAG_POLL , &q->queue_flags))return 0 ;
@@ -3915,18 +3901,17 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)if (current->plug)blk_flush_plug_list (current->plug, false); - hctx =blk_qc_to_hctx (q, cookie); -/* -* If we sleep, have the caller restart the poll loop to reset -* the state. Like for the other success return cases, the -* caller is responsible for checking if the IO completed. If -* the IO isn't complete, we'll get called again and will go -* straight to the busy poll loop. If specified not to spin, -* we also should not sleep. +* If we sleep, have the caller restart the poll loop to reset the +* state. Like for the other success return cases, the caller is +* responsible for checking if the IO completed. If the IO isn't +* complete, we'll get called again and will go straight to the busy +* poll loop. If specified not to spin, we also should not sleep. */ -if (spin &&blk_mq_poll_hybrid (q, hctx, cookie)) -return 1 ; +if (spin && q->poll_nsec !=BLK_MQ_POLL_CLASSIC ) { +if (blk_mq_poll_hybrid (q, cookie)) +return 1 ; + }return blk_mq_poll_classic (q, cookie, spin); }EXPORT_SYMBOL_GPL (blk_poll);
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 7/12 blk-mq: remove blk_qc_t_to_tag and blk_qc_t_is_internal
In reply to Christoph HellwigMerge both functions into their only caller to keep the blk-mq tag to blk_qc_t mapping as private as possible in blk-mq.c.
--- block/blk-mq.c | 8 +++++--- include/linux/blk_types.h | 10 ---------- 2 files changed, 5 insertions(+), 13 deletions(-)
block/blk-mq.c +5 -3
@@ -72,9 +72,11 @@ static inline struct blk_mq_hw_ctx *blk_qc_to_hctx(struct request_queue *q,static inline struct request *blk_qc_to_rq (struct blk_mq_hw_ctx *hctx,blk_qc_t qc) { -if (blk_qc_t_is_internal (qc)) -return blk_mq_tag_to_rq (hctx->sched_tags,blk_qc_t_to_tag (qc)); -return blk_mq_tag_to_rq (hctx->tags,blk_qc_t_to_tag (qc)); +unsigned int tag = qc & ((1U <<BLK_QC_T_SHIFT ) -1 ); + +if (qc &BLK_QC_T_INTERNAL ) +return blk_mq_tag_to_rq (hctx->sched_tags, tag); +return blk_mq_tag_to_rq (hctx->tags, tag); }/*
include/linux/blk_types.h +0 -10
@@ -515,16 +515,6 @@ static inline bool blk_qc_t_valid(blk_qc_t cookie)return cookie !=BLK_QC_T_NONE ; } -static inline unsigned int blk_qc_t_to_tag (blk_qc_t cookie) -{ -return cookie & ((1u <<BLK_QC_T_SHIFT ) -1 ); -} - -static inline bool blk_qc_t_is_internal (blk_qc_t cookie) -{ -return (cookie &BLK_QC_T_INTERNAL ) !=0 ; -} -struct blk_rq_stat {u64 mean;u64 min;
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 8/12 blk-mq: remove blk_qc_t_valid
In reply to Christoph HellwigMove the trivial check into the only caller.
--- block/blk-mq.c | 2 +- include/linux/blk_types.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-)
block/blk-mq.c +1 -1
@@ -3896,7 +3896,7 @@ static int blk_mq_poll_classic(struct request_queue *q, blk_qc_t qc, bool spin)*/ int blk_poll (struct request_queue *q,blk_qc_t cookie,bool spin) { -if (!blk_qc_t_valid (cookie) || +if (cookie ==BLK_QC_T_NONE || !test_bit (QUEUE_FLAG_POLL , &q->queue_flags))return 0 ;
include/linux/blk_types.h +0 -5
@@ -510,11 +510,6 @@ typedef unsigned int blk_qc_t;#define BLK_QC_T_SHIFT 16#define BLK_QC_T_INTERNAL (1U << 31) -static inline bool blk_qc_t_valid (blk_qc_t cookie) -{ -return cookie !=BLK_QC_T_NONE ; -} -struct blk_rq_stat {u64 mean;u64 min;
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 9/12 block: rename REQ_HIPRI to REQ_POLLED
In reply to Christoph HellwigUnlike the RWF_HIPRI userspace ABI which is intentionally kept vague, the bio flag is specіfic to the polling implementation, so rename and document it properly.
--- block/blk-core.c | 2 +- block/blk-merge.c | 2 +- block/blk-mq-debugfs.c | 2 +- block/blk-mq.c | 4 ++-- block/blk-mq.h | 4 ++-- block/blk-wbt.c | 4 ++-- drivers/nvme/host/core.c | 2 +- include/linux/bio.h | 2 +- include/linux/blk_types.h | 4 ++-- mm/page_io.c | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-)
block/blk-core.c +1 -1
@@ -837,7 +837,7 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio) }if (!test_bit (QUEUE_FLAG_POLL , &q->queue_flags)) - bio->bi_opf &= ~REQ_HIPRI ; + bio->bi_opf &= ~REQ_POLLED ;switch (bio_op (bio)) {case REQ_OP_DISCARD :
block/blk-merge.c +1 -1
@@ -285,7 +285,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,* iopoll in direct IO routine. Given performance gain of iopoll for * big IO can be trival, disable iopoll when split needed. */ - bio->bi_opf &= ~REQ_HIPRI ; + bio->bi_opf &= ~REQ_POLLED ;return bio_split (bio, sectors,GFP_NOIO , bs); }
block/blk-mq-debugfs.c +1 -1
@@ -286,7 +286,7 @@ static const char *const cmd_flag_name[] = {CMD_FLAG_NAME (BACKGROUND ),CMD_FLAG_NAME (NOWAIT ),CMD_FLAG_NAME (NOUNMAP ), - CMD_FLAG_NAME(HIPRI), + CMD_FLAG_NAME(POLLED), };#undef CMD_FLAG_NAME
block/blk-mq.c +2 -2
@@ -667,7 +667,7 @@ bool blk_mq_complete_request_remote(struct request *rq)* For a polled request, always complete locallly, it's pointless * to redirect the completion. */ -if (rq->cmd_flags &REQ_HIPRI ) +if (rq->cmd_flags &REQ_POLLED )return false;if (blk_mq_complete_need_ipi (rq)) {
@@ -2201,7 +2201,7 @@ blk_qc_t blk_mq_submit_bio(struct bio *bio)rq_qos_throttle (q, bio); - hipri = bio->bi_opf &REQ_HIPRI ; + hipri = bio->bi_opf &REQ_POLLED ; data.cmd_flags = bio->bi_opf; rq =__blk_mq_alloc_request (&data);
block/blk-mq.h +2 -2
@@ -108,9 +108,9 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,enum hctx_type type =HCTX_TYPE_DEFAULT ;/* -* The caller ensure that if REQ_HIPRI, poll must be enabled. +* The caller ensure that if REQ_POLLED, poll must be enabled. */ -if (flags &REQ_HIPRI ) +if (flags &REQ_POLLED ) type =HCTX_TYPE_POLL ;else if ((flags &REQ_OP_MASK ) ==REQ_OP_READ ) type =HCTX_TYPE_READ ;
block/blk-wbt.c +2 -2
@@ -445,7 +445,7 @@ static bool close_io(struct rq_wb *rwb)time_before (now, rwb->last_comp +HZ /10 ); } -#define REQ_HIPRIO (REQ_SYNC | REQ_META | REQ_PRIO) +#define REQ_POLLEDO (REQ_SYNC | REQ_META | REQ_PRIO)static inline unsigned int get_limit (struct rq_wb *rwb,unsigned long rw) {
@@ -469,7 +469,7 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)* the idle limit, or go to normal if we haven't had competing * IO for a bit. */ -if ((rw &REQ_HIPRIO ) ||wb_recent_wait (rwb) ||current_is_kswapd ()) +if ((rw &REQ_POLLEDO ) ||wb_recent_wait (rwb) ||current_is_kswapd ()) limit = rwb->rq_depth.max_depth;else if ((rw &REQ_BACKGROUND ) ||close_io (rwb)) {/*
drivers/nvme/host/core.c +1 -1
@@ -958,7 +958,7 @@ static void nvme_execute_rq_polled(struct request_queue *q,WARN_ON_ONCE (!test_bit (QUEUE_FLAG_POLL , &q->queue_flags)); - rq->cmd_flags |=REQ_HIPRI ; + rq->cmd_flags |=REQ_POLLED ; rq->end_io_data = &wait;blk_execute_rq_nowait (bd_disk, rq, at_head, nvme_end_sync_rq);
include/linux/bio.h +1 -1
@@ -817,7 +817,7 @@ static inline int bio_integrity_add_page(struct bio *bio, struct page *page,*/ static inline void bio_set_polled (struct bio *bio,struct kiocb *kiocb) { - bio->bi_opf |=REQ_HIPRI ; + bio->bi_opf |=REQ_POLLED ;if (!is_sync_kiocb (kiocb)) bio->bi_opf |=REQ_NOWAIT ; }
include/linux/blk_types.h +2 -2
@@ -392,7 +392,7 @@ enum req_flag_bits {/* command specific flags for REQ_OP_WRITE_ZEROES: */ __REQ_NOUNMAP,/* do not free blocks when zeroing */ - __REQ_HIPRI, + __REQ_POLLED,/* caller polls for completion using blk_poll */ /* for driver use */ __REQ_DRV,
@@ -417,7 +417,7 @@ enum req_flag_bits {#define REQ_CGROUP_PUNT (1ULL << __REQ_CGROUP_PUNT)#define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP) -#define REQ_HIPRI (1ULL << __REQ_HIPRI) +#define REQ_POLLED (1ULL << __REQ_POLLED)#define REQ_DRV (1ULL << __REQ_DRV)#define REQ_SWAP (1ULL << __REQ_SWAP)
mm/page_io.c +1 -1
@@ -416,7 +416,7 @@ int swap_readpage(struct page *page, bool synchronous)* attempt to access it in the page fault retry time check. */ if (synchronous) { - bio->bi_opf |=REQ_HIPRI ; + bio->bi_opf |=REQ_POLLED ;get_task_struct (current); bio->bi_private = current; }
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 10/12 block: RCU free polled bios
In reply to Christoph HellwigFree the actual memory used for the bio using RCU for polled bios. This will allow to store all the polling information in the bio and thus simplify passing the cookie and allow for polling stacked devices.
--- block/bio.c | 28 +++++++++++++++++++--------- include/linux/blk_types.h | 6 +++++- 2 files changed, 24 insertions(+), 10 deletions(-)
block/bio.c +19 -9
@@ -215,25 +215,35 @@ void bio_uninit(struct bio *bio) }EXPORT_SYMBOL (bio_uninit); +static inline void bio_mempool_free (struct bio *bio) +{ +struct bio_set *bs = bio->bi_pool; +void *p = bio; + + p -= bs->front_pad; +mempool_free (p, &bs->bio_pool); +} + +static void bio_free_rcu (struct rcu_head *head) +{ +bio_mempool_free (container_of(head ,struct bio ,bi_rcu_free )); +} +static void bio_free (struct bio *bio) {struct bio_set *bs = bio->bi_pool; -void *p;bio_uninit (bio);if (bs) {bvec_free (&bs->bvec_pool, bio->bi_io_vec, bio->bi_max_vecs); - -/* -* If we have front padding, adjust the bio pointer before freeing -*/ - p = bio; - p -= bs->front_pad; - -mempool_free (p, &bs->bio_pool); +if (bio->bi_opf &REQ_POLLED ) +call_rcu (&bio->bi_rcu_free, bio_free_rcu); +else +bio_mempool_free (bio); }else {/* Bio was allocated by bio_kmalloc() */ +WARN_ON_ONCE (bio->bi_opf &REQ_POLLED );kfree (bio); } }
include/linux/blk_types.h +5 -1
@@ -10,6 +10,7 @@#include <linux/bvec.h> #include <linux/device.h> #include <linux/ktime.h> +#include <linux/rcupdate.h> struct bio_set ;struct bio ;
@@ -233,7 +234,10 @@ struct bio {blk_status_t bi_status;atomic_t __bi_remaining; -struct bvec_iter bi_iter; +union { +struct bvec_iter bi_iter; +struct rcu_head bi_rcu_free; + };bio_end_io_t *bi_end_io;
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 11/12 block: define 'struct bvec_iter' as packed
In reply to Christoph HellwigFrom: Ming Lei <[email protected]>
'struct bvec_iter' is embedded into 'struct bio', define it as packed so that we can get one extra 4bytes for other uses without expanding bio.
'struct bvec_iter' is often allocated on stack, so making it packed doesn't affect performance. Also I have run io_uring on both nvme/null_blk, and not observe performance effect in this way.
--- include/linux/bvec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/bvec.h +1 -1
@@ -43,7 +43,7 @@ struct bvec_iter {unsigned int bi_bvec_done;/* number of bytes completed in current bvec */ -}; +} __packed;struct bvec_iter_all {struct bio_vec bv;
Signature · 1 line
2.30.1
Christoph Hellwig
maintainerPATCH 12/12 block: switch polling to be bio based
In reply to Christoph HellwigReplace the blk_poll interface that requires the caller to keep a queue and cookie from the submissions with polling based on the bio.
Polling for the bio itself leads to a few advantages:
- the cookie construction can made entirely private in blk-mq.c
- the caller does not need to remember the request_queue and cookie separately and thus sidesteps their lifetime issues
- keeping the device and the cookie inside the bio allows to trivially support polling BIOs remapping by stacking drivers
- a lot of code to propagate the cookie back up the submission path can be removed entirely.
--- arch/m68k/emu/nfblock.c | 3 +- arch/xtensa/platforms/iss/simdisk.c | 3 +- block/bio.c | 1 + block/blk-core.c | 103 +++++++++++++++++++--------- block/blk-mq.c | 75 +++++++------------- block/blk-mq.h | 2 + drivers/block/brd.c | 12 ++-- drivers/block/drbd/drbd_int.h | 2 +- drivers/block/drbd/drbd_req.c | 3 +- drivers/block/n64cart.c | 12 ++-- drivers/block/null_blk/main.c | 3 +- drivers/block/pktcdvd.c | 7 +- drivers/block/ps3vram.c | 6 +- drivers/block/rsxx/dev.c | 7 +- drivers/block/umem.c | 4 +- drivers/block/zram/zram_drv.c | 10 +-- drivers/lightnvm/pblk-init.c | 6 +- drivers/md/bcache/request.c | 13 ++-- drivers/md/bcache/request.h | 4 +- drivers/md/dm.c | 28 +++----- drivers/md/md.c | 10 ++- drivers/nvdimm/blk.c | 5 +- drivers/nvdimm/btt.c | 5 +- drivers/nvdimm/pmem.c | 3 +- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 6 +- drivers/nvme/host/nvme.h | 2 +- drivers/s390/block/dcssblk.c | 7 +- drivers/s390/block/xpram.c | 5 +- fs/block_dev.c | 25 +++---- fs/btrfs/inode.c | 8 +-- fs/ext4/file.c | 2 +- fs/gfs2/file.c | 4 +- fs/iomap/direct-io.c | 39 ++++------- fs/xfs/xfs_file.c | 2 +- fs/zonefs/super.c | 2 +- include/linux/bio.h | 2 +- include/linux/blk-mq.h | 15 +--- include/linux/blk_types.h | 12 ++-- include/linux/blkdev.h | 8 ++- include/linux/fs.h | 6 +- include/linux/iomap.h | 3 +- mm/page_io.c | 8 +-- 43 files changed, 208 insertions(+), 277 deletions(-)
arch/m68k/emu/nfblock.c +1 -2
@@ -59,7 +59,7 @@ struct nfhd_device {struct gendisk *disk; }; -static blk_qc_t nfhd_submit_bio (struct bio *bio) +static void nfhd_submit_bio (struct bio *bio) {struct nfhd_device *dev = bio->bi_bdev->bd_disk->private_data;struct bio_vec bvec;
@@ -77,7 +77,6 @@ static blk_qc_t nfhd_submit_bio(struct bio *bio) sec += len; }bio_endio (bio); -return BLK_QC_T_NONE ; }static int nfhd_getgeo (struct block_device *bdev,struct hd_geometry *geo)
arch/xtensa/platforms/iss/simdisk.c +1 -2
@@ -101,7 +101,7 @@ static void simdisk_transfer(struct simdisk *dev, unsigned long sector,spin_unlock (&dev->lock); } -static blk_qc_t simdisk_submit_bio (struct bio *bio) +static void simdisk_submit_bio (struct bio *bio) {struct simdisk *dev = bio->bi_bdev->bd_disk->private_data;struct bio_vec bvec;
@@ -119,7 +119,6 @@ static blk_qc_t simdisk_submit_bio(struct bio *bio) }bio_endio (bio); -return BLK_QC_T_NONE ; }static int simdisk_open (struct block_device *bdev,fmode_t mode)
block/bio.c +1 -0
@@ -259,6 +259,7 @@ void bio_init(struct bio *bio, struct bio_vec *table,memset (bio,0 ,sizeof (*bio));atomic_set (&bio->__bi_remaining,1 );atomic_set (&bio->__bi_cnt,1 ); + bio->bi_cookie =BLK_QC_T_NONE ; bio->bi_io_vec = table; bio->bi_max_vecs = max_vecs;
block/blk-core.c +72 -31
188 lines not on this page · raw message
block/blk-mq.c +23 -52
222 lines not on this page · raw message
block/blk-mq.h +2 -0
@@ -37,6 +37,8 @@ struct blk_mq_ctx {struct kobject kobj; }____cacheline_aligned_in_smp ; +void blk_mq_submit_bio (struct bio *bio); +int blk_mq_poll (struct request_queue *q,blk_qc_t cookie,bool spin);void blk_mq_exit_queue (struct request_queue *q);int blk_mq_update_nr_requests (struct request_queue *q,unsigned int nr);void blk_mq_wake_waiters (struct request_queue *q);
drivers/block/brd.c +5 -7
@@ -282,7 +282,7 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,return err; } -static blk_qc_t brd_submit_bio (struct bio *bio) +static void brd_submit_bio (struct bio *bio) {struct brd_device *brd = bio->bi_bdev->bd_disk->private_data;sector_t sector = bio->bi_iter.bi_sector;
@@ -299,16 +299,14 @@ static blk_qc_t brd_submit_bio(struct bio *bio) err =brd_do_bvec (brd, bvec.bv_page, len, bvec.bv_offset,bio_op (bio), sector); -if (err) - goto io_error; +if (err) { +bio_io_error (bio); +return ; + } sector += len >>SECTOR_SHIFT ; }bio_endio (bio); -return BLK_QC_T_NONE ; -io_error: -bio_io_error (bio); -return BLK_QC_T_NONE ; } static int brd_rw_page(struct block_device *bdev, sector_t sector,
drivers/block/drbd/drbd_int.h +1 -1
@@ -1448,7 +1448,7 @@ extern void conn_free_crypto(struct drbd_connection *connection);/* drbd_req */ extern void do_submit (struct work_struct *ws);extern void __drbd_make_request (struct drbd_device *,struct bio *); -extern blk_qc_t drbd_submit_bio (struct bio *bio); +void drbd_submit_bio (struct bio *bio);extern int drbd_read_remote (struct drbd_device *device,struct drbd_request *req);extern int is_valid_ar_handle (struct drbd_request *,sector_t );
drivers/block/drbd/drbd_req.c +1 -2
@@ -1596,7 +1596,7 @@ void do_submit(struct work_struct *ws) } } -blk_qc_t drbd_submit_bio (struct bio *bio) +void drbd_submit_bio (struct bio *bio) {struct drbd_device *device = bio->bi_bdev->bd_disk->private_data;
@@ -1609,7 +1609,6 @@ blk_qc_t drbd_submit_bio(struct bio *bio)inc_ap_bio (device);__drbd_make_request (device, bio); -return BLK_QC_T_NONE ; } static bool net_timeout_reached(struct drbd_request *net_req,
drivers/block/n64cart.c +5 -7
@@ -84,7 +84,7 @@ static bool n64cart_do_bvec(struct device *dev, struct bio_vec *bv, u32 pos)return true; } -static blk_qc_t n64cart_submit_bio (struct bio *bio) +static void n64cart_submit_bio (struct bio *bio) {struct bio_vec bvec;struct bvec_iter iter;
@@ -92,16 +92,14 @@ static blk_qc_t n64cart_submit_bio(struct bio *bio)u32 pos = bio->bi_iter.bi_sector <<SECTOR_SHIFT ;bio_for_each_segment (bvec, bio, iter) { -if (!n64cart_do_bvec (dev, &bvec, pos)) - goto io_error; +if (!n64cart_do_bvec (dev, &bvec, pos)) { +bio_io_error (bio); +return ; + } pos += bvec.bv_len; }bio_endio (bio); -return BLK_QC_T_NONE ; -io_error: -bio_io_error (bio); -return BLK_QC_T_NONE ; }static const struct block_device_operations n64cart_fops = {
drivers/block/null_blk/main.c +1 -2
@@ -1416,7 +1416,7 @@ static struct nullb_queue *nullb_to_queue(struct nullb *nullb)return &nullb->queues[index]; } -static blk_qc_t null_submit_bio (struct bio *bio) +static void null_submit_bio (struct bio *bio) {sector_t sector = bio->bi_iter.bi_sector;sector_t nr_sectors =bio_sectors (bio);
@@ -1428,7 +1428,6 @@ static blk_qc_t null_submit_bio(struct bio *bio) cmd->bio = bio;null_handle_cmd (cmd, sector, nr_sectors,bio_op (bio)); -return BLK_QC_T_NONE ; }static bool should_timeout_request (struct request *rq)
drivers/block/pktcdvd.c +3 -4
@@ -2402,7 +2402,7 @@ static void pkt_make_request_write(struct request_queue *q, struct bio *bio) } } -static blk_qc_t pkt_submit_bio (struct bio *bio) +static void pkt_submit_bio (struct bio *bio) {struct pktcdvd_device *pd;char b[BDEVNAME_SIZE ];
@@ -2425,7 +2425,7 @@ static blk_qc_t pkt_submit_bio(struct bio *bio)*/ if (bio_data_dir (bio) ==READ ) {pkt_make_request_read (pd, bio); -return BLK_QC_T_NONE ; +return ; }if (!test_bit (PACKET_WRITABLE , &pd->flags)) {
@@ -2457,10 +2457,9 @@ static blk_qc_t pkt_submit_bio(struct bio *bio)pkt_make_request_write (bio->bi_bdev->bd_disk->queue, split); }while (split != bio); -return BLK_QC_T_NONE ; +return ; end_io:bio_io_error (bio); -return BLK_QC_T_NONE ; }static void pkt_init_queue (struct pktcdvd_device *pd)
drivers/block/ps3vram.c +2 -4
@@ -579,7 +579,7 @@ static struct bio *ps3vram_do_bio(struct ps3_system_bus_device *dev,return next; } -static blk_qc_t ps3vram_submit_bio (struct bio *bio) +static void ps3vram_submit_bio (struct bio *bio) {struct ps3_system_bus_device *dev = bio->bi_bdev->bd_disk->private_data;struct ps3vram_priv *priv =ps3_system_bus_get_drvdata (dev);
@@ -595,13 +595,11 @@ static blk_qc_t ps3vram_submit_bio(struct bio *bio)spin_unlock_irq (&priv->lock);if (busy) -return BLK_QC_T_NONE ; +return ;do { bio =ps3vram_do_bio (dev, bio); }while (bio); - -return BLK_QC_T_NONE ; }static const struct block_device_operations ps3vram_fops = {
drivers/block/rsxx/dev.c +3 -4
@@ -50,7 +50,7 @@ struct rsxx_bio_meta {static struct kmem_cache *bio_meta_pool; -static blk_qc_t rsxx_submit_bio (struct bio *bio); +static void rsxx_submit_bio (struct bio *bio);/*----------------- Block Device Operations -----------------*/ static int rsxx_blkdev_ioctl(struct block_device *bdev,
@@ -120,7 +120,7 @@ static void bio_dma_done_cb(struct rsxx_cardinfo *card, } } -static blk_qc_t rsxx_submit_bio (struct bio *bio) +static void rsxx_submit_bio (struct bio *bio) {struct rsxx_cardinfo *card = bio->bi_bdev->bd_disk->private_data;struct rsxx_bio_meta *bio_meta;
@@ -169,7 +169,7 @@ static blk_qc_t rsxx_submit_bio(struct bio *bio)if (st) goto queue_err; -return BLK_QC_T_NONE ; +return ; queue_err:kmem_cache_free (bio_meta_pool, bio_meta);
@@ -177,7 +177,6 @@ static blk_qc_t rsxx_submit_bio(struct bio *bio)if (st) bio->bi_status = st;bio_endio (bio); -return BLK_QC_T_NONE ; }/*----------------- Device Setup -------------------*/
drivers/block/umem.c +1 -3
@@ -519,7 +519,7 @@ static int mm_check_plugged(struct cardinfo *card)return !!blk_check_plugged (mm_unplug, card,sizeof (struct blk_plug_cb )); } -static blk_qc_t mm_submit_bio (struct bio *bio) +static void mm_submit_bio (struct bio *bio) {struct cardinfo *card = bio->bi_bdev->bd_disk->private_data;
@@ -536,8 +536,6 @@ static blk_qc_t mm_submit_bio(struct bio *bio)if (op_is_sync (bio->bi_opf) || !mm_check_plugged (card))activate (card);spin_unlock_irq (&card->lock); - -return BLK_QC_T_NONE ; }static irqreturn_t mm_interrupt (int irq,void *__card)
drivers/block/zram/zram_drv.c +3 -7
@@ -1598,22 +1598,18 @@ static void __zram_make_request(struct zram *zram, struct bio *bio)/* * Handler function for all zram I/O requests. */ -static blk_qc_t zram_submit_bio (struct bio *bio) +static void zram_submit_bio (struct bio *bio) {struct zram *zram = bio->bi_bdev->bd_disk->private_data;if (!valid_io_request (zram, bio->bi_iter.bi_sector, bio->bi_iter.bi_size)) {atomic64_inc (&zram->stats.invalid_io); - goto error; +bio_io_error (bio); +return ; }__zram_make_request (zram, bio); -return BLK_QC_T_NONE ; - -error: -bio_io_error (bio); -return BLK_QC_T_NONE ; } static void zram_slot_free_notify(struct block_device *bdev,
drivers/lightnvm/pblk-init.c +2 -4
@@ -47,7 +47,7 @@ static struct pblk_global_caches pblk_caches = {struct bio_set pblk_bio_set; -static blk_qc_t pblk_submit_bio (struct bio *bio) +static void pblk_submit_bio (struct bio *bio) {struct pblk *pblk = bio->bi_bdev->bd_disk->queue->queuedata;
@@ -55,7 +55,7 @@ static blk_qc_t pblk_submit_bio(struct bio *bio)pblk_discard (pblk, bio);if (!(bio->bi_opf &REQ_PREFLUSH )) {bio_endio (bio); -return BLK_QC_T_NONE ; +return ; } }
@@ -75,8 +75,6 @@ static blk_qc_t pblk_submit_bio(struct bio *bio)pblk_write_to_cache (pblk, bio,PBLK_IOTYPE_USER ); } - -return BLK_QC_T_NONE ; }static const struct block_device_operations pblk_bops = {
drivers/md/bcache/request.c +5 -8
@@ -1169,7 +1169,7 @@ static void quit_max_writeback_rate(struct cache_set *c,/* Cached devices - read & write stuff */ -blk_qc_t cached_dev_submit_bio (struct bio *bio) +void cached_dev_submit_bio (struct bio *bio) {struct search *s;struct block_device *orig_bdev = bio->bi_bdev;
@@ -1182,7 +1182,7 @@ blk_qc_t cached_dev_submit_bio(struct bio *bio) dc->io_disable)) { bio->bi_status =BLK_STS_IOERR ;bio_endio (bio); -return BLK_QC_T_NONE ; +return ; }if (likely (d->c)) {
@@ -1228,8 +1228,6 @@ blk_qc_t cached_dev_submit_bio(struct bio *bio) }else /* I/O request sent to backing device */ detached_dev_do_request (d, bio, orig_bdev, start_time); - -return BLK_QC_T_NONE ; } static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
@@ -1279,7 +1277,7 @@ static void flash_dev_nodata(struct closure *cl)continue_at (cl, search_free,NULL ); } -blk_qc_t flash_dev_submit_bio (struct bio *bio) +void flash_dev_submit_bio (struct bio *bio) {struct search *s;struct closure *cl;
@@ -1288,7 +1286,7 @@ blk_qc_t flash_dev_submit_bio(struct bio *bio)if (unlikely (d->c &&test_bit (CACHE_SET_IO_DISABLE , &d->c->flags))) { bio->bi_status =BLK_STS_IOERR ;bio_endio (bio); -return BLK_QC_T_NONE ; +return ; } s =search_alloc (bio, d, bio->bi_bdev,bio_start_io_acct (bio));
@@ -1304,7 +1302,7 @@ blk_qc_t flash_dev_submit_bio(struct bio *bio)continue_at_nobarrier (&s->cl, flash_dev_nodata, bcache_wq); -return BLK_QC_T_NONE ; +return ; }else if (bio_data_dir (bio)) { bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &KEY(d->id, bio->bi_iter.bi_sector, 0),
@@ -1320,7 +1318,6 @@ blk_qc_t flash_dev_submit_bio(struct bio *bio) }continue_at (cl, search_free,NULL ); -return BLK_QC_T_NONE ; } static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
drivers/md/bcache/request.h +2 -2
@@ -37,10 +37,10 @@ unsigned int bch_get_congested(const struct cache_set *c);void bch_data_insert (struct closure *cl);void bch_cached_dev_request_init (struct cached_dev *dc); -blk_qc_t cached_dev_submit_bio (struct bio *bio); +void cached_dev_submit_bio (struct bio *bio);void bch_flash_dev_request_init (struct bcache_device *d); -blk_qc_t flash_dev_submit_bio (struct bio *bio); +void flash_dev_submit_bio (struct bio *bio);extern struct kmem_cache *bch_search_cache;
drivers/md/dm.c +10 -18
@@ -1294,14 +1294,13 @@ static noinline void __set_swap_bios_limit(struct mapped_device *md, int latch)mutex_unlock (&md->swap_bios_lock); } -static blk_qc_t __map_bio (struct dm_target_io *tio) +static void __map_bio (struct dm_target_io *tio) {int r;sector_t sector;struct bio *clone = &tio->clone;struct dm_io *io = tio->io;struct dm_target *ti = tio->ti; -blk_qc_t ret =BLK_QC_T_NONE ; clone->bi_end_io = clone_endio;
@@ -1328,7 +1327,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)case DM_MAPIO_REMAPPED :/* the bio has been remapped so dispatch it */ trace_block_bio_remap (clone,bio_dev (io->orig_bio), sector); - ret =submit_bio_noacct (clone); +submit_bio_noacct (clone);break ;case DM_MAPIO_KILL :if (unlikely (swap_bios_limit (ti, clone))) {
@@ -1350,8 +1349,6 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)DMWARN ("unimplemented target map return value: %d" , r);BUG (); } - -return ret; }static void bio_setup_sector (struct bio *bio,sector_t sector,unsigned len)
@@ -1438,7 +1435,7 @@ static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci, } } -static blk_qc_t __clone_and_map_simple_bio (struct clone_info *ci, +static void __clone_and_map_simple_bio (struct clone_info *ci,struct dm_target_io *tio,unsigned *len) {struct bio *clone = &tio->clone;
@@ -1448,8 +1445,7 @@ static blk_qc_t __clone_and_map_simple_bio(struct clone_info *ci,__bio_clone_fast (clone, ci->bio);if (len)bio_setup_sector (clone, ci->sector, *len); - -return __map_bio (tio); +__map_bio (tio); } static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
@@ -1463,7 +1459,7 @@ static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,while ((bio =bio_list_pop (&blist))) { tio = container_of(bio, struct dm_target_io, clone); - (void )__clone_and_map_simple_bio (ci, tio, len); +__clone_and_map_simple_bio (ci, tio, len); } }
@@ -1507,7 +1503,7 @@ static int __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,free_tio (tio);return r; } - (void )__map_bio (tio); +__map_bio (tio);return 0 ; }
@@ -1622,11 +1618,10 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md,/* * Entry point to split a bio into clones and submit them to the targets. */ -static blk_qc_t __split_and_process_bio (struct mapped_device *md, +static void __split_and_process_bio (struct mapped_device *md,struct dm_table *map,struct bio *bio) {struct clone_info ci; -blk_qc_t ret =BLK_QC_T_NONE ;int error =0 ;init_clone_info (&ci, md, map, bio);
@@ -1670,7 +1665,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,bio_chain (b, bio);trace_block_split (b, bio->bi_iter.bi_sector); - ret =submit_bio_noacct (bio); +submit_bio_noacct (bio);break ; } }
@@ -1678,13 +1673,11 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,/* drop the extra reference count */ dec_pending (ci.io,errno_to_blk_status (error)); -return ret; } -static blk_qc_t dm_submit_bio (struct bio *bio) +static void dm_submit_bio (struct bio *bio) {struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; -blk_qc_t ret =BLK_QC_T_NONE ;int srcu_idx;struct dm_table *map;
@@ -1714,10 +1707,9 @@ static blk_qc_t dm_submit_bio(struct bio *bio)if (is_abnormal_io (bio))blk_queue_split (&bio); - ret =__split_and_process_bio (md, map, bio); +__split_and_process_bio (md, map, bio); out:dm_put_live_table (md, srcu_idx); -return ret; }/*-----------------------------------------------------------------
drivers/md/md.c +4 -6
@@ -465,19 +465,19 @@ static void md_end_io(struct bio *bio) bio->bi_end_io (bio); } -static blk_qc_t md_submit_bio (struct bio *bio) +static void md_submit_bio (struct bio *bio) {const int rw =bio_data_dir (bio);struct mddev *mddev = bio->bi_bdev->bd_disk->private_data;if (mddev ==NULL || mddev->pers ==NULL ) {bio_io_error (bio); -return BLK_QC_T_NONE ; +return ; }if (unlikely (test_bit (MD_BROKEN , &mddev->flags)) && (rw ==WRITE )) {bio_io_error (bio); -return BLK_QC_T_NONE ; +return ; }blk_queue_split (&bio);
@@ -486,7 +486,7 @@ static blk_qc_t md_submit_bio(struct bio *bio)if (bio_sectors (bio) !=0 ) bio->bi_status =BLK_STS_IOERR ;bio_endio (bio); -return BLK_QC_T_NONE ; +return ; }if (bio->bi_end_io != md_end_io) {
@@ -508,8 +508,6 @@ static blk_qc_t md_submit_bio(struct bio *bio) bio->bi_opf &= ~REQ_NOMERGE ;md_handle_request (mddev, bio); - -return BLK_QC_T_NONE ; }/* mddev_suspend makes sure no new requests are submitted
drivers/nvdimm/blk.c +2 -3
@@ -162,7 +162,7 @@ static int nsblk_do_bvec(struct nd_namespace_blk *nsblk,return err; } -static blk_qc_t nd_blk_submit_bio (struct bio *bio) +static void nd_blk_submit_bio (struct bio *bio) {struct bio_integrity_payload *bip;struct nd_namespace_blk *nsblk = bio->bi_bdev->bd_disk->private_data;
@@ -173,7 +173,7 @@ static blk_qc_t nd_blk_submit_bio(struct bio *bio)bool do_acct;if (!bio_integrity_prep (bio)) -return BLK_QC_T_NONE ; +return ; bip =bio_integrity (bio); rw =bio_data_dir (bio);
@@ -199,7 +199,6 @@ static blk_qc_t nd_blk_submit_bio(struct bio *bio)bio_end_io_acct (bio, start);bio_endio (bio); -return BLK_QC_T_NONE ; } static int nsblk_rw_bytes(struct nd_namespace_common *ndns,
drivers/nvdimm/btt.c +2 -3
@@ -1439,7 +1439,7 @@ static int btt_do_bvec(struct btt *btt, struct bio_integrity_payload *bip,return ret; } -static blk_qc_t btt_submit_bio (struct bio *bio) +static void btt_submit_bio (struct bio *bio) {struct bio_integrity_payload *bip =bio_integrity (bio);struct btt *btt = bio->bi_bdev->bd_disk->private_data;
@@ -1450,7 +1450,7 @@ static blk_qc_t btt_submit_bio(struct bio *bio)bool do_acct;if (!bio_integrity_prep (bio)) -return BLK_QC_T_NONE ; +return ; do_acct =blk_queue_io_stat (bio->bi_bdev->bd_disk->queue);if (do_acct)
@@ -1482,7 +1482,6 @@ static blk_qc_t btt_submit_bio(struct bio *bio)bio_end_io_acct (bio, start);bio_endio (bio); -return BLK_QC_T_NONE ; } static int btt_rw_page(struct block_device *bdev, sector_t sector,
drivers/nvdimm/pmem.c +1 -2
@@ -188,7 +188,7 @@ static blk_status_t pmem_do_write(struct pmem_device *pmem,return rc; } -static blk_qc_t pmem_submit_bio (struct bio *bio) +static void pmem_submit_bio (struct bio *bio) {int ret =0 ;blk_status_t rc =0 ;
@@ -227,7 +227,6 @@ static blk_qc_t pmem_submit_bio(struct bio *bio) bio->bi_status =errno_to_blk_status (ret);bio_endio (bio); -return BLK_QC_T_NONE ; } static int pmem_rw_page(struct block_device *bdev, sector_t sector,
drivers/nvme/host/core.c +1 -1
@@ -963,7 +963,7 @@ static void nvme_execute_rq_polled(struct request_queue *q,blk_execute_rq_nowait (bd_disk, rq, at_head, nvme_end_sync_rq);while (!completion_done (&wait)) { -blk_poll (q,request_to_qc_t (rq->mq_hctx, rq), true); +bio_poll (rq->bio, true);cond_resched (); } }
drivers/nvme/host/multipath.c +2 -4
@@ -294,12 +294,11 @@ static bool nvme_available_path(struct nvme_ns_head *head)return false; } -blk_qc_t nvme_ns_head_submit_bio (struct bio *bio) +void nvme_ns_head_submit_bio (struct bio *bio) {struct nvme_ns_head *head = bio->bi_bdev->bd_disk->private_data;struct device *dev =disk_to_dev (head->disk);struct nvme_ns *ns; -blk_qc_t ret =BLK_QC_T_NONE ;int srcu_idx;/*
@@ -316,7 +315,7 @@ blk_qc_t nvme_ns_head_submit_bio(struct bio *bio) bio->bi_opf |=REQ_NVME_MPATH ;trace_block_bio_remap (bio,disk_devt (ns->head->disk), bio->bi_iter.bi_sector); - ret =submit_bio_noacct (bio); +submit_bio_noacct (bio); }else if (nvme_available_path (head)) {dev_warn_ratelimited (dev,"no usable path - requeuing I/O\n" );
@@ -331,7 +330,6 @@ blk_qc_t nvme_ns_head_submit_bio(struct bio *bio) }srcu_read_unlock (&head->srcu, srcu_idx); -return ret; }static void nvme_requeue_work (struct work_struct *work)
drivers/nvme/host/nvme.h +1 -1
@@ -674,7 +674,7 @@ void nvme_mpath_stop(struct nvme_ctrl *ctrl);bool nvme_mpath_clear_current_path (struct nvme_ns *ns);void nvme_mpath_clear_ctrl_paths (struct nvme_ctrl *ctrl);struct nvme_ns *nvme_find_path (struct nvme_ns_head *head); -blk_qc_t nvme_ns_head_submit_bio (struct bio *bio); +void nvme_ns_head_submit_bio (struct bio *bio);static inline void nvme_mpath_check_last_path (struct nvme_ns *ns) {
drivers/s390/block/dcssblk.c +3 -4
@@ -31,7 +31,7 @@static int dcssblk_open (struct block_device *bdev,fmode_t mode);static void dcssblk_release (struct gendisk *disk,fmode_t mode); -static blk_qc_t dcssblk_submit_bio (struct bio *bio); +static void dcssblk_submit_bio (struct bio *bio);static long dcssblk_dax_direct_access (struct dax_device *dax_dev,pgoff_t pgoff,long nr_pages,void **kaddr,pfn_t *pfn);
@@ -865,7 +865,7 @@ dcssblk_release(struct gendisk *disk, fmode_t mode)up_write (&dcssblk_devices_sem); } -static blk_qc_t +static void dcssblk_submit_bio (struct bio *bio) {struct dcssblk_dev_info *dev_info;
@@ -919,10 +919,9 @@ dcssblk_submit_bio(struct bio *bio) bytes_done += bvec.bv_len; }bio_endio (bio); -return BLK_QC_T_NONE ; +return ; fail:bio_io_error (bio); -return BLK_QC_T_NONE ; } static long
drivers/s390/block/xpram.c +2 -3
@@ -182,7 +182,7 @@ static unsigned long xpram_highest_page_index(void)/* * Block device make request function. */ -static blk_qc_t xpram_submit_bio (struct bio *bio) +static void xpram_submit_bio (struct bio *bio) {xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data;struct bio_vec bvec;
@@ -224,10 +224,9 @@ static blk_qc_t xpram_submit_bio(struct bio *bio) } }bio_endio (bio); -return BLK_QC_T_NONE ; +return ; fail:bio_io_error (bio); -return BLK_QC_T_NONE ; }static int xpram_getgeo (struct block_device *bdev,struct hd_geometry *geo)
fs/block_dev.c +8 -17
@@ -239,7 +239,6 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,bool should_dirty = false;struct bio bio;ssize_t ret; -blk_qc_t qc;if ((pos |iov_iter_alignment (iter)) & (bdev_logical_block_size (bdev) -1 ))
@@ -278,13 +277,12 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,if (iocb->ki_flags &IOCB_HIPRI )bio_set_polled (&bio, iocb); - qc =submit_bio (&bio); +submit_bio (&bio);for (;;) {set_current_state (TASK_UNINTERRUPTIBLE );if (!READ_ONCE (bio.bi_private))break ; -if (!(iocb->ki_flags &IOCB_HIPRI ) || - !blk_poll (bdev_get_queue (bdev), qc, true)) +if (!(iocb->ki_flags &IOCB_HIPRI ) || !bio_poll (&bio, true))blk_io_schedule (); }__set_current_state (TASK_RUNNING );
@@ -317,14 +315,6 @@ struct blkdev_dio {static struct bio_set blkdev_dio_pool; -static int blkdev_iopoll (struct kiocb *kiocb,bool wait) -{ -struct block_device *bdev =I_BDEV (kiocb->ki_filp->f_mapping->host); -struct request_queue *q =bdev_get_queue (bdev); - -return blk_poll (q,READ_ONCE (kiocb->ki_cookie), wait); -} -static void blkdev_bio_end_io (struct bio *bio) {struct blkdev_dio *dio = bio->bi_private;
@@ -338,6 +328,8 @@ static void blkdev_bio_end_io(struct bio *bio)struct kiocb *iocb = dio->iocb;ssize_t ret; +WRITE_ONCE (iocb->private,NULL ); +if (likely (!dio->bio.bi_status)) { ret = dio->size; iocb->ki_pos += ret;
@@ -376,7 +368,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bool is_poll = (iocb->ki_flags &IOCB_HIPRI ), do_poll = false;bool is_read = (iov_iter_rw (iter) ==READ ), is_sync;loff_t pos = iocb->ki_pos; -blk_qc_t qc =BLK_QC_T_NONE ;int ret =0 ; if ((pos | iov_iter_alignment(iter)) &
@@ -449,10 +440,10 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,bio_set_polled (bio, iocb); do_poll = true; } - qc =submit_bio (bio); +submit_bio (bio);if (!nr_pages) {if (do_poll) -WRITE_ONCE (iocb->ki_cookie, qc); +WRITE_ONCE (iocb->private, bio);break ; } bio =bio_alloc (GFP_KERNEL , nr_pages);
@@ -469,7 +460,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,if (!READ_ONCE (dio->waiter))break ; -if (!do_poll || !blk_poll (bdev_get_queue (bdev), qc, true)) +if (!do_poll || !bio_poll (bio, true))blk_io_schedule (); }__set_current_state (TASK_RUNNING );
@@ -1823,7 +1814,7 @@ const struct file_operations def_blk_fops = { .llseek = block_llseek, .read_iter = blkdev_read_iter, .write_iter = blkdev_write_iter, - .iopoll = blkdev_iopoll, + .iopoll = iocb_bio_iopoll, .mmap = generic_file_mmap, .fsync = blkdev_fsync, .unlocked_ioctl = block_ioctl,
fs/btrfs/inode.c +3 -5
@@ -8095,7 +8095,7 @@ static struct btrfs_dio_private *btrfs_create_dio_private(struct bio *dio_bio,return dip; } -static blk_qc_t btrfs_submit_direct (struct inode *inode,struct iomap *iomap, +static void btrfs_submit_direct (struct inode *inode,struct iomap *iomap,struct bio *dio_bio,loff_t file_offset) {const bool write = (btrfs_op (dio_bio) ==BTRFS_MAP_WRITE );
@@ -8124,7 +8124,7 @@ static blk_qc_t btrfs_submit_direct(struct inode *inode, struct iomap *iomap, } dio_bio->bi_status =BLK_STS_RESOURCE ;bio_endio (dio_bio); -return BLK_QC_T_NONE ; +return ; }if (!write) {
@@ -8222,15 +8222,13 @@ static blk_qc_t btrfs_submit_direct(struct inode *inode, struct iomap *iomap,free_extent_map (em); }while (submit_len >0 ); -return BLK_QC_T_NONE ; +return ; out_err_em:free_extent_map (em); out_err: dip->dio_bio->bi_status = status;btrfs_dio_private_put (dip); - -return BLK_QC_T_NONE ; }const struct iomap_ops btrfs_dio_iomap_ops = {
fs/ext4/file.c +1 -1
@@ -896,7 +896,7 @@ const struct file_operations ext4_file_operations = { .llseek = ext4_llseek, .read_iter = ext4_file_read_iter, .write_iter = ext4_file_write_iter, - .iopoll = iomap_dio_iopoll, + .iopoll = iocb_bio_iopoll, .unlocked_ioctl = ext4_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = ext4_compat_ioctl,
fs/gfs2/file.c +2 -2
@@ -1359,7 +1359,7 @@ const struct file_operations gfs2_file_fops = { .llseek = gfs2_llseek, .read_iter = gfs2_file_read_iter, .write_iter = gfs2_file_write_iter, - .iopoll = iomap_dio_iopoll, + .iopoll = iocb_bio_iopoll, .unlocked_ioctl = gfs2_ioctl, .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap,
@@ -1392,7 +1392,7 @@ const struct file_operations gfs2_file_fops_nolock = { .llseek = gfs2_llseek, .read_iter = gfs2_file_read_iter, .write_iter = gfs2_file_write_iter, - .iopoll = iomap_dio_iopoll, + .iopoll = iocb_bio_iopoll, .unlocked_ioctl = gfs2_ioctl, .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap,
fs/iomap/direct-io.c +13 -26
@@ -38,8 +38,7 @@ struct iomap_dio {struct {struct iov_iter *iter;struct task_struct *waiter; -struct request_queue *last_queue; -blk_qc_t cookie; +struct bio *poll_bio; } submit;/* used for aio completion: */
@@ -49,31 +48,21 @@ struct iomap_dio { }; }; -int iomap_dio_iopoll (struct kiocb *kiocb,bool spin) -{ -struct request_queue *q =READ_ONCE (kiocb->private); - -if (!q) -return 0 ; -return blk_poll (q,READ_ONCE (kiocb->ki_cookie), spin); -} -EXPORT_SYMBOL_GPL (iomap_dio_iopoll); -static void iomap_dio_submit_bio (struct iomap_dio *dio,struct iomap *iomap,struct bio *bio,loff_t pos) {atomic_inc (&dio->ref); -if (dio->iocb->ki_flags &IOCB_HIPRI ) +if (dio->iocb->ki_flags &IOCB_HIPRI ) {bio_set_polled (bio, dio->iocb); + dio->submit.poll_bio = bio; + } - dio->submit.last_queue =bdev_get_queue (iomap->bdev);if (dio->dops && dio->dops->submit_io) - dio->submit.cookie = dio->dops->submit_io ( -file_inode (dio->iocb->ki_filp), - iomap, bio, pos); + dio->dops->submit_io (file_inode (dio->iocb->ki_filp), iomap, bio, + pos);else - dio->submit.cookie =submit_bio (bio); +submit_bio (bio); }ssize_t iomap_dio_complete (struct iomap_dio *dio)
@@ -166,9 +155,11 @@ static void iomap_dio_bio_end_io(struct bio *bio) }else if (dio->flags &IOMAP_DIO_WRITE ) {struct inode *inode =file_inode (dio->iocb->ki_filp); +WRITE_ONCE (dio->iocb->private,NULL );INIT_WORK (&dio->aio.work, iomap_dio_complete_work);queue_work (inode->i_sb->s_dio_done_wq, &dio->aio.work); }else { +WRITE_ONCE (dio->iocb->private,NULL );iomap_dio_complete_work (&dio->aio.work); } }
@@ -492,8 +483,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->submit.iter = iter; dio->submit.waiter = current; - dio->submit.cookie =BLK_QC_T_NONE ; - dio->submit.last_queue =NULL ; + dio->submit.poll_bio =NULL ;if (iov_iter_rw (iter) ==READ ) {if (pos >= dio->i_size)
@@ -601,8 +591,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,if (dio->flags &IOMAP_DIO_WRITE_FUA ) dio->flags &= ~IOMAP_DIO_NEED_SYNC ; -WRITE_ONCE (iocb->ki_cookie, dio->submit.cookie); -WRITE_ONCE (iocb->private, dio->submit.last_queue); +WRITE_ONCE (iocb->private, dio->submit.poll_bio);/* * We are about to drop our additional submission reference, which
@@ -629,10 +618,8 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,if (!READ_ONCE (dio->submit.waiter))break ; -if (!(iocb->ki_flags &IOCB_HIPRI ) || - !dio->submit.last_queue || - !blk_poll (dio->submit.last_queue, - dio->submit.cookie, true)) +if (!dio->submit.poll_bio || + !bio_poll (dio->submit.poll_bio, true))blk_io_schedule (); }__set_current_state (TASK_RUNNING );
fs/xfs/xfs_file.c +1 -1
@@ -1429,7 +1429,7 @@ const struct file_operations xfs_file_operations = { .write_iter = xfs_file_write_iter, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, - .iopoll = iomap_dio_iopoll, + .iopoll = iocb_bio_iopoll, .unlocked_ioctl = xfs_file_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = xfs_file_compat_ioctl,
fs/zonefs/super.c +1 -1
@@ -1143,7 +1143,7 @@ static const struct file_operations zonefs_file_operations = { .write_iter = zonefs_file_write_iter, .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, - .iopoll = iomap_dio_iopoll, + .iopoll = iocb_bio_iopoll, };static struct kmem_cache *zonefs_inode_cachep;
include/linux/bio.h +1 -1
@@ -426,7 +426,7 @@ static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned short nr_iovecs)return bio_alloc_bioset (gfp_mask, nr_iovecs, &fs_bio_set); } -extern blk_qc_t submit_bio (struct bio *); +void submit_bio (struct bio *bio);extern void bio_endio (struct bio *);
include/linux/blk-mq.h +2 -13
@@ -148,9 +148,9 @@ struct blk_mq_hw_ctx {/** @kobj: Kernel object for sysfs. */ struct kobject kobj; -/** @poll_considered: Count times blk_poll() was called. */ +/** @poll_considered: Count times blk_mq_poll() was called. */ unsigned long poll_considered; -/** @poll_invoked: Count how many requests blk_poll() polled. */ +/** @poll_invoked: Count how many requests blk_mq_poll() polled. */ unsigned long poll_invoked;/** @poll_success: Count how many polled requests were completed. */ unsigned long poll_success;
@@ -586,16 +586,6 @@ static inline void *blk_mq_rq_to_pdu(struct request *rq)for ((i) =0 ; (i) < (hctx)->nr_ctx && \ ({ ctx = (hctx)->ctxs[(i)];1 ; }); (i)++) -static inline blk_qc_t request_to_qc_t(struct blk_mq_hw_ctx *hctx, -struct request *rq) -{ -if (rq->tag !=-1 ) -return rq->tag | (hctx->queue_num <<BLK_QC_T_SHIFT ); - -return rq->internal_tag | (hctx->queue_num <<BLK_QC_T_SHIFT ) | -BLK_QC_T_INTERNAL ; -} - static inline void blk_mq_cleanup_rq(struct request *rq) {if (rq->q->mq_ops->cleanup_rq)
@@ -614,7 +604,6 @@ static inline void blk_rq_bio_prep(struct request *rq, struct bio *bio, rq->rq_disk = bio->bi_bdev->bd_disk; } -blk_qc_t blk_mq_submit_bio (struct bio *bio);void blk_mq_hctx_set_fq_lock_class (struct blk_mq_hw_ctx *hctx,struct lock_class_key *key);
include/linux/blk_types.h +5 -7
@@ -217,6 +217,9 @@ static inline void bio_issue_init(struct bio_issue *issue, ((u64)size << BIO_ISSUE_SIZE_SHIFT)); } +typedef unsigned int blk_qc_t ; +#define BLK_QC_T_NONE -1U +/* * main unit of I/O for the block layer and lower layers (ie drivers and * stacking drivers)
@@ -238,9 +241,9 @@ struct bio {struct bvec_iter bi_iter;struct rcu_head bi_rcu_free; }; +blk_qc_t bi_cookie;bio_end_io_t *bi_end_io; -void *bi_private;#ifdef CONFIG_BLK_CGROUP /*
@@ -396,7 +399,7 @@ enum req_flag_bits {/* command specific flags for REQ_OP_WRITE_ZEROES: */ __REQ_NOUNMAP,/* do not free blocks when zeroing */ - __REQ_POLLED,/* caller polls for completion using blk_poll */ + __REQ_POLLED,/* caller polls for completion using bio_poll */ /* for driver use */ __REQ_DRV,
@@ -509,11 +512,6 @@ static inline int op_stat_group(unsigned int op)return op_is_write (op); } -typedef unsigned int blk_qc_t ; -#define BLK_QC_T_NONE -1U -#define BLK_QC_T_SHIFT 16 -#define BLK_QC_T_INTERNAL (1U << 31) -struct blk_rq_stat {u64 mean;u64 min;
include/linux/blkdev.h +5 -3
@@ -38,6 +38,7 @@ struct sg_io_hdr;struct bsg_job ;struct blkcg_gq ;struct blk_flush_queue ; +struct kiocb ;struct pr_ops ;struct rq_qos ;struct blk_queue_stats ;
@@ -904,7 +905,7 @@ static inline void rq_flush_dcache_pages(struct request *rq)extern int blk_register_queue (struct gendisk *disk);extern void blk_unregister_queue (struct gendisk *disk); -blk_qc_t submit_bio_noacct (struct bio *bio); +void submit_bio_noacct (struct bio *bio);extern void blk_rq_init (struct request_queue *q,struct request *rq);extern void blk_put_request (struct request *); extern struct request *blk_get_request(struct request_queue *, unsigned int op,
@@ -950,7 +951,8 @@ extern const char *blk_op_str(unsigned int op);int blk_status_to_errno (blk_status_t status);blk_status_t errno_to_blk_status (int errno); -int blk_poll (struct request_queue *q,blk_qc_t cookie,bool spin); +int bio_poll (struct bio *bio,bool spin); +int iocb_bio_iopoll (struct kiocb *kiocb,bool spin);static inline struct request_queue *bdev_get_queue (struct block_device *bdev) {
@@ -1855,7 +1857,7 @@ static inline void blk_ksm_unregister(struct request_queue *q) { }struct block_device_operations { -blk_qc_t (*submit_bio) (struct bio *bio); +void (*submit_bio)(struct bio *bio);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 );
include/linux/fs.h +1 -5
@@ -331,11 +331,7 @@ struct kiocb {int ki_flags;u16 ki_hint;u16 ki_ioprio;/* See linux/ioprio.h */ -union { -unsigned int ki_cookie;/* for ->iopoll */ -struct wait_page_queue *ki_waitq;/* for async buffered IO */ - }; - +struct wait_page_queue *ki_waitq;/* for async buffered IO */ randomized_struct_fields_end };
include/linux/iomap.h +1 -2
@@ -254,7 +254,7 @@ int iomap_writepages(struct address_space *mapping,struct iomap_dio_ops {int (*end_io)(struct kiocb *iocb,ssize_t size,int error,unsigned flags); -blk_qc_t (*submit_io)(struct inode *inode,struct iomap *iomap, +void (*submit_io)(struct inode *inode,struct iomap *iomap,struct bio *bio,loff_t file_offset); };
@@ -278,7 +278,6 @@ struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags);ssize_t iomap_dio_complete (struct iomap_dio *dio); -int iomap_dio_iopoll (struct kiocb *kiocb,bool spin);#ifdef CONFIG_SWAP struct file ;
mm/page_io.c +2 -6
@@ -358,8 +358,6 @@ int swap_readpage(struct page *page, bool synchronous)struct bio *bio;int ret =0 ;struct swap_info_struct *sis =page_swap_info (page); -blk_qc_t qc; -struct gendisk *disk;unsigned long pflags;VM_BUG_ON_PAGE (!PageSwapCache (page) && !synchronous, page);
@@ -409,8 +407,6 @@ int swap_readpage(struct page *page, bool synchronous) bio->bi_iter.bi_sector =swap_page_sector (page); bio->bi_end_io = end_swap_bio_read;bio_add_page (bio, page,thp_size (page),0 ); - - disk = bio->bi_bdev->bd_disk;/* * Keep this task valid during swap readpage because the oom killer may * attempt to access it in the page fault retry time check.
@@ -422,13 +418,13 @@ int swap_readpage(struct page *page, bool synchronous) }count_vm_event (PSWPIN );bio_get (bio); - qc =submit_bio (bio); +submit_bio (bio);while (synchronous) {set_current_state (TASK_UNINTERRUPTIBLE );if (!READ_ONCE (bio->bi_private))break ; -if (!blk_poll (disk->queue, qc, true)) +if (!bio_poll (bio, true))blk_io_schedule (); }__set_current_state (TASK_RUNNING );
Signature · 1 line
2.30.1
Re: [PATCH 12/12] block: switch polling to be bio based
Quoted 297 lines · Christoph Hellwig
Replace the
blk_pollinterface that requires the caller to keep a queue and cookie from the submissions with polling based on the bio.Polling for the bio itself leads to a few advantages:
- the cookie construction can made entirely private in
blk-mq.c
- the caller does not need to remember therequest_queueand cookie separately and thus sidesteps their lifetime issues
- keeping the device and the cookie inside the bio allows to trivially support polling BIOs remapping by stacking drivers
- a lot of code to propagate the cookie back up the submission path can be removed entirely.Signed-off-by Christoph Hellwig <[email protected]>--- arch/m68k/emu/nfblock.c | 3 +- arch/xtensa/platforms/iss/simdisk.c | 3 +- block/bio.c | 1 + block/blk-core.c | 103 +++++++++++++++++++--------- block/blk-mq.c | 75 +++++++------------- block/blk-mq.h | 2 + drivers/block/brd.c | 12 ++-- drivers/block/drbd/drbd_int.h | 2 +- drivers/block/drbd/drbd_req.c | 3 +- drivers/block/n64cart.c | 12 ++-- drivers/block/null_blk/main.c | 3 +- drivers/block/pktcdvd.c | 7 +- drivers/block/ps3vram.c | 6 +- drivers/block/rsxx/dev.c | 7 +- drivers/block/umem.c | 4 +- drivers/block/zram/zram_drv.c | 10 +-- drivers/lightnvm/pblk-init.c | 6 +- drivers/md/bcache/request.c | 13 ++-- drivers/md/bcache/request.h | 4 +- drivers/md/dm.c | 28 +++----- drivers/md/md.c | 10 ++- drivers/nvdimm/blk.c | 5 +- drivers/nvdimm/btt.c | 5 +- drivers/nvdimm/pmem.c | 3 +- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 6 +- drivers/nvme/host/nvme.h | 2 +- drivers/s390/block/dcssblk.c | 7 +- drivers/s390/block/xpram.c | 5 +- fs/block_dev.c | 25 +++---- fs/btrfs/inode.c | 8 +-- fs/ext4/file.c | 2 +- fs/gfs2/file.c | 4 +- fs/iomap/direct-io.c | 39 ++++------- fs/xfs/xfs_file.c | 2 +- fs/zonefs/super.c | 2 +- include/linux/bio.h | 2 +- include/linux/blk-mq.h | 15 +--- include/linux/blk_types.h | 12 ++-- include/linux/blkdev.h | 8 ++- include/linux/fs.h | 6 +- include/linux/iomap.h | 3 +- mm/page_io.c | 8 +-- 43 files changed, 208 insertions(+), 277 deletions(-)arch/m68k/emu/nfblock.c +1
-2@@ -59,7 +59,7 @@ struct nfhd_device {struct gendisk *disk; }; -static blk_qc_t nfhd_submit_bio (struct bio *bio) +static void nfhd_submit_bio (struct bio *bio) {struct nfhd_device *dev = bio->bi_bdev->bd_disk->private_data;struct bio_vec bvec;@@ -77,7 +77,6 @@ static blk_qc_t nfhd_submit_bio(struct bio *bio) sec += len; }bio_endio (bio); -return BLK_QC_T_NONE ; }static int nfhd_getgeo (struct block_device *bdev,struct hd_geometry *geo)arch/xtensa/platforms/iss/simdisk.c +1
-2@@ -101,7 +101,7 @@ static void simdisk_transfer(struct simdisk *dev, unsigned long sector,spin_unlock (&dev->lock); } -static blk_qc_t simdisk_submit_bio (struct bio *bio) +static void simdisk_submit_bio (struct bio *bio) {struct simdisk *dev = bio->bi_bdev->bd_disk->private_data;struct bio_vec bvec;@@ -119,7 +119,6 @@ static blk_qc_t simdisk_submit_bio(struct bio *bio) }bio_endio (bio); -return BLK_QC_T_NONE ; }static int simdisk_open (struct block_device *bdev,fmode_t mode)block/bio.c +1
-0@@ -259,6 +259,7 @@ void bio_init(struct bio *bio, struct bio_vec *table,memset (bio,0 ,sizeof (*bio));atomic_set (&bio->__bi_remaining,1 );atomic_set (&bio->__bi_cnt,1 ); + bio->bi_cookie =BLK_QC_T_NONE ; bio->bi_io_vec = table; bio->bi_max_vecs = max_vecs;block/blk-core.c +57
-31@@ -910,18 +910,18 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio)return false; } -static blk_qc_t __submit_bio (struct bio *bio) +static void __submit_bio (struct bio *bio) {struct gendisk *disk = bio->bi_bdev->bd_disk; -blk_qc_t ret =BLK_QC_T_NONE ;if (blk_crypto_bio_prep (&bio)) { -if (!disk->fops->submit_bio) -return blk_mq_submit_bio (bio); - ret = disk->fops->submit_bio (bio); +if (!disk->fops->submit_bio) { +blk_mq_submit_bio (bio); +return ; + } + disk->fops->submit_bio (bio); }blk_queue_exit (disk->queue); -return ret; }/* @@ -943,10 +943,9 @@ static blk_qc_t __submit_bio(struct bio *bio)* bio_list_on_stack[1] contains bios that were submitted before the current * ->submit_bio_bio, but that haven't been processed yet. */ -static blk_qc_t __submit_bio_noacct (struct bio *bio) +static void __submit_bio_noacct (struct bio *bio) {struct bio_list bio_list_on_stack[2 ]; -blk_qc_t ret =BLK_QC_T_NONE ;BUG_ON (bio->bi_next);@@ -966,7 +965,7 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio) bio_list_on_stack[1 ] = bio_list_on_stack[0 ];bio_list_init (&bio_list_on_stack[0 ]); - ret =__submit_bio (bio); +__submit_bio (bio);/* * Sort new bios into those for a lower level and those for the @@ -989,13 +988,11 @@ static blk_qc_t __submit_bio_noacct(struct bio *bio) }while ((bio =bio_list_pop (&bio_list_on_stack[0 ]))); current->bio_list =NULL ; -return ret; } -static blk_qc_t __submit_bio_noacct_mq (struct bio *bio) +static void __submit_bio_noacct_mq (struct bio *bio) {struct bio_list bio_list[2 ] = { }; -blk_qc_t ret =BLK_QC_T_NONE ; current->bio_list = bio_list;@@ -1007,15 +1004,13 @@ static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)if (!blk_crypto_bio_prep (&bio)) {blk_queue_exit (disk->queue); - ret =BLK_QC_T_NONE ;continue ; } - ret =blk_mq_submit_bio (bio); +blk_mq_submit_bio (bio); }while ((bio =bio_list_pop (&bio_list[0 ]))); current->bio_list =NULL ; -return ret; }/** @@ -1027,10 +1022,10 @@ static blk_qc_t __submit_bio_noacct_mq(struct bio *bio)* systems and other upper level users of the block layer should use * submit_bio() instead. */ -blk_qc_t submit_bio_noacct (struct bio *bio) +void submit_bio_noacct (struct bio *bio) {if (!submit_bio_checks (bio)) -return BLK_QC_T_NONE ; +return ;/* * We only want one ->submit_bio to be active at a time, else stack @@ -1038,14 +1033,12 @@ blk_qc_t submit_bio_noacct(struct bio *bio)* to collect a list of requests submited by a ->submit_bio method while * it is active, and then process them after it returned. */ -if (current->bio_list) { +if (current->bio_list)bio_list_add (¤t->bio_list[0 ], bio); -return BLK_QC_T_NONE ; - } - -if (!bio->bi_bdev->bd_disk->fops->submit_bio) -return __submit_bio_noacct_mq (bio); -return __submit_bio_noacct (bio); +else if (!bio->bi_bdev->bd_disk->fops->submit_bio) +__submit_bio_noacct_mq (bio); +else +__submit_bio_noacct (bio); }EXPORT_SYMBOL (submit_bio_noacct);@@ -1062,10 +1055,10 @@ EXPORT_SYMBOL(submit_bio_noacct);* in @bio. The bio must NOT be touched by thecaller until ->bi_end_io() has * been called. */ -blk_qc_t submit_bio (struct bio *bio) +void submit_bio (struct bio *bio) {if (blkcg_punt_bio_submit (bio)) -return BLK_QC_T_NONE ; +return ;/* * If it's a regular read/write or a barrier with data attached, @@ -1106,19 +1099,67 @@ blk_qc_t submit_bio(struct bio *bio)if (unlikely (bio_op (bio) ==REQ_OP_READ &&bio_flagged (bio,BIO_WORKINGSET ))) {unsigned long pflags; -blk_qc_t ret;psi_memstall_enter (&pflags); - ret =submit_bio_noacct (bio); +submit_bio_noacct (bio);psi_memstall_leave (&pflags); - -return ret; +return ; } -return submit_bio_noacct (bio); +submit_bio_noacct (bio); }EXPORT_SYMBOL (submit_bio); +/** +* bio_poll - poll for BIO completions +* @bio: bio to poll for +* +* Poll for completions on queue associated with the bio. Returns number of +* completed entries found. If @spin is true, then bio_poll will continue +* looping until at least one completion is found, unless the task is +* otherwise marked running (or we need to reschedule). +* +* Note: the caller must either be the context that submitted @bio, or +* be in a RCU critical section to prevent freeing of @bio. +*/ +int bio_poll (struct bio *bio,bool spin) +{ +struct request_queue *q = bio->bi_bdev->bd_disk->queue; +blk_qc_t cookie =READ_ONCE (bio->bi_cookie); + +if (cookie ==BLK_QC_T_NONE || + !test_bit (QUEUE_FLAG_POLL , &q->queue_flags)) +return 0 ; + +if (current->plug) +blk_flush_plug_list (current->plug, false); + +/* not yet implemented, so this should not happen */ +if (WARN_ON_ONCE (!queue_is_mq (q))) +return 0 ; +return blk_mq_poll (q, cookie, spin); +} +EXPORT_SYMBOL_GPL (bio_poll); + +/* +* Helper to implements file_operations.iopoll. Requires the bio to be stored +* in iocb->private, and cleared before freeing the bio. +*/
block/blk-core.c blk_qc_t submit_bio(struct bio *bio) · line 1157
Quoted 10 lines
block/blk-core.c +10
-0+int iocb_bio_iopoll (struct kiocb *kiocb,bool spin) +{ +struct bio *bio; +int ret =0 ; + +rcu_read_lock (); + bio =READ_ONCE (kiocb->private); +if (bio) + ret =bio_poll (bio, spin); +rcu_read_unlock ();
If bio_poll() sleeps in case of 'spin', rcu_read_lock() can't be used. And the POLLED bio may be ended by iocb_bio_iopoll() explicitly via one bio flag.
Thanks,
Ming
Jens Axboe
maintainerQuoted 15 lines · Christoph Hellwig
Hi all,
This series clean up the block polling code a bit and changes the interface to poll for a specific bio instead of a
request_queueand cookie pair.Polling for the bio itself leads to a few advantages:
- the cookie construction can made entirely private in
blk-mq.c
- the caller does not need to remember therequest_queueand cookie separately and thus sidesteps their lifetime issues
- keeping the device and the cookie inside the bio allows to trivially support polling BIOs remapping by stacking drivers
- a lot of code to propagate the cookie back up the submission path can removed entirely
Quoted 4 lines
The one major caveat is that this requires RCU freeing polled BIOs to make sure the bio that contains the polling information is still alive when
io_uringtries to poll it through the iocb. For synchronous polling all the callers have a bio reference anyway, so this is not an issue.
Was curious about this separately, so ran a quick test on it. Running polled IO on a fast device, performance drops about 10% with this applied. Outside of that, we have ksoftirqd using 5-7% of CPU continually, just doing frees:
+ 45.33% ksoftirqd/0 [kernel.vmlinux] [k] __slab_free + 15.91% ksoftirqd/0 [kernel.vmlinux] [k] kmem_cache_free + 12.66% ksoftirqd/0 [kernel.vmlinux] [k] rcu_cblist_dequeue + 8.39% ksoftirqd/0 [kernel.vmlinux] [k] rcu_core + 4.75% ksoftirqd/0 [kernel.vmlinux] [k] free_one_page + 3.27% ksoftirqd/0 [kernel.vmlinux] [k] bio_free_rcu + 1.98% ksoftirqd/0 [kernel.vmlinux] [k] mempool_free_slab
This all means that we go from 2.97M IOPS to 2.70M IOPS in that particular test (QD=128, async polled).
I was separately curious about this as I have a (as of yet unposted) patchset that recycles bio allocations, as we spend quite a bit of time doing that for high rate polled IO. It's good for taking the above 2.97M IOPS to 3.2-3.3M IOPS, and it'd obviously be a bit more problematic with required RCU freeing of bio's. Even without the alloc cache, using RCU will ruin any potential cache locality on back-to-back bio free + bio alloc.
Signature · 1 line
Jens Axboe
Christoph Hellwig
maintainerQuoted 7 lines · Jens Axboe
I was separately curious about this as I have a (as of yet unposted) patchset that recycles bio allocations, as we spend quite a bit of time doing that for high rate polled IO. It's good for taking the above 2.97M IOPS to 3.2-3.3M IOPS, and it'd obviously be a bit more problematic with required RCU freeing of bio's. Even without the alloc cache, using RCU will ruin any potential cache locality on back-to-back bio free + bio alloc.
That sucks indeed. How do you recycle the bios? If we make sure the bio is only ever recycled as a bio and bi_bdev remaings valid long enough we might not need the rcu free. Even without your recycling we could probably do something nasty using SLAB_TYPESAFE_BY_RCU.
Jens Axboe
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 7 lines · Jens Axboe
I was separately curious about this as I have a (as of yet unposted) patchset that recycles bio allocations, as we spend quite a bit of time doing that for high rate polled IO. It's good for taking the above 2.97M IOPS to 3.2-3.3M IOPS, and it'd obviously be a bit more problematic with required RCU freeing of bio's. Even without the alloc cache, using RCU will ruin any potential cache locality on back-to-back bio free + bio alloc.
That sucks indeed. How do you recycle the bios? If we make sure the
Here's the series. It's not super clean (yet), but basically allows users like io_uring to setup a bio cache, and pass that in through iocb->ki_bi_cache. With that, we can recycle them instead of going through free+alloc continually. If you look at profiles for high iops, we're spending more time than desired doing just that.
https://git.kernel.dk/cgit/linux-block/log/?h=io_uring-bio-cache
Quoted 3 lines
bio is only ever recycled as a bio and
bi_bdevremaings valid long enough we might not need the rcu free. Even without your recycling we could probably do something nasty usingSLAB_TYPESAFE_BY_RCU.
It would not be hard to restrict to same bdev for the cache, just one more check to do for recycling.
Note that the caching series _only_ supports polled IO for now, as non-polled would require IRQ juggling for free+alloc and that will definitely take some of the win away and maybe even render it moot. Have yet to test that part out. Not a huge deal with the RCU free, as you end up doing that purely for polled IO and hence wouldn't impact the IRQ side of things negatively.
Signature · 1 line
Jens Axboe
Christoph Hellwig
maintainerQuoted 7 lines · Jens Axboe
Here's the series. It's not super clean (yet), but basically allows users like
io_uringto setup a bio cache, and pass that in throughiocb->ki_bi_cache. With that, we can recycle them instead of going through free+alloc continually. If you look at profiles for high iops, we're spending more time than desired doing just that.https://git.kernel.dk/cgit/linux-block/log/?h=io_uring-bio-cache
So where do you spend the cycles? The do not memset the whole bio optimization is pretty obvious and is someting we should do independent of the allocator.
The other thing that sucks is the mempool implementation, as it forces each allocation and free to do an indirect call. I think it might be worth to try to frontend it with a normal slab cache and only fall back to the mempool if that fails.
Jens Axboe
maintainerQuoted 7 lines · Christoph Hellwig
Quoted 6 lines · Jens Axboe
Here's the series. It's not super clean (yet), but basically allows users like
io_uringto setup a bio cache, and pass that in throughiocb->ki_bi_cache. With that, we can recycle them instead of going through free+alloc continually. If you look at profiles for high iops, we're spending more time than desired doing just that.
Quoted 5 lines
So where do you spend the cycles? The do not memset the whole bio optimization is pretty obvious and is someting we should do independent of the allocator.
memset is just a small optimization on top. If we look at current profiles, the alloc+free looks something ala:
+ 2.71% io_uring [kernel.vmlinux] [k] bio_alloc_bioset + 2.03% io_uring [kernel.vmlinux] [k] kmem_cache_alloc
and
+ 2.82% io_uring [kernel.vmlinux] [k] __slab_free
+ 1.73% io_uring [kernel.vmlinux] [k] kmem_cache_free
0.36% io_uring [kernel.vmlinux] [k] mempool_free_slab
0.27% io_uring [kernel.vmlinux] [k] mempool_freeWhich is a substantial amount of cycles that is needed just to repeatedly use the same set of bios for doing IO. Using the caching patchset, all of the above are completely eliminated, and the only thing we dynamically allocate is a request which is a lot cheaper (ends up being 1-2% for either kernel).
Quoted 4 lines
The other thing that sucks is the mempool implementation, as it forces each allocation and free to do an indirect call. I think it might be worth to try to frontend it with a normal slab cache and only fall back to the mempool if that fails.
Also minor I believe, but yes it'll eat cycles too. FWIW, the testing above is done without RETPOLINE.
Signature · 1 line
Jens Axboe
Christoph Hellwig
maintainerCan you test the force pushed update? This now avoids the RCU free for each bio and just uses SLAB_TYPESAFE_BY_RCU instead.
Jens Axboe
maintainerQuoted 2 lines · Christoph Hellwig
Can you test the force pushed update? This now avoids the RCU free for each bio and just uses
SLAB_TYPESAFE_BY_RCUinstead.
That looks better, perf is now back where it is without the series. At least according to usual variation within boots.
Signature · 1 line
Jens Axboe