Three blk_mq_submit_bio() patches
Subsystems (2)
v2 cover Three blk_mq_submit_bio() patches
Hi Jens,
This patch series includes:
- One patch with a micro-optimization for blk_mq_submit_bio().
- Two patches that improve blk_mq_submit_bio() readability by moving error handling code into blk_mq_submit_bio().
Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v1 of this patch series:
- Addressed Christoph's comments on patch 2/3.
- Added patch 3/3 to this series.
Bart Van Assche (3):
block: Optimize blk_mq_submit_bio() for the cache hit scenario
blk-mq: Move more error handling into blk_mq_submit_bio()
blk-zoned: Move more error handling into blk_mq_submit_bio()
block/blk-mq.c | 36 +++++++++++++++-------- block/blk-zoned.c | 67 +++++++++++++++++++----------------------- include/linux/blkdev.h | 13 ++++++-- 3 files changed, 66 insertions(+), 50 deletions(-)
PATCH v2 1/3 block: Optimize blk_mq_submit_bio() for the cache hit scenario
Help the CPU branch predictor in case of a cache hit by handling the cache hit scenario first.
--- block/blk-mq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-mq.c +3 -3
@@ -3102,12 +3102,12 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; new_request: -if (!rq) { +if (rq) { +blk_mq_use_cached_rq (rq, plug, bio); + }else { rq =blk_mq_get_new_requests (q, plug, bio, nr_segs);if (unlikely (!rq)) goto queue_exit; - }else { -blk_mq_use_cached_rq (rq, plug, bio); }trace_block_getrq (bio);
Re: [PATCH v2 1/3] block: Optimize blk_mq_submit_bio() for the cache hit scenario
Quoted 6 lines · Bart Van Assche
Help the CPU branch predictor in case of a cache hit by handling the cache hit scenario first.
Cc Damien Le Moal <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Looks OK to me.
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH v2 2/3 blk-mq: Move more error handling into blk_mq_submit_bio()
In reply to Bart Van AsscheThe error handling code in blk_mq_get_new_requests() cannot be understood without knowing that this function is only called by blk_mq_submit_bio(). Hence move the code for handling blk_mq_get_new_requests() failures into blk_mq_submit_bio().
--- block/blk-mq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
block/blk-mq.c +7 -7
@@ -2968,12 +2968,9 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, } rq =__blk_mq_alloc_requests (&data); -if (rq) -return rq; -rq_qos_cleanup (q, bio); -if (bio->bi_opf &REQ_NOWAIT ) -bio_wouldblock_error (bio); -return NULL ; +if (!rq) +rq_qos_cleanup (q, bio); +return rq; }/*
@@ -3106,8 +3103,11 @@ void blk_mq_submit_bio(struct bio *bio)blk_mq_use_cached_rq (rq, plug, bio); }else { rq =blk_mq_get_new_requests (q, plug, bio, nr_segs); -if (unlikely (!rq)) +if (unlikely (!rq)) { +if (bio->bi_opf &REQ_NOWAIT ) +bio_wouldblock_error (bio); goto queue_exit; + } }trace_block_getrq (bio);
Damien Le Moal
maintainerRe: [PATCH v2 2/3] blk-mq: Move more error handling into blk_mq_submit_bio()
Quoted 17 lines · Bart Van Assche
The error handling code in
blk_mq_get_new_requests()cannot be understood without knowing that this function is only called byblk_mq_submit_bio(). Hence move the code for handlingblk_mq_get_new_requests()failures intoblk_mq_submit_bio().Cc Damien Le Moal <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- block/blk-mq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)block/blk-mq.c +0
-0
block/blk-mq.c static struct request *blk_mq_get_new_requests(struct request_queue *q, · line 2971
Quoted 10 lines
block/blk-mq.c +1
-6@@ -2968,12 +2968,9 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, } rq =__blk_mq_alloc_requests (&data); -if (rq) -return rq; -rq_qos_cleanup (q, bio); -if (bio->bi_opf &REQ_NOWAIT ) -bio_wouldblock_error (bio); -return NULL ; +if (!rq)
No unlikely() here ?
Quoted 18 lines
block/blk-mq.c +6
-1+rq_qos_cleanup (q, bio); +return rq; }/* @@ -3106,8 +3103,11 @@ void blk_mq_submit_bio(struct bio *bio)blk_mq_use_cached_rq (rq, plug, bio); }else { rq =blk_mq_get_new_requests (q, plug, bio, nr_segs); -if (unlikely (!rq)) +if (unlikely (!rq)) { +if (bio->bi_opf &REQ_NOWAIT ) +bio_wouldblock_error (bio); goto queue_exit; + } }trace_block_getrq (bio);
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 2/3] blk-mq: Move more error handling into blk_mq_submit_bio()
Quoted 8 lines · Damien Le Moal
Quoted 7 lines · Bart Van Assche
block/blk-mq.c +0
-0@@ -2968,12 +2968,9 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, }
Quoted 10 lines
block/blk-mq.c static struct request *blk_mq_get_new_requests(struct request_queue *q, · line 2971
Quoted 8 lines
block/blk-mq.c +1
-6rq =__blk_mq_alloc_requests (&data); -if (rq) -return rq; -rq_qos_cleanup (q, bio); -if (bio->bi_opf &REQ_NOWAIT ) -bio_wouldblock_error (bio); -return NULL ; +if (!rq)No
unlikely()here ?
I will add unlikely here().
Thanks,
Bart.
PATCH v2 3/3 blk-zoned: Move more error handling into blk_mq_submit_bio()
In reply to Bart Van AsscheThe error handling code in blk_zone_plug_bio() and in the functions called by blk_zone_plug_bio() cannot be understood without knowing that these functions are only called by blk_mq_submit_bio(). Move the error handling code in blk_mq_submit_bio() such that all error handling code for blk_mq_submit_bio() occurs inside blk_mq_submit_bio() itself.
--- block/blk-mq.c | 16 ++++++++-- block/blk-zoned.c | 67 +++++++++++++++++++----------------------- include/linux/blkdev.h | 13 ++++++-- 3 files changed, 56 insertions(+), 40 deletions(-)
block/blk-mq.c +14 -2
@@ -3095,8 +3095,20 @@ void blk_mq_submit_bio(struct bio *bio)if (blk_mq_attempt_bio_merge (q, bio, nr_segs)) goto queue_exit; -if (blk_queue_is_zoned (q) &&blk_zone_plug_bio (bio, nr_segs)) - goto queue_exit; +if (blk_queue_is_zoned (q)) { +switch (blk_zone_plug_bio (bio, nr_segs)) { +case bzp_not_plugged: +break ; +case bzp_plugged: + goto queue_exit; +case bzp_wouldblock: +bio_wouldblock_error (bio); + goto queue_exit; +case bzp_failed: +bio_io_error (bio); + goto queue_exit; + } + } new_request:if (rq) {
block/blk-zoned.c +31 -36
171 lines not on this page · raw message
include/linux/blkdev.h +11 -2
@@ -690,18 +690,27 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) (q->limits.features &BLK_FEAT_ZONED ); } +enum blk_zone_plug_status { + bzp_not_plugged, + bzp_plugged, + bzp_wouldblock, + bzp_failed, +}; +#ifdef CONFIG_BLK_DEV_ZONED static inline unsigned int disk_nr_zones (struct gendisk *disk) {return disk->nr_zones; } -bool blk_zone_plug_bio (struct bio *bio,unsigned int nr_segs); +enum blk_zone_plug_status blk_zone_plug_bio (struct bio *bio, +unsigned int nr_segs);#else /* CONFIG_BLK_DEV_ZONED */ static inline unsigned int disk_nr_zones (struct gendisk *disk) {return 0 ; } -static inline bool blk_zone_plug_bio (struct bio *bio,unsigned int nr_segs) +static inline enum blk_zone_plug_status blk_zone_plug_bio (struct bio *bio, +unsigned int nr_segs) {return false; }
Damien Le Moal
maintainerRe: [PATCH v2 3/3] blk-zoned: Move more error handling into blk_mq_submit_bio()
Quoted 6 lines · Bart Van Assche
The error handling code in
blk_zone_plug_bio()and in the functions called byblk_zone_plug_bio()cannot be understood without knowing that these functions are only called byblk_mq_submit_bio(). Move the error handling code inblk_mq_submit_bio()such that all error handling code forblk_mq_submit_bio()occurs insideblk_mq_submit_bio()itself.
I am not a big fan of this. Furthermore, blk_zone_plug_bio() is also called from drivers/md/dm.c, which would need to have the same amount of additional code. Not nice.
Quoted 259 lines
Cc Damien Le Moal <[email protected]>Cc Christoph Hellwig <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- block/blk-mq.c | 16 ++++++++-- block/blk-zoned.c | 67 +++++++++++++++++++----------------------- include/linux/blkdev.h | 13 ++++++-- 3 files changed, 56 insertions(+), 40 deletions(-)block/blk-mq.c +14
-2@@ -3095,8 +3095,20 @@ void blk_mq_submit_bio(struct bio *bio)if (blk_mq_attempt_bio_merge (q, bio, nr_segs)) goto queue_exit; -if (blk_queue_is_zoned (q) &&blk_zone_plug_bio (bio, nr_segs)) - goto queue_exit; +if (blk_queue_is_zoned (q)) { +switch (blk_zone_plug_bio (bio, nr_segs)) { +case bzp_not_plugged: +break ; +case bzp_plugged: + goto queue_exit; +case bzp_wouldblock: +bio_wouldblock_error (bio); + goto queue_exit; +case bzp_failed: +bio_io_error (bio); + goto queue_exit; + } + } new_request:if (rq) {block/blk-zoned.c +31
-36@@ -675,8 +675,8 @@ static int disk_zone_sync_wp_offset(struct gendisk *disk, sector_t sector) disk_report_zones_cb, &args); } -static bool blk_zone_wplug_handle_reset_or_finish (struct bio *bio, -unsigned int wp_offset) +static enum blk_zone_plug_status +blk_zone_wplug_handle_reset_or_finish (struct bio *bio,unsigned int wp_offset) {struct gendisk *disk = bio->bi_bdev->bd_disk;sector_t sector = bio->bi_iter.bi_sector;@@ -684,10 +684,8 @@ static bool blk_zone_wplug_handle_reset_or_finish(struct bio *bio,unsigned long flags;/* Conventional zones cannot be reset nor finished. */ -if (!bdev_zone_is_seq (bio->bi_bdev, sector)) { -bio_io_error (bio); -return true; - } +if (!bdev_zone_is_seq (bio->bi_bdev, sector)) +return bzp_failed;/* * No-wait reset or finish BIOs do not make much sense as the callers @@ -713,10 +711,11 @@ static bool blk_zone_wplug_handle_reset_or_finish(struct bio *bio,disk_put_zone_wplug (zwplug); } -return false; +return bzp_not_plugged; } -static bool blk_zone_wplug_handle_reset_all (struct bio *bio) +static enum blk_zone_plug_status +blk_zone_wplug_handle_reset_all (struct bio *bio) {struct gendisk *disk = bio->bi_bdev->bd_disk;struct blk_zone_wplug *zwplug;@@ -739,7 +738,7 @@ static bool blk_zone_wplug_handle_reset_all(struct bio *bio) } } -return false; +return bzp_not_plugged; } static void disk_zone_wplug_schedule_bio_work(struct gendisk *disk,@@ -964,7 +963,8 @@ static bool blk_zone_wplug_prepare_bio(struct blk_zone_wplug *zwplug,return true; } -static bool blk_zone_wplug_handle_write (struct bio *bio,unsigned int nr_segs) +static enum blk_zone_plug_status +blk_zone_wplug_handle_write (struct bio *bio,unsigned int nr_segs) {struct gendisk *disk = bio->bi_bdev->bd_disk;sector_t sector = bio->bi_iter.bi_sector;@@ -980,19 +980,15 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)* BIO-based devices, it is the responsibility of the driver to split * the bio before submitting it. */ -if (WARN_ON_ONCE (bio_straddles_zones (bio))) { -bio_io_error (bio); -return true; - } +if (WARN_ON_ONCE (bio_straddles_zones (bio))) +return bzp_failed;/* Conventional zones do not need write plugging. */ if (!bdev_zone_is_seq (bio->bi_bdev, sector)) {/* Zone append to conventional zones is not allowed. */ -if (bio_op (bio) ==REQ_OP_ZONE_APPEND ) { -bio_io_error (bio); -return true; - } -return false; +if (bio_op (bio) ==REQ_OP_ZONE_APPEND ) +return bzp_failed; +return bzp_not_plugged; }if (bio->bi_opf &REQ_NOWAIT )@@ -1001,10 +997,9 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs) zwplug =disk_get_and_lock_zone_wplug (disk, sector, gfp_mask, &flags);if (!zwplug) {if (bio->bi_opf &REQ_NOWAIT ) -bio_wouldblock_error (bio); +return bzp_wouldblock;else -bio_io_error (bio); -return true; +return bzp_failed; }/* Indicate that this BIO is being handled using zone write plugging. */ @@ -1022,22 +1017,21 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)if (!blk_zone_wplug_prepare_bio (zwplug, bio)) {spin_unlock_irqrestore (&zwplug->lock, flags); -bio_io_error (bio); -return true; +return bzp_failed; } zwplug->flags |=BLK_ZONE_WPLUG_PLUGGED ;spin_unlock_irqrestore (&zwplug->lock, flags); -return false; +return bzp_not_plugged; plug:disk_zone_wplug_add_bio (disk, zwplug, bio, nr_segs);spin_unlock_irqrestore (&zwplug->lock, flags); -return true; +return bzp_plugged; }/** @@ -1048,16 +1042,17 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)* Handle write, write zeroes and zone append operations requiring emulation * using zone write plugging. * -* Return true whenever @bio execution needs to be delayed through the zone -* write plug. Otherwise, return false to let the submission path process -* @bio normally. +* Return %bzp_plugged if the @bio has been scheduled for delayed execution by +* adding it to zwplug->bio_list; %bzp_failed if the caller should fail @bio or +* %bzp_not_plugged to let the submission path process @bio normally. */ -bool blk_zone_plug_bio (struct bio *bio,unsigned int nr_segs) +enum blk_zone_plug_status blk_zone_plug_bio (struct bio *bio, +unsigned int nr_segs) {struct block_device *bdev = bio->bi_bdev;if (!bdev->bd_disk->zone_wplugs_hash) -return false; +return bzp_not_plugged;/* * If the BIO already has the plugging flag set, then it was already @@ -1065,7 +1060,7 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)* plug bio submit work. */ if (bio_flagged (bio,BIO_ZONE_WRITE_PLUGGING )) -return false; +return bzp_not_plugged;/* * We do not need to do anything special for empty flush BIOs, e.g @@ -1075,7 +1070,7 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)* the written data. */ if (op_is_flush (bio->bi_opf) && !bio_sectors (bio)) -return false; +return bzp_not_plugged;/* * Regular writes and write zeroes need to be handled through the target @@ -1097,7 +1092,7 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)switch (bio_op (bio)) {case REQ_OP_ZONE_APPEND :if (!bdev_emulates_zone_append (bdev)) -return false; +return bzp_not_plugged; fallthrough;case REQ_OP_WRITE :case REQ_OP_WRITE_ZEROES :@@ -1110,10 +1105,10 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)case REQ_OP_ZONE_RESET_ALL :return blk_zone_wplug_handle_reset_all (bio);default : -return false; +return bzp_not_plugged; } -return false; +return bzp_not_plugged; }EXPORT_SYMBOL_GPL (blk_zone_plug_bio);include/linux/blkdev.h +11
-2@@ -690,18 +690,27 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) (q->limits.features &BLK_FEAT_ZONED ); } +enum blk_zone_plug_status { + bzp_not_plugged, + bzp_plugged, + bzp_wouldblock, + bzp_failed, +}; +#ifdef CONFIG_BLK_DEV_ZONED static inline unsigned int disk_nr_zones (struct gendisk *disk) {return disk->nr_zones; } -bool blk_zone_plug_bio (struct bio *bio,unsigned int nr_segs); +enum blk_zone_plug_status blk_zone_plug_bio (struct bio *bio, +unsigned int nr_segs);#else /* CONFIG_BLK_DEV_ZONED */ static inline unsigned int disk_nr_zones (struct gendisk *disk) {return 0 ; } -static inline bool blk_zone_plug_bio (struct bio *bio,unsigned int nr_segs) +static inline enum blk_zone_plug_status blk_zone_plug_bio (struct bio *bio, +unsigned int nr_segs) {return false; }
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 3/3] blk-zoned: Move more error handling into blk_mq_submit_bio()
Quoted 11 lines · Damien Le Moal
Quoted 6 lines · Bart Van Assche
The error handling code in
blk_zone_plug_bio()and in the functions called byblk_zone_plug_bio()cannot be understood without knowing that these functions are only called byblk_mq_submit_bio(). Move the error handling code inblk_mq_submit_bio()such that all error handling code forblk_mq_submit_bio()occurs insideblk_mq_submit_bio()itself.I am not a big fan of this. Furthermore,
blk_zone_plug_bio()is also called fromdrivers/md/dm.c, which would need to have the same amount of additional code. Not nice.
I will drop this patch.
Thanks,
Bart.