blk-mq: don't insert FUA request with data into scheduler queue
PATCH 1/1 blk-mq: don't insert FUA request with data into scheduler queue
We never insert flush request into scheduler queue before.
Recently commit d92ca9d8348f ("blk-mq: don't handle non-flush requests in blk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadline dd_exit_sched() or io hang in case of kyber since RQF_ELVPRIV isn't set for flush request, then ->finish_request won't be called.
Fix the issue by inserting FUA data request with blk_mq_request_bypass_insert() when the device supports FUA, just like what we did before.
--- block/blk-flush.c | 12 ++++++------ block/blk-mq.c | 4 +++- block/blk.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-)
block/blk-flush.c +6 -6
@@ -379,7 +379,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)* @rq is being submitted. Analyze what needs to be done and put it on the * right queue. */ -bool blk_insert_flush (struct request *rq) +void blk_insert_flush (struct request *rq) {struct request_queue *q = rq->q;unsigned long fflags = q->queue_flags;/* may change, cache */
@@ -409,7 +409,7 @@ bool blk_insert_flush(struct request *rq)*/ if (!policy) {blk_mq_end_request (rq,0 ); -return true; +return ; }BUG_ON (rq->bio != rq->biotail);/*assumes zero or single bio rq */
@@ -420,8 +420,10 @@ bool blk_insert_flush(struct request *rq)* for normal execution. */ if ((policy &REQ_FSEQ_DATA ) && - !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) -return false; + !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) { +blk_mq_request_bypass_insert (rq, false, true); +return ; + }/* * @rq should go through flush machinery. Mark it part of flush
@@ -437,8 +439,6 @@ bool blk_insert_flush(struct request *rq)spin_lock_irq (&fq->mq_flush_lock);blk_flush_complete_seq (rq, fq,REQ_FSEQ_ACTIONS & ~policy,0 );spin_unlock_irq (&fq->mq_flush_lock); - -return true; }/**
block/blk-mq.c +3 -1
@@ -2647,8 +2647,10 @@ void blk_mq_submit_bio(struct bio *bio)return ; } -if (op_is_flush (bio->bi_opf) &&blk_insert_flush (rq)) +if (op_is_flush (bio->bi_opf)) { +blk_insert_flush (rq);return ; + } if (plug && (q->nr_hw_queues == 1 || blk_mq_is_shared_tags(rq->mq_hctx->flags) ||
block/blk.h +1 -1
@@ -272,7 +272,7 @@ void __blk_account_io_done(struct request *req, u64 now);*/ #define ELV_ON_HASH (rq) ((rq)->rq_flags & RQF_HASHED) -bool blk_insert_flush (struct request *rq); +void blk_insert_flush (struct request *rq);int elevator_switch_mq (struct request_queue *q,struct elevator_type *new_e);
Signature · 1 line
2.31.1
Quoted 8 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.
Quoted 4 lines
Fix the issue by inserting FUA data request with
blk_mq_request_bypass_insert()when the device supports FUA, just like what we did before.
I had not yet noticed that report. Anyway, thank you for having fixed this issue.
Quoted 10 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.Fix the issue by inserting FUA data request with
blk_mq_request_bypass_insert()when the device supports FUA, just like what we did before.
How we did end up with REQ_ELV set for this request?
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.
Quoted 4 lines
Quoted 2 lines
Fix the issue by inserting FUA data request with
blk_mq_request_bypass_insert()when the device supports FUA, just like what we did before.How we did end up with
REQ_ELVset for this request?
We set REQ_ELV for any request if q->elevator isn't NULL, see __blk_mq_alloc_requests(), and REQ_ELV is just for replacing the check on q->elevator. If we clear REQ_ELV for flush rq, other problem may be caused, such as blk_mq_rq_ctx_init() may be confused.
Also flush request is always inserted to hctx->dispatch directly, either before commit d92ca9d8348f or being queued via requeue in current code.
Thanks,
Ming
Quoted 9 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.[...]
Applied, thanks!
[1/1] blk-mq: don't insert FUA request with data into scheduler queue
commit: 2b504bd4841bccbf3eb83c1fec229b65956ad8ad
Best regards,
Signature · 1 line
Jens Axboe
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 13 lines · On 19 Nov 2021 Tim Walker wrote:
Quoted 9 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.[...]
Quoted 11 lines
Applied, thanks!
[1/1] blk-mq: don't insert FUA request with data into scheduler queue
commit: 2b504bd4841bccbf3eb83c1fec229b65956ad8adBest regards,
--
Jens Axboe
I know the discussion is over, but I can't figure out why we treat FUA as a flush. A FUA write only applies to the command at hand, and is not required to flush any previous command's data from the device's volatile write cache. Similarly for a read request - servicing a read from media is really more the rule than the exception (lots of workload dependencies here...), so why would a FUA read bypass the scheduler? The device is always free to service any request from media or cache (as long as it follows the applicable volatile write and read cache settings), so normally we don't know how it is treating the request, so it doesn't seem to matter.
Consider a FUA write: Why does the fact that we intend that write to bypass the device volatile write cache mean it should bypass the scheduler? All the other traffic-shaping algorithms that help effectively schedule writes are still applicable. E.g. we know we can delay/coalesce them a bit to allow reads to be prioritized, but I can't figure out why we would fast-track a FUA write. Isn't the value to the system for scheduling still valid, even though we are forcing the data to go to media?
I'm sure there is some detail I am missing - any help would be appreciated. Thanks!
Best regards,
-Tim
Direct reply without a quote a the formatting of your mail is completely messed up. We don't treat a FUA a a flush. If the device supports FUA is is just passed on. But if the device does not support FUA it is sequenced into doing the write first and then a flush before returning completion to the caller to guarantee the FUA semantics. Because of that the command needs special treatment and be handed over to the flush state machine, but it won't do anything interesting if FUA is actually natively supported.
Quoted 3 lines · Christoph Hellwig
Direct reply without a quote a the formatting of your mail is completely messed up.
Sorry about that - hopefully this is better.
Quoted 2 lines
We don't treat a FUA a a flush. If the device supports FUA is is just passed on.
Does this mean a FUA request for a device that natively supports FUA is eventually "passed on" to the scheduler? Or does it go straight to dispatch?
Quoted 7 lines
But if the device does not support FUA it
is sequenced into doing the write first and then a flush before returning completion to the caller to guarantee the FUA semantics. Because of that the command needs special treatment and be handed over to the flush state machine, but it won't do anything interesting if FUA is actually natively supported.
Yes, I can see why this flush logic is needed for devices that don't support FUA. Thanks.
Quoted 22 lines · Tim Walker
Quoted 18 lines · On 19 Nov 2021 Tim Walker wrote:
Quoted 9 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.[...]
Applied, thanks!
[1/1] blk-mq: don't insert FUA request with data into scheduler queue
commit: 2b504bd4841bccbf3eb83c1fec229b65956ad8ad
Quoted 8 lines
Quoted 6 lines
Best regards,
--
Jens AxboeI know the discussion is over, >
This thread is just for fixing one recent regression caused by queuing FUA data into scheduler queue, and actually direct dispach has been done for very long time, but I don't mean it is reasonable.
Quoted 6 lines
but I can't figure out why we treat FUA as a flush. A FUA write only applies to the command at hand, and is not required to flush any previous command's data from the device's volatile write cache. Similarly for a read request - servicing a read from media is really more the rule than the exception (lots of workload dependencies here...), so why would a FUA read bypass the scheduler?
Is there linux kernel FUA read users? Just run a quick grep, seems FUA is just used for sync write.
Quoted 5 lines
The device is always free to service any request from media or cache ( as long as it follows the applicable volatile write and read cache settings), so normally we don't know how it is treating the request, so it doesn't seem to matter.
Quoted 7 lines
Consider a FUA write: Why does the fact that we intend that write to bypass the device volatile write cache mean it should bypass the scheduler? All the other traffic-shaping algorithms that help effectively schedule writes are still applicable. E.g. we know we can delay/coalesce them a bit to allow reads to be prioritized, but I can't figure out why we would fast-track a FUA write. Isn't the value to the system for scheduling still valid, even though we are forcing the data to go to media?
It shouldn't be hard to to queue FUA into scheduler, but details need to consider, such as, if FUA can be merged with normal IO, maybe others.
Also do you have any test or benchmark result to support the change of queuing FUA to scheduler?
Thanks,
Ming
Quoted 44 lines · Ming Lei
Quoted 22 lines · Tim Walker
Quoted 18 lines · On 19 Nov 2021 Tim Walker wrote:
Quoted 9 lines · Ming Lei
We never insert flush request into scheduler queue before.
Recently commit
d92ca9d8348f("blk-mq: don't handle non-flush requests inblk_insert_flush") tries to handle FUA data request as normal request. This way has caused warning[1] in mq-deadlinedd_exit_sched()or io hang in case of kyber sinceRQF_ELVPRIVisn't set for flush request, then ->finish_request won't be called.[...]
Applied, thanks!
[1/1] blk-mq: don't insert FUA request with data into scheduler queue
commit: 2b504bd4841bccbf3eb83c1fec229b65956ad8adQuoted 8 lines
Quoted 6 lines
Best regards,
--
Jens AxboeI know the discussion is over, >
This thread is just for fixing one recent regression caused by queuing FUA data into scheduler queue, and actually direct dispach has been done for very long time, but I don't mean it is reasonable.
Quoted 6 lines
but I can't figure out why we treat FUA as a flush. A FUA write only applies to the command at hand, and is not required to flush any previous command's data from the device's volatile write cache. Similarly for a read request - servicing a read from media is really more the rule than the exception (lots of workload dependencies here...), so why would a FUA read bypass the scheduler?
Quoted 2 lines
Is there linux kernel FUA read users? Just run a quick grep, seems FUA is just used for sync write.
I don't know if Linux ever issues FUA read. I was thinking from the device's perspective.
Quoted 17 lines
Quoted 6 lines
The device is always free to service any request from media or cache ( as long as it follows the applicable volatile write and read cache settings), so normally we don't know how it is treating the request, so it doesn't seem to matter.
Quoted 7 lines
Consider a FUA write: Why does the fact that we intend that write to bypass the device volatile write cache mean it should bypass the scheduler? All the other traffic-shaping algorithms that help effectively schedule writes are still applicable. E.g. we know we can delay/coalesce them a bit to allow reads to be prioritized, but I can't figure out why we would fast-track a FUA write. Isn't the value to the system for scheduling still valid, even though we are forcing the data to go to media?
It shouldn't be hard to to queue FUA into scheduler, but details need to consider, such as, if FUA can be merged with normal IO, maybe others.
Quoted 7 lines
Also do you have any test or benchmark result to support the change of queuing FUA to scheduler?
Thanks,
Ming
No, Unfortunately I don't have any benchmarks. It seems that FUA creates a shortcut by-passing the scheduler. It does not seem too important for flash, but of course HDDs are very sensitive to workload. The scheduler attempts to ensure the best workload for the best performance, so perhaps all requests should be scheduled, unless there is an architectural reason to the contrary. From a HDD's perspective we should schedule a FUA write to maintain an optimal workload, and I was looking for the block-layer-architecture reason not to.
Perhaps I can generate some problematic workloads and post them later for discussion.
Thanks,
-Tim