From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
John Garry <john.garry@huawei.com>,
Bart Van Assche <bvanassche@acm.org>,
Hannes Reinecke <hare@suse.com>, Christoph Hellwig <hch@lst.de>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH V6 5/8] block: add blk_end_flush_machinery
Date: Tue, 7 Apr 2020 17:28:58 +0800 [thread overview]
Message-ID: <20200407092901.314228-6-ming.lei@redhat.com> (raw)
In-Reply-To: <20200407092901.314228-1-ming.lei@redhat.com>
Flush requests aren't same with normal FS request:
1) on dedicated per-hctx flush rq is pre-allocated for sending flush request
2) flush requests are issued to hardware via one machinary so that flush merge
can be applied
We can't simply re-submit flush rqs via blk_steal_bios(), so add
blk_end_flush_machinery to collect flush requests which needs to
be resubmitted:
- if one flush command without DATA is enough, send one flush, complete this
kind of requests
- otherwise, add the request into a list and let caller re-submit it.
Cc: John Garry <john.garry@huawei.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-flush.c | 125 +++++++++++++++++++++++++++++++++++++++++++---
block/blk.h | 4 ++
2 files changed, 122 insertions(+), 7 deletions(-)
diff --git a/block/blk-flush.c b/block/blk-flush.c
index 7b247c0470c0..75aa9b4d2880 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -173,10 +173,11 @@ static void blk_flush_complete_seq(struct request *rq,
unsigned int cmd_flags;
BUG_ON(rq->flush.seq & seq);
- rq->flush.seq |= seq;
+ if (!error)
+ rq->flush.seq |= seq;
cmd_flags = rq->cmd_flags;
- if (likely(!error))
+ if (likely(!error && !fq->flush_queue_terminating))
seq = blk_flush_cur_seq(rq);
else
seq = REQ_FSEQ_DONE;
@@ -203,9 +204,15 @@ static void blk_flush_complete_seq(struct request *rq,
* normal completion and end it.
*/
BUG_ON(!list_empty(&rq->queuelist));
- list_del_init(&rq->flush.list);
- blk_flush_restore_request(rq);
- blk_mq_end_request(rq, error);
+
+ /* Terminating code will end the request from flush queue */
+ if (likely(!fq->flush_queue_terminating)) {
+ list_del_init(&rq->flush.list);
+ blk_flush_restore_request(rq);
+ blk_mq_end_request(rq, error);
+ } else {
+ list_move_tail(&rq->flush.list, pending);
+ }
break;
default:
@@ -282,7 +289,8 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
struct request *flush_rq = fq->flush_rq;
/* C1 described at the top of this file */
- if (fq->flush_pending_idx != fq->flush_running_idx || list_empty(pending))
+ if (fq->flush_pending_idx != fq->flush_running_idx ||
+ list_empty(pending) || fq->flush_queue_terminating)
return;
/* C2 and C3
@@ -334,7 +342,7 @@ static void mq_flush_data_end_io(struct request *rq, blk_status_t error)
struct blk_flush_queue *fq = blk_get_flush_queue(q, ctx);
if (q->elevator) {
- WARN_ON(rq->tag < 0);
+ WARN_ON(rq->tag < 0 && !fq->flush_queue_terminating);
blk_mq_put_driver_tag(rq);
}
@@ -515,3 +523,106 @@ void blk_free_flush_queue(struct blk_flush_queue *fq)
kfree(fq->flush_rq);
kfree(fq);
}
+
+static void __blk_end_queued_flush(struct blk_flush_queue *fq,
+ unsigned int queue_idx, struct list_head *resubmit_list,
+ struct list_head *flush_list)
+{
+ struct list_head *queue = &fq->flush_queue[queue_idx];
+ struct request *rq, *nxt;
+
+ list_for_each_entry_safe(rq, nxt, queue, flush.list) {
+ unsigned int seq = blk_flush_cur_seq(rq);
+
+ list_del_init(&rq->flush.list);
+ blk_flush_restore_request(rq);
+ if (!blk_rq_sectors(rq) || seq == REQ_FSEQ_POSTFLUSH )
+ list_add_tail(&rq->queuelist, flush_list);
+ else
+ list_add_tail(&rq->queuelist, resubmit_list);
+ }
+}
+
+static void blk_end_queued_flush(struct blk_flush_queue *fq,
+ struct list_head *resubmit_list, struct list_head *flush_list)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&fq->mq_flush_lock, flags);
+ __blk_end_queued_flush(fq, 0, resubmit_list, flush_list);
+ __blk_end_queued_flush(fq, 1, resubmit_list, flush_list);
+ spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
+}
+
+/* complete requests which just requires one flush command */
+static void blk_complete_flush_requests(struct blk_flush_queue *fq,
+ struct list_head *flush_list)
+{
+ struct block_device *bdev;
+ struct request *rq;
+ int error = -ENXIO;
+
+ if (list_empty(flush_list))
+ return;
+
+ rq = list_first_entry(flush_list, struct request, queuelist);
+
+ /* Send flush via one active hctx so we can move on */
+ bdev = bdget_disk(rq->rq_disk, 0);
+ if (bdev) {
+ error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
+ bdput(bdev);
+ }
+
+ while (!list_empty(flush_list)) {
+ rq = list_first_entry(flush_list, struct request, queuelist);
+ list_del_init(&rq->queuelist);
+ blk_mq_end_request(rq, error);
+ }
+}
+
+/*
+ * Called when this hctx is inactive and all CPUs of this hctx is dead.
+ *
+ * Terminate this hw queue's flush machinery, and try to complete flush
+ * IO requests if possible, such as any flush IO without data, or flush
+ * data IO in POSTFLUSH stage. Otherwise, add the flush IOs into @list
+ * and let caller to re-submit them.
+ *
+ * No need to hold the flush queue lock given no any flush activity can
+ * reach this queue now.
+ */
+void blk_end_flush_machinery(struct blk_mq_hw_ctx *hctx,
+ struct list_head *in, struct list_head *out)
+{
+ LIST_HEAD(resubmit_list);
+ LIST_HEAD(flush_list);
+ struct blk_flush_queue *fq = hctx->fq;
+ struct request *rq, *nxt;
+ unsigned long flags;
+
+ spin_lock_irqsave(&fq->mq_flush_lock, flags);
+ fq->flush_queue_terminating = 1;
+ spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
+
+ /* End inflight flush requests */
+ list_for_each_entry_safe(rq, nxt, in, queuelist) {
+ WARN_ON(!(rq->rq_flags & RQF_FLUSH_SEQ));
+ list_del_init(&rq->queuelist);
+ rq->end_io(rq, BLK_STS_AGAIN);
+ }
+
+ /* End queued requests */
+ blk_end_queued_flush(fq, &resubmit_list, &flush_list);
+
+ /* Send flush and complete requests which just need one flush req */
+ blk_complete_flush_requests(fq, &flush_list);
+
+ spin_lock_irqsave(&fq->mq_flush_lock, flags);
+ /* reset flush queue so that it is ready to work next time */
+ fq->flush_pending_idx = fq->flush_running_idx = 0;
+ fq->flush_queue_terminating = 0;
+ spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
+
+ list_splice_init(&resubmit_list, out);
+}
diff --git a/block/blk.h b/block/blk.h
index c824d66f24e2..594e4236d55c 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -19,6 +19,7 @@ struct blk_flush_queue {
unsigned int flush_queue_delayed:1;
unsigned int flush_pending_idx:1;
unsigned int flush_running_idx:1;
+ unsigned int flush_queue_terminating:1;
blk_status_t rq_status;
unsigned long flush_pending_since;
struct list_head flush_queue[2];
@@ -349,4 +350,7 @@ void blk_queue_free_zone_bitmaps(struct request_queue *q);
static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
#endif
+void blk_end_flush_machinery(struct blk_mq_hw_ctx *hctx,
+ struct list_head *in, struct list_head *out);
+
#endif /* BLK_INTERNAL_H */
--
2.25.2
next prev parent reply other threads:[~2020-04-07 9:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 9:28 [PATCH V6 0/8] blk-mq: improvement CPU hotplug Ming Lei
2020-04-07 9:28 ` [PATCH V6 1/8] blk-mq: assign rq->tag in blk_mq_get_driver_tag Ming Lei
2020-04-07 17:14 ` Christoph Hellwig
2020-04-08 1:38 ` Ming Lei
2020-04-07 9:28 ` [PATCH V6 2/8] blk-mq: add new state of BLK_MQ_S_INACTIVE Ming Lei
2020-04-07 17:14 ` Christoph Hellwig
2020-04-07 9:28 ` [PATCH V6 3/8] blk-mq: prepare for draining IO when hctx's all CPUs are offline Ming Lei
2020-04-07 9:28 ` [PATCH V6 4/8] blk-mq: stop to handle IO and drain IO before hctx becomes inactive Ming Lei
2020-04-07 9:28 ` Ming Lei [this message]
2020-04-07 9:28 ` [PATCH V6 6/8] blk-mq: re-submit IO in case that hctx is inactive Ming Lei
2020-04-07 9:29 ` [PATCH V6 7/8] blk-mq: handle requests dispatched from IO scheduler in case of inactive hctx Ming Lei
2020-04-07 9:29 ` [PATCH V6 8/8] block: deactivate hctx when the hctx is actually inactive Ming Lei
2020-04-08 12:40 ` [PATCH V6 0/8] blk-mq: improvement CPU hotplug Daniel Wagner
2020-04-08 13:01 ` John Garry
2020-04-08 13:10 ` Daniel Wagner
2020-04-08 13:29 ` John Garry
2020-04-08 15:14 ` Daniel Wagner
2020-04-08 16:56 ` John Garry
2020-04-08 13:25 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200407092901.314228-6-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=john.garry@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).