* [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*()
@ 2019-09-30 8:27 Pavel Begunkov (Silence)
2019-09-30 8:33 ` Christoph Hellwig
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
0 siblings, 2 replies; 7+ messages in thread
From: Pavel Begunkov (Silence) @ 2019-09-30 8:27 UTC (permalink / raw)
To: Jens Axboe, linux-block, linux-kernel; +Cc: Pavel Begunkov
From: Pavel Begunkov <asml.silence@gmail.com>
1. Reuse the same walker callback for both blk_mq_in_flight() and
blk_mq_in_flight_rw().
2. Store inflight counters immediately in struct mq_inflight.
It's type-safer and removes extra indirection.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
block/blk-mq.c | 32 ++++++++------------------------
1 file changed, 8 insertions(+), 24 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index c4e5070c2ecd..d97181d9a3ec 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -93,7 +93,7 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx,
struct mq_inflight {
struct hd_struct *part;
- unsigned int *inflight;
+ unsigned int inflight[2];
};
static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
@@ -102,45 +102,29 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
{
struct mq_inflight *mi = priv;
- /*
- * index[0] counts the specific partition that was asked for.
- */
if (rq->part == mi->part)
- mi->inflight[0]++;
+ mi->inflight[rq_data_dir(rq)]++;
return true;
}
unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)
{
- unsigned inflight[2];
- struct mq_inflight mi = { .part = part, .inflight = inflight, };
+ struct mq_inflight mi = { .part = part };
- inflight[0] = inflight[1] = 0;
blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
- return inflight[0];
-}
-
-static bool blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx,
- struct request *rq, void *priv,
- bool reserved)
-{
- struct mq_inflight *mi = priv;
-
- if (rq->part == mi->part)
- mi->inflight[rq_data_dir(rq)]++;
-
- return true;
+ return mi.inflight[0] + mi.inflight[1];
}
void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2])
{
- struct mq_inflight mi = { .part = part, .inflight = inflight, };
+ struct mq_inflight mi = { .part = part };
- inflight[0] = inflight[1] = 0;
- blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight_rw, &mi);
+ blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
+ inflight[0] = mi.inflight[0];
+ inflight[1] = mi.inflight[1];
}
void blk_freeze_queue_start(struct request_queue *q)
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*()
2019-09-30 8:27 [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*() Pavel Begunkov (Silence)
@ 2019-09-30 8:33 ` Christoph Hellwig
2019-09-30 9:20 ` Pavel Begunkov
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
1 sibling, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2019-09-30 8:33 UTC (permalink / raw)
To: Pavel Begunkov (Silence); +Cc: Jens Axboe, linux-block, linux-kernel
On Mon, Sep 30, 2019 at 11:27:32AM +0300, Pavel Begunkov (Silence) wrote:
> From: Pavel Begunkov <asml.silence@gmail.com>
>
> 1. Reuse the same walker callback for both blk_mq_in_flight() and
> blk_mq_in_flight_rw().
>
> 2. Store inflight counters immediately in struct mq_inflight.
> It's type-safer and removes extra indirection.
You really want to split this into two patches. Part 2 looks very
sensible to me, but I don't really see how 1 is qn equivalent
transformation right now. Splitting it out and writing a non-trivial
changelog might help understanding it if you think it really is
equivalent as-is.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*()
2019-09-30 8:33 ` Christoph Hellwig
@ 2019-09-30 9:20 ` Pavel Begunkov
0 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov @ 2019-09-30 9:20 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Jens Axboe, linux-block, linux-kernel
On 9/30/2019 11:33 AM, Christoph Hellwig wrote:
> On Mon, Sep 30, 2019 at 11:27:32AM +0300, Pavel Begunkov (Silence) wrote:
>> From: Pavel Begunkov <asml.silence@gmail.com>
>>
>> 1. Reuse the same walker callback for both blk_mq_in_flight() and
>> blk_mq_in_flight_rw().
>>
>> 2. Store inflight counters immediately in struct mq_inflight.
>> It's type-safer and removes extra indirection.
>
> You really want to split this into two patches. Part 2 looks very
Good point, diff is peculiarly aligned indeed. I will resend it.
> sensible to me, but I don't really see how 1 is qn equivalent
> transformation right now. Splitting it out and writing a non-trivial
> changelog might help understanding it if you think it really is
> equivalent as-is.
>
blk_mq_check_inflight() increments only inflight[0].
blk_mq_check_inflight_rw() increments inflight[0] or inflight[1]
depending on a flag, so summing them gives what the first function returns.
--
Yours sincerely,
Pavel Begunkov
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 0/2] Simplify blk_mq_in_flight*
2019-09-30 8:27 [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*() Pavel Begunkov (Silence)
2019-09-30 8:33 ` Christoph Hellwig
@ 2019-09-30 18:55 ` Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 1/2] blk-mq: Reuse callback in blk_mq_in_flight*() Pavel Begunkov (Silence)
` (2 more replies)
1 sibling, 3 replies; 7+ messages in thread
From: Pavel Begunkov (Silence) @ 2019-09-30 18:55 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, linux-block, linux-kernel; +Cc: Pavel Begunkov
From: Pavel Begunkov <asml.silence@gmail.com>
Clean up inflight counting code. Deduplicate it and fortify with types.
v2: splitting the patch in two by Christoph suggestion
Pavel Begunkov (2):
blk-mq: Reuse callback in blk_mq_in_flight*()
blk-mq: Embed counters into struct mq_inflight
block/blk-mq.c | 32 ++++++++------------------------
1 file changed, 8 insertions(+), 24 deletions(-)
--
2.23.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] blk-mq: Reuse callback in blk_mq_in_flight*()
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
@ 2019-09-30 18:55 ` Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 2/2] blk-mq: Embed counters into struct mq_inflight Pavel Begunkov (Silence)
2019-10-02 3:40 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov (Silence) @ 2019-09-30 18:55 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, linux-block, linux-kernel; +Cc: Pavel Begunkov
From: Pavel Begunkov <asml.silence@gmail.com>
Reuse a more generic callback in both blk_mq_in_flight() and
blk_mq_in_flight_rw().
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
block/blk-mq.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index c4e5070c2ecd..3359a0b6c398 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -102,11 +102,8 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
{
struct mq_inflight *mi = priv;
- /*
- * index[0] counts the specific partition that was asked for.
- */
if (rq->part == mi->part)
- mi->inflight[0]++;
+ mi->inflight[rq_data_dir(rq)]++;
return true;
}
@@ -119,19 +116,7 @@ unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)
inflight[0] = inflight[1] = 0;
blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
- return inflight[0];
-}
-
-static bool blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx,
- struct request *rq, void *priv,
- bool reserved)
-{
- struct mq_inflight *mi = priv;
-
- if (rq->part == mi->part)
- mi->inflight[rq_data_dir(rq)]++;
-
- return true;
+ return inflight[0] + inflight[1];
}
void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
@@ -140,7 +125,7 @@ void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
struct mq_inflight mi = { .part = part, .inflight = inflight, };
inflight[0] = inflight[1] = 0;
- blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight_rw, &mi);
+ blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
}
void blk_freeze_queue_start(struct request_queue *q)
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] blk-mq: Embed counters into struct mq_inflight
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 1/2] blk-mq: Reuse callback in blk_mq_in_flight*() Pavel Begunkov (Silence)
@ 2019-09-30 18:55 ` Pavel Begunkov (Silence)
2019-10-02 3:40 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Pavel Begunkov (Silence) @ 2019-09-30 18:55 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, linux-block, linux-kernel; +Cc: Pavel Begunkov
From: Pavel Begunkov <asml.silence@gmail.com>
Store inflight counters immediately in struct mq_inflight.
That's type-safer and removes extra indirection.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
block/blk-mq.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 3359a0b6c398..d97181d9a3ec 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -93,7 +93,7 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx,
struct mq_inflight {
struct hd_struct *part;
- unsigned int *inflight;
+ unsigned int inflight[2];
};
static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
@@ -110,22 +110,21 @@ static bool blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part)
{
- unsigned inflight[2];
- struct mq_inflight mi = { .part = part, .inflight = inflight, };
+ struct mq_inflight mi = { .part = part };
- inflight[0] = inflight[1] = 0;
blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
- return inflight[0] + inflight[1];
+ return mi.inflight[0] + mi.inflight[1];
}
void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
unsigned int inflight[2])
{
- struct mq_inflight mi = { .part = part, .inflight = inflight, };
+ struct mq_inflight mi = { .part = part };
- inflight[0] = inflight[1] = 0;
blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
+ inflight[0] = mi.inflight[0];
+ inflight[1] = mi.inflight[1];
}
void blk_freeze_queue_start(struct request_queue *q)
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] Simplify blk_mq_in_flight*
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 1/2] blk-mq: Reuse callback in blk_mq_in_flight*() Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 2/2] blk-mq: Embed counters into struct mq_inflight Pavel Begunkov (Silence)
@ 2019-10-02 3:40 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2019-10-02 3:40 UTC (permalink / raw)
To: Pavel Begunkov (Silence), Christoph Hellwig, linux-block, linux-kernel
On 9/30/19 12:55 PM, Pavel Begunkov (Silence) wrote:
> From: Pavel Begunkov <asml.silence@gmail.com>
>
> Clean up inflight counting code. Deduplicate it and fortify with types.
>
> v2: splitting the patch in two by Christoph suggestion
Looks good, applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-02 3:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 8:27 [PATCH 1/1] blk-mq: reuse code in blk_mq_check_inflight*() Pavel Begunkov (Silence)
2019-09-30 8:33 ` Christoph Hellwig
2019-09-30 9:20 ` Pavel Begunkov
2019-09-30 18:55 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 1/2] blk-mq: Reuse callback in blk_mq_in_flight*() Pavel Begunkov (Silence)
2019-09-30 18:55 ` [PATCH v2 2/2] blk-mq: Embed counters into struct mq_inflight Pavel Begunkov (Silence)
2019-10-02 3:40 ` [PATCH v2 0/2] Simplify blk_mq_in_flight* Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).