avoid the ->make_request_fn indirect for blk-mq drivers
Subsystems (3)
Hi Jens,
this small series avoids an indirect call for every submitted bio that eventually ends up being handled by blk-mq drivers. Let me know what you think.
PATCH 1/3 bcache: remove a duplicate ->make_request_fn assignment
The make_request_fn pointer should only be assigned by blk_alloc_queue. Fix a left over manual initialization.
--- drivers/md/bcache/request.c | 1 - 1 file changed, 1 deletion(-)
drivers/md/bcache/request.c +0 -1
@@ -1372,7 +1372,6 @@ void bch_flash_dev_request_init(struct bcache_device *d) {struct gendisk *g = d->disk; - g->queue->make_request_fn = flash_dev_make_request; g->queue->backing_dev_info->congested_fn = flash_dev_congested; d->cache_miss = flash_dev_cache_miss; d->ioctl = flash_dev_ioctl;
Signature · 1 line
2.26.1
Re: [PATCH 1/3] bcache: remove a duplicate ->make_request_fn assignment
Quoted 5 lines · Christoph Hellwig
The
make_request_fnpointer should only be assigned byblk_alloc_queue. Fix a left over manual initialization.Fixes ff27668ce809 ("bcache: pass the make_request methods to blk_queue_make_request")Signed-off-by Christoph Hellwig <[email protected]>
It looks good to me.
Thanks.
Coly Li
Quoted 17 lines
--- drivers/md/bcache/request.c | 1 - 1 file changed, 1 deletion(-)drivers/md/bcache/request.c +0
-1@@ -1372,7 +1372,6 @@ void bch_flash_dev_request_init(struct bcache_device *d) {struct gendisk *g = d->disk; - g->queue->make_request_fn = flash_dev_make_request; g->queue->backing_dev_info->congested_fn = flash_dev_congested; d->cache_miss = flash_dev_cache_miss; d->ioctl = flash_dev_ioctl;
PATCH 2/3 dm: remove the make_request_fn check in device_area_is_invalid
In reply to Christoph Hellwig--- drivers/md/dm-table.c | 17 ----------------- 1 file changed, 17 deletions(-)
drivers/md/dm-table.c +0 -17
@@ -279,7 +279,6 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)static int device_area_is_invalid (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) { -struct request_queue *q;struct queue_limits *limits = data;struct block_device *bdev = dev->bdev; sector_t dev_size =
@@ -288,22 +287,6 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, limits->logical_block_size >>SECTOR_SHIFT ;char b[BDEVNAME_SIZE ]; -/* -* Some devices exist without request functions, -* such as loop devices not yet bound to backing files. -* Forbid the use of such devices. -*/ - q =bdev_get_queue (bdev); -if (!q || !q->make_request_fn) { -DMWARN ("%s: %s is not yet initialised: " -"start=%llu, len=%llu, dev_size=%llu" , -dm_device_name (ti->table->md),bdevname (bdev, b), - (unsigned long long )start, - (unsigned long long )len, - (unsigned long long )dev_size); -return 1 ; - } -if (!dev_size)return 0 ;
Signature · 1 line
2.26.1
Re: [PATCH 2/3] dm: remove the make_request_fn check in device_area_is_invalid
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Think it'd be useful to add a commit message like you did for revert commit f01b411f41f91fc3196eae4317cf8b4d872830a6 , e.g.:
We can't have queues without a make_request_fn any more (and the loop device uses blk-mq these days anyway..).
But that aside:
Thanks.
Quoted 47 lines
--- drivers/md/dm-table.c | 17 ----------------- 1 file changed, 17 deletions(-)drivers/md/dm-table.c +0
-17@@ -279,7 +279,6 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)static int device_area_is_invalid (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) { -struct request_queue *q;struct queue_limits *limits = data;struct block_device *bdev = dev->bdev; sector_t dev_size =@@ -288,22 +287,6 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, limits->logical_block_size >>SECTOR_SHIFT ;char b[BDEVNAME_SIZE ]; -/* -* Some devices exist without request functions, -* such as loop devices not yet bound to backing files. -* Forbid the use of such devices. -*/ - q =bdev_get_queue (bdev); -if (!q || !q->make_request_fn) { -DMWARN ("%s: %s is not yet initialised: " -"start=%llu, len=%llu, dev_size=%llu" , -dm_device_name (ti->table->md),bdevname (bdev, b), - (unsigned long long )start, - (unsigned long long )len, - (unsigned long long )dev_size); -return 1 ; - } -if (!dev_size)return 0 ;Signature · 7 lines
2.26.1 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH 3/3 block: bypass ->make_request_fn for blk-mq drivers
In reply to Christoph HellwigCall blk_mq_make_request when no ->make_request_fn is set. This is safe now that blk_alloc_queue always sets up the pointer for make_request based drivers. This avoids an indirect call in the blk-mq driver I/O fast path, which is rather expensive due to spectre mitigations.
--- block/blk-core.c | 26 +++++++++++++++++--------- block/blk-mq.c | 4 ++-- drivers/md/dm.c | 3 +++ include/linux/blk-mq.h | 2 ++ 4 files changed, 24 insertions(+), 11 deletions(-)
block/blk-core.c +17 -9
@@ -1072,7 +1072,10 @@ blk_qc_t generic_make_request(struct bio *bio)/* Create a fresh bio_list for all subordinate requests */ bio_list_on_stack[1 ] = bio_list_on_stack[0 ];bio_list_init (&bio_list_on_stack[0 ]); - ret = q->make_request_fn (q, bio); +if (q->make_request_fn) + ret = q->make_request_fn (q, bio); +else + ret =blk_mq_make_request (q, bio);blk_queue_exit (q);
@@ -1112,9 +1115,7 @@ EXPORT_SYMBOL(generic_make_request);* * This function behaves like generic_make_request(), but does not protect * against recursion. Must only be used if the called driver is known -* to not call generic_make_request (or direct_make_request) again from -* its make_request function. (Calling direct_make_request again from -* a workqueue is perfectly fine as that doesn't recurse). +* to be blk-mq based. */ blk_qc_t direct_make_request (struct bio *bio) {
@@ -1122,20 +1123,27 @@ blk_qc_t direct_make_request(struct bio *bio)bool nowait = bio->bi_opf &REQ_NOWAIT ;blk_qc_t ret; +if (WARN_ON_ONCE (q->make_request_fn)) + goto io_error;if (!generic_make_request_checks (bio))return BLK_QC_T_NONE ;if (unlikely (blk_queue_enter (q, nowait ?BLK_MQ_REQ_NOWAIT :0 ))) {if (nowait && !blk_queue_dying (q)) -bio_wouldblock_error (bio); -else -bio_io_error (bio); -return BLK_QC_T_NONE ; + goto would_block; + goto io_error; } - ret = q->make_request_fn (q, bio); + ret =blk_mq_make_request (q, bio);blk_queue_exit (q);return ret; + +would_block: +bio_wouldblock_error (bio); +return BLK_QC_T_NONE ; +io_error: +bio_io_error (bio); +return BLK_QC_T_NONE ; }EXPORT_SYMBOL_GPL (direct_make_request);
block/blk-mq.c +2 -2
@@ -1984,7 +1984,7 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)* * Returns: Request queue cookie. */ -static blk_qc_t blk_mq_make_request (struct request_queue *q,struct bio *bio) +blk_qc_t blk_mq_make_request (struct request_queue *q,struct bio *bio) {const int is_sync =op_is_sync (bio->bi_opf);const int is_flush_fua =op_is_flush (bio->bi_opf);
@@ -2096,6 +2096,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)return cookie; } +EXPORT_SYMBOL_GPL (blk_mq_make_request);/* only for request based dm */ void blk_mq_free_rqs (struct blk_mq_tag_set *set,struct blk_mq_tags *tags,unsigned int hctx_idx)
@@ -2955,7 +2956,6 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,INIT_LIST_HEAD (&q->requeue_list);spin_lock_init (&q->requeue_lock); - q->make_request_fn = blk_mq_make_request; q->nr_requests = set->queue_depth;/*
drivers/md/dm.c +3 -0
@@ -1788,6 +1788,9 @@ static blk_qc_t dm_make_request(struct request_queue *q, struct bio *bio)int srcu_idx;struct dm_table *map; +if (dm_get_md_type (md) ==DM_TYPE_REQUEST_BASED ) +return blk_mq_make_request (q, bio); + map =dm_get_live_table (md, &srcu_idx);/* if we're suspended, we have to queue this io for later */
include/linux/blk-mq.h +2 -0
@@ -578,4 +578,6 @@ static inline void blk_mq_cleanup_rq(struct request *rq) rq->q->mq_ops->cleanup_rq(rq); } +blk_qc_t blk_mq_make_request (struct request_queue *q,struct bio *bio); +#endif
Signature · 1 line
2.26.1
Re: [PATCH 3/3] block: bypass ->make_request_fn for blk-mq drivers
Quoted 6 lines · Christoph Hellwig
Call
blk_mq_make_requestwhen no ->make_request_fn is set. This is safe now thatblk_alloc_queuealways sets up the pointer formake_requestbased drivers. This avoids an indirect call in the blk-mq driver I/O fast path, which is rather expensive due to spectre mitigations.Signed-off-by Christoph Hellwig <[email protected]>
Makes me cringe thinking about all the indirect calls sprinkled throughout DM...
Jens Axboe
maintainerQuoted 5 lines · Christoph Hellwig
Hi Jens,
this small series avoids an indirect call for every submitted bio that eventually ends up being handled by blk-mq drivers. Let me know what you think.
I like it, I've been pondering something like this for a bit, but I like the simplicity of this one and changing it so that only non-regular make_request_fn is set.
I'll apply this.
Signature · 1 line
Jens Axboe