block: tidy up blk_mq_plug
PATCH 1/1 block: tidy up blk_mq_plug
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
block/blk-mq.h +4 -10
@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context
@@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio))) -return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ -return NULL ; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; +return current->plug; }#endif
Signature · 1 line
2.20.1
Looks good, we should avoid "!" conditions when possible it makes code much easier to read.
Quoted 43 lines · Christoph Hellwig
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)block/blk-mq.h +4
-10@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context @@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio))) -return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ -return NULL ; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; +return current->plug; }#endif
Jens Axboe
maintainerQuoted 32 lines · Christoph Hellwig
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)block/blk-mq.h +1
-6@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context @@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio)))
block/blk-mq.h static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) · line 262
Quoted 10 lines
block/blk-mq.h +3
-4-return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ - return NULL; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; + return current->plug; }#endif
I agree it's more readable, but probably also means that the path that we care the least about (zoned+write) is now the inline one.
Signature · 1 line
Jens Axboe
Quoted 42 lines · Jens Axboe
Quoted 41 lines · Christoph Hellwig
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)block/blk-mq.h +4
-10@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context @@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio))) -return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ -return NULL ; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; +return current->plug; }
Quoted 4 lines
block/blk-mq.h static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) · line 262
Quoted 1 line
block/blk-mq.h +0
-0#endif I agree it's more readable, but probably also means that the path that we care the least about (zoned+write) is now the inline one.
What about an additional inline function ?
So something like this is very readable I think and blk_mq_plug() can also be optimized with #ifdef for the !CONFIG_BLK_DEV_ZONED case.
#ifndef CONFIG_BLK_DEV_ZONED
static inline struct blk_plug *blk_mq_plug(struct request_queue *q,
struct bio *bio)
{
return current->plug;
}
#else
static inline struct blk_plug *blk_zoned_get_plug(struct request_queue *q,
struct bio *bio)
{
if (op_is_write(bio_op(bio)))
return NULL;
return current->plug;
}static inline struct blk_plug *blk_mq_plug(struct request_queue *q,
struct bio *bio)
{
if (!blk_queue_is_zoned(q))
return current->plug;
return blk_zoned_get_plug(q, bio);
}#endif
Signature · 2 lines
Damien Le Moal Western Digital Research
Jens Axboe
maintainerQuoted 70 lines · Damien Le Moal
Quoted 42 lines · Jens Axboe
Quoted 41 lines · Christoph Hellwig
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)block/blk-mq.h +4
-10@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context @@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio))) -return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ -return NULL ; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; +return current->plug; }Quoted 4 lines
block/blk-mq.h static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) · line 262
Quoted 1 line
block/blk-mq.h +0
-0#endif I agree it's more readable, but probably also means that the path that we care the least about (zoned+write) is now the inline one.
What about an additional inline function ?
So something like this is very readable I think andblk_mq_plug()can also be optimized with #ifdef for the !CONFIG_BLK_DEV_ZONED case.#ifndef
CONFIG_BLK_DEV_ZONED
static inline structblk_plug*blk_mq_plug(structrequest_queue*q,
struct bio *bio){ return current->plug; } #else static inline struct blk_plug *blk_zoned_get_plug(struct request_queue *q, struct bio *bio) { if (op_is_write(bio_op(bio))) return NULL; return current->plug; }static inline struct
blk_plug*blk_mq_plug(structrequest_queue*q,
struct bio *bio)
Quoted 7 lines
{ if (!blk_queue_is_zoned(q)) return current->plug; return blk_zoned_get_plug(q, bio); }#endif
Let's not go that far into ifdef'ery, please... Besides, that usually solves nothing, as most/all kernels will have zoned support enabled.
I'm actually fine with the existing setup. Yes, the other variant is easier to read, but I bet the existing one inlines better.
Signature · 1 line
Jens Axboe
Quoted 79 lines · Jens Axboe
Quoted 70 lines · Damien Le Moal
Quoted 42 lines · Jens Axboe
Quoted 41 lines · Christoph Hellwig
Make the zoned device write path the special case and just fall though to the defaul case to make the code easier to read. Also update the top of function comment to use the proper kdoc format and remove the extra in-function comments that just duplicate it.
Signed-off-by Christoph Hellwig <[email protected]>--- block/blk-mq.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)block/blk-mq.h +4
-10@@ -233,7 +233,7 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) qmap->mq_map[cpu] =0 ; } -/* +/** * blk_mq_plug() - Get caller context plug * @q: request queue * @bio : the bio being submitted by the caller context @@ -254,15 +254,9 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)static inline struct blk_plug *blk_mq_plug (struct request_queue *q,struct bio *bio) { -/* -* For regular block devices or read operations, use the context plug -* which may be NULL if blk_start_plug() was not executed. -*/ -if (!blk_queue_is_zoned (q) || !op_is_write (bio_op (bio))) -return current->plug; - -/* Zoned block device write operation case: do not plug the BIO */ -return NULL ; +if (blk_queue_is_zoned (q) &&op_is_write (bio_op (bio))) +return NULL ; +return current->plug; }Quoted 4 lines
block/blk-mq.h static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap) · line 262
Quoted 1 line
block/blk-mq.h +0
-0#endif I agree it's more readable, but probably also means that the path that we care the least about (zoned+write) is now the inline one.
What about an additional inline function ?
So something like this is very readable I think andblk_mq_plug()can also be optimized with #ifdef for the !CONFIG_BLK_DEV_ZONED case.#ifndef
CONFIG_BLK_DEV_ZONED
static inline structblk_plug*blk_mq_plug(structrequest_queue*q,
struct bio *bio){ return current->plug; } #else static inline struct blk_plug *blk_zoned_get_plug(struct request_queue *q, struct bio *bio) { if (op_is_write(bio_op(bio))) return NULL; return current->plug; }static inline struct
blk_plug*blk_mq_plug(structrequest_queue*q,
struct bio *bio)Quoted 7 lines
{ if (!blk_queue_is_zoned(q)) return current->plug; return blk_zoned_get_plug(q, bio); }#endif
Quoted 6 lines
Let's not go that far into ifdef'ery, please... Besides, that usually solves nothing, as most/all kernels will have zoned support enabled.
I'm actually fine with the existing setup. Yes, the other variant is easier to read, but I bet the existing one inlines better.
OK. Thanks.
Signature · 2 lines
Damien Le Moal Western Digital Research