History

block: sum requests in the plug structure

This isn't exactly the same as the previous count, as it includes requests for all devices. But that really doesn't matter, if we have more than the threshold (16) queued up, flush it. It's not worth it to have an expensive list loop for this.

Jens Axboe committed 7 years ago

Commit 5f0ed771 parent af78ff74 files · +10 −39Browse files

Unified · Split

4 files
  1. block/blk-core.c +4 −26
  2. block/blk-mq.c +5 −11
  3. block/blk.h +0 −2
  4. include/linux/blkdev.h +1 −0
block/blk-core.c+4−26
@@ -736,7 +736,6 @@ no_merge: · 735 unmodified lines
736736 * Caller must ensure !blk_queue_nomerges(q) beforehand.
737737 */
738738 bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
739− unsigned int *request_count,
740739 struct request **same_queue_rq)
741740 {
742741 struct blk_plug *plug;
@@ -746,22 +745,19 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio, · 3 unmodified lines
746745 plug = current->plug;
747746 if (!plug)
748747 return false;
749− *request_count = 0;
750748
751749 plug_list = &plug->mq_list;
752750
753751 list_for_each_entry_reverse(rq, plug_list, queuelist) {
754752 bool merged = false;
755753
756− if (rq->q == q) {
757− (*request_count)++;
754+ if (rq->q == q && same_queue_rq) {
758755 /*
759756 * Only blk-mq multiple hardware queues case checks the
760757 * rq in the same queue, there should be only one such
761758 * rq in a queue
762759 **/
763− if (same_queue_rq)
764− *same_queue_rq = rq;
760+ *same_queue_rq = rq;
765761 }
766762
767763 if (rq->q != q || !blk_rq_merge_ok(rq, bio))
@@ -788,26 +784,6 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio, · 20 unmodified lines
788784 return false;
789785 }
790786
791−unsigned int blk_plug_queued_count(struct request_queue *q)
792−{
793− struct blk_plug *plug;
794− struct request *rq;
795− struct list_head *plug_list;
796− unsigned int ret = 0;
797−
798− plug = current->plug;
799− if (!plug)
800− goto out;
801−
802− plug_list = &plug->mq_list;
803− list_for_each_entry(rq, plug_list, queuelist) {
804− if (rq->q == q)
805− ret++;
806− }
807−out:
808− return ret;
809−}
810−
811787 void blk_init_request_from_bio(struct request *req, struct bio *bio)
812788 {
813789 if (bio->bi_opf & REQ_RAHEAD)
@@ -1803,6 +1779,8 @@ void blk_start_plug(struct blk_plug *plug) · 989 unmodified lines
18031779
18041780 INIT_LIST_HEAD(&plug->mq_list);
18051781 INIT_LIST_HEAD(&plug->cb_list);
1782+ plug->rq_count = 0;
1783+
18061784 /*
18071785 * Store ordering should not be needed here, since a potential
18081786 * preempt will imply a full memory barrier
block/blk-mq.c+5−11
@@ -1675,6 +1675,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · 1674 unmodified lines
16751675 unsigned int depth;
16761676
16771677 list_splice_init(&plug->mq_list, &list);
1678+ plug->rq_count = 0;
16781679
16791680 list_sort(NULL, &list, plug_rq_cmp);
16801681
@@ -1871,7 +1872,6 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 190 unmodified lines
18711872 const int is_flush_fua = op_is_flush(bio->bi_opf);
18721873 struct blk_mq_alloc_data data = { .flags = 0, .cmd_flags = bio->bi_opf };
18731874 struct request *rq;
1874− unsigned int request_count = 0;
18751875 struct blk_plug *plug;
18761876 struct request *same_queue_rq = NULL;
18771877 blk_qc_t cookie;
@@ -1884,7 +1884,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 6 unmodified lines
18841884 return BLK_QC_T_NONE;
18851885
18861886 if (!is_flush_fua && !blk_queue_nomerges(q) &&
1887− blk_attempt_plug_merge(q, bio, &request_count, &same_queue_rq))
1887+ blk_attempt_plug_merge(q, bio, &same_queue_rq))
18881888 return BLK_QC_T_NONE;
18891889
18901890 if (blk_mq_sched_bio_merge(q, bio))
@@ -1915,20 +1915,12 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 24 unmodified lines
19151915 blk_insert_flush(rq);
19161916 blk_mq_run_hw_queue(data.hctx, true);
19171917 } else if (plug && q->nr_hw_queues == 1) {
1918+ unsigned int request_count = plug->rq_count;
19181919 struct request *last = NULL;
19191920
19201921 blk_mq_put_ctx(data.ctx);
19211922 blk_mq_bio_to_request(rq, bio);
19221923
1923− /*
1924− * @request_count may become stale because of schedule
1925− * out, so check the list again.
1926− */
1927− if (list_empty(&plug->mq_list))
1928− request_count = 0;
1929− else if (blk_queue_nomerges(q))
1930− request_count = blk_plug_queued_count(q);
1931−
19321924 if (!request_count)
19331925 trace_block_plug(q);
19341926 else
@@ -1941,6 +1933,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 6 unmodified lines
19411933 }
19421934
19431935 list_add_tail(&rq->queuelist, &plug->mq_list);
1936+ plug->rq_count++;
19441937 } else if (plug && !blk_queue_nomerges(q)) {
19451938 blk_mq_bio_to_request(rq, bio);
19461939
@@ -1956,6 +1949,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 9 unmodified lines
19561949 if (same_queue_rq)
19571950 list_del_init(&same_queue_rq->queuelist);
19581951 list_add_tail(&rq->queuelist, &plug->mq_list);
1952+ plug->rq_count++;
19591953
19601954 blk_mq_put_ctx(data.ctx);
19611955
block/blk.h+0−2
@@ -161,9 +161,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req, · 160 unmodified lines
161161 bool bio_attempt_discard_merge(struct request_queue *q, struct request *req,
162162 struct bio *bio);
163163 bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
164− unsigned int *request_count,
165164 struct request **same_queue_rq);
166−unsigned int blk_plug_queued_count(struct request_queue *q);
167165
168166 void blk_account_io_start(struct request *req, bool new_io);
169167 void blk_account_io_completion(struct request *req, unsigned int bytes);
include/linux/blkdev.h+1−0
@@ -1130,6 +1130,7 @@ extern void blk_set_queue_dying(struct request_queue *); · 1129 unmodified lines
11301130 struct blk_plug {
11311131 struct list_head mq_list; /* blk-mq requests */
11321132 struct list_head cb_list; /* md requires an unplug callback */
1133+ unsigned short rq_count;
11331134 };
11341135 #define BLK_MAX_REQUEST_COUNT 16
11351136 #define BLK_PLUG_FLUSH_SIZE (128 * 1024)