blk-mq: Minor tweaks
cover blk-mq: Minor tweaks
Hi Jens,
These are few changes to blk-mq/blk-mq-tag, nothing really serious.
Alexander Gordeev (3):
blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
blk-mq: Eliminate superfluous check of BLK_MQ_S_TAG_ACTIVE flag
blk-mq: Fix formula to calculate fair share of tags
block/blk-mq-tag.c | 9 +++------ block/blk-mq-tag.h | 17 ++++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/3 blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
--- block/blk-mq-tag.c | 4 +--- block/blk-mq-tag.h | 17 ++++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-)
block/blk-mq-tag.c +1 -3
@@ -58,13 +58,11 @@ static inline void bt_index_atomic_inc(atomic_t *index)/* * If a previously inactive queue goes active, bump the active user count. */ -bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) +void __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {if (!test_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state) && !test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state))atomic_inc (&hctx->tags->active_queues); - -return true; }/*
block/blk-mq-tag.h +8 -9
@@ -66,23 +66,22 @@ enum { BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1, }; -extern bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *); +extern void __blk_mq_tag_busy (struct blk_mq_hw_ctx *);extern void __blk_mq_tag_idle (struct blk_mq_hw_ctx *);static inline bool blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) { -if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return false; - -return __blk_mq_tag_busy (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) { +__blk_mq_tag_busy (hctx); +return true; + } +return false; }static inline void blk_mq_tag_idle (struct blk_mq_hw_ctx *hctx) { -if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return ; - -__blk_mq_tag_idle (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) +__blk_mq_tag_idle (hctx); }#endif
Signature · 1 line
1.9.3
Jens Axboe
maintainerRe: [PATCH 1/3] blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
Quoted 14 lines · Alexander Gordeev
Signed-off-by Alexander Gordeev <[email protected]>Cc Jens Axboe <[email protected]>--- block/blk-mq-tag.c | 4 +--- block/blk-mq-tag.h | 17 ++++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-)block/blk-mq-tag.c +0
-0@@ -58,13 +58,11 @@ static inline void bt_index_atomic_inc(atomic_t *index)/* * If a previously inactive queue goes active, bump the active user count.
block/blk-mq-tag.c static inline void bt_index_atomic_inc(atomic_t *index) · line 66
Quoted 10 lines
block/blk-mq-tag.c +1
-3*/ -bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) +void __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {if (!test_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state) && !test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state))atomic_inc (&hctx->tags->active_queues); - -return true; }
This is obviously a good idea.
Quoted 14 lines
block/blk-mq-tag.h +1
-1@@ -66,23 +66,22 @@ enum { BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1, }; -extern bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *); +extern void __blk_mq_tag_busy (struct blk_mq_hw_ctx *);extern void __blk_mq_tag_idle (struct blk_mq_hw_ctx *);static inline bool blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {
block/blk-mq-tag.h enum { · line 79
Quoted 10 lines
block/blk-mq-tag.h +5
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return false; - -return __blk_mq_tag_busy (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) { +__blk_mq_tag_busy (hctx); +return true; + } +return false; }
The normal/fast path here is the flag NOT being set, which is why it was coded that way to put the fast path inline.
block/blk-mq-tag.h enum { · line 85
Quoted 10 lines
block/blk-mq-tag.h +2
-4static inline void blk_mq_tag_idle (struct blk_mq_hw_ctx *hctx) { -if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return ; - -__blk_mq_tag_idle (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) +__blk_mq_tag_idle (hctx); }
Ditto
Signature · 1 line
Jens Axboe
Re: [PATCH 1/3] blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
Quoted 1 line · On Wed, 03 Sep 2014 14:35:29 -0600 Jens Axboe <[email protected]> wrote:
On 09/03/2014 02:33 PM, Alexander Gordeev wrote:
<snip>
Quoted 29 lines
Quoted 14 lines
block/blk-mq-tag.h +1
-1@@ -66,23 +66,22 @@ enum { BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1, }; -extern bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *); +extern void __blk_mq_tag_busy (struct blk_mq_hw_ctx *);extern void __blk_mq_tag_idle (struct blk_mq_hw_ctx *);static inline bool blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {block/blk-mq-tag.h enum { · line 79
Quoted 10 lines
block/blk-mq-tag.h +5
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return false; - -return __blk_mq_tag_busy (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) { +__blk_mq_tag_busy (hctx); +return true; + } +return false; }The normal/fast path here is the flag NOT being set, which is why it was coded that way to put the fast path inline.
Quoted 1 line
Quoted 11 lines
block/blk-mq-tag.h enum { · line 85
Quoted 9 lines
static inline void
blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx){block/blk-mq-tag.h +2
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return ; - -__blk_mq_tag_idle (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) +__blk_mq_tag_idle (hctx); }Ditto
Shouldn't it just add unlikely() then? That way it's obvious what the common case is, instead of relying on convoluted code.
Jens Axboe
maintainerRe: [PATCH 1/3] blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
Quoted 46 lines · Chuck Ebbert
Quoted 1 line · On Wed, 03 Sep 2014 14:35:29 -0600 Jens Axboe <[email protected]> wrote:
On 09/03/2014 02:33 PM, Alexander Gordeev wrote:
<snip>
Quoted 29 lines
Quoted 14 lines
block/blk-mq-tag.h +1
-1@@ -66,23 +66,22 @@ enum { BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1, }; -extern bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *); +extern void __blk_mq_tag_busy (struct blk_mq_hw_ctx *);extern void __blk_mq_tag_idle (struct blk_mq_hw_ctx *);static inline bool blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {block/blk-mq-tag.h enum { · line 79
Quoted 10 lines
block/blk-mq-tag.h +5
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return false; - -return __blk_mq_tag_busy (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) { +__blk_mq_tag_busy (hctx); +return true; + } +return false; }The normal/fast path here is the flag NOT being set, which is why it was coded that way to put the fast path inline.
Quoted 1 line
Quoted 11 lines
block/blk-mq-tag.h enum { · line 85
Quoted 9 lines
static inline void
blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx){block/blk-mq-tag.h +2
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return ; - -__blk_mq_tag_idle (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) +__blk_mq_tag_idle (hctx); }Ditto
Quoted 2 lines
Shouldn't it just add
unlikely()then? That way it's obvious what the common case is, instead of relying on convoluted code.
It's a common construct. Besides, if you find a flag-not-set check convoluted, then I hope you are not programming anything I use. That's a bit of a straw man, imho.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/3] blk-mq: Cleanup blk_mq_tag_busy() and blk_mq_tag_idle()
Quoted 47 lines · On Thu, 04 Sep 2014 19:30:18 -0600 Jens Axboe <[email protected]> wrote:
Quoted 46 lines · Chuck Ebbert
Quoted 1 line · On Wed, 03 Sep 2014 14:35:29 -0600 Jens Axboe <[email protected]> wrote:
On 09/03/2014 02:33 PM, Alexander Gordeev wrote:
<snip>
Quoted 40 lines
Quoted 14 lines
block/blk-mq-tag.h +1
-1@@ -66,23 +66,22 @@ enum { BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1, }; -extern bool __blk_mq_tag_busy (struct blk_mq_hw_ctx *); +extern void __blk_mq_tag_busy (struct blk_mq_hw_ctx *);extern void __blk_mq_tag_idle (struct blk_mq_hw_ctx *);static inline bool blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) {block/blk-mq-tag.h enum { · line 79
Quoted 10 lines
block/blk-mq-tag.h +5
-4-if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return false; - -return __blk_mq_tag_busy (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) { +__blk_mq_tag_busy (hctx); +return true; + } +return false; }The normal/fast path here is the flag NOT being set, which is why it was coded that way to put the fast path inline.
block/blk-mq-tag.h enum { · line 85
Quoted 10 lines
block/blk-mq-tag.h +2
-4static inline void blk_mq_tag_idle (struct blk_mq_hw_ctx *hctx) { -if (!(hctx->flags &BLK_MQ_F_TAG_SHARED )) -return ; - -__blk_mq_tag_idle (hctx); +if (hctx->flags &BLK_MQ_F_TAG_SHARED ) +__blk_mq_tag_idle (hctx); }Ditto
Quoted 7 lines
Quoted 2 lines
Shouldn't it just add
unlikely()then? That way it's obvious what the common case is, instead of relying on convoluted code.It's a common construct. Besides, if you find a flag-not-set check convoluted, then I hope you are not programming anything I use. That's a bit of a straw man, imho.
Sure, it's a common construct. But there's nothing there to prevent the optimizer from rearranging things any way it pleases. Nor is there anything keeping a human from doing the same. ;)
PATCH 2/3 blk-mq: Eliminate superfluous check of BLK_MQ_S_TAG_ACTIVE flag
In reply to Alexander Gordeev--- block/blk-mq-tag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq-tag.c +1 -2
@@ -60,8 +60,7 @@ static inline void bt_index_atomic_inc(atomic_t *index)*/ void __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) { -if (!test_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state) && - !test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state)) +if (!test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state))atomic_inc (&hctx->tags->active_queues); }
Signature · 1 line
1.9.3
Jens Axboe
maintainerRe: [PATCH 2/3] blk-mq: Eliminate superfluous check of BLK_MQ_S_TAG_ACTIVE flag
Quoted 11 lines · Alexander Gordeev
Signed-off-by Alexander Gordeev <[email protected]>Cc Jens Axboe <[email protected]>--- block/blk-mq-tag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/blk-mq-tag.c +0
-0
block/blk-mq-tag.c static inline void bt_index_atomic_inc(atomic_t *index) · line 64
Quoted 7 lines
block/blk-mq-tag.c +1
-2@@ -60,8 +60,7 @@ static inline void bt_index_atomic_inc(atomic_t *index)*/ void __blk_mq_tag_busy (struct blk_mq_hw_ctx *hctx) { -if (!test_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state) && - !test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state)) +if (!test_and_set_bit (BLK_MQ_S_TAG_ACTIVE , &hctx->state))atomic_inc (&hctx->tags->active_queues);
That's done on purpose as well, it's a lot faster to do the (non-atomic) check first and only do the expensive test and set if needed.
See 7fcbbaf18392 for similar construct and actual numbers on a real case.
Signature · 1 line
Jens Axboe
PATCH 3/3 blk-mq: Fix formula to calculate fair share of tags
In reply to Alexander GordeevFair share of tags is number of tags diveded on number of users. Not sure why it is different.
--- block/blk-mq-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq-tag.c +1 -1
@@ -127,7 +127,7 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,/* * Allow at least some tags */ - depth =max ((bt->depth + users -1 ) / users,4U ); + depth =max (bt->depth / users,4U );return atomic_read (&hctx->nr_active) < depth; }
Signature · 1 line
1.9.3
Jens Axboe
maintainerRe: [PATCH 3/3] blk-mq: Fix formula to calculate fair share of tags
Quoted 14 lines · Alexander Gordeev
Fair share of tags is number of tags diveded on number of users. Not sure why it is different.
Signed-off-by Alexander Gordeev <[email protected]>Cc Jens Axboe <[email protected]>--- block/blk-mq-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-mq-tag.c +0
-0
block/blk-mq-tag.c static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx, · line 131
Quoted 6 lines
block/blk-mq-tag.c +1
-1@@ -127,7 +127,7 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,/* * Allow at least some tags */ - depth =max ((bt->depth + users -1 ) / users,4U ); + depth =max (bt->depth / users,4U );return atomic_read (&hctx->nr_active) < depth;
It's normal rounding, you'll round down otherwise. Say you have a tag depth of 31 (SATA), and 4 active users. Your change would make that 7 tags per user, leaving 3 idle. If you round up, you end up with 8 tags instead. That will potentially just leave some sleeping for a new tag, but at least you'll exhaust the space.
Signature · 1 line
Jens Axboe