@@ -165,6 +165,7 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
return BLK_MQ_NO_TAG;
}
+ wait.nr_tags += data->nr_split;
do {
struct sbitmap_queue *bt_prev;
@@ -2760,12 +2760,14 @@ static bool blk_mq_attempt_bio_merge(struct request_queue *q,
static struct request *blk_mq_get_new_requests(struct request_queue *q,
struct blk_plug *plug,
struct bio *bio,
- unsigned int nsegs)
+ unsigned int nsegs,
+ unsigned int nr_split)
{
struct blk_mq_alloc_data data = {
.q = q,
.nr_tags = 1,
.cmd_flags = bio->bi_opf,
+ .nr_split = nr_split,
.preempt = (bio->bi_opf & REQ_PREEMPT),
};
struct request *rq;
@@ -2824,6 +2826,19 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
return rq;
}
+static inline unsigned int caculate_sectors_split(struct bio *bio)
+{
+ switch (bio_op(bio)) {
+ case REQ_OP_DISCARD:
+ case REQ_OP_SECURE_ERASE:
+ case REQ_OP_WRITE_ZEROES:
+ return 0;
+ default:
+ return (bio_sectors(bio) - 1) /
+ queue_max_sectors(bio->bi_bdev->bd_queue);
+ }
+}
+
/**
* blk_mq_submit_bio - Create and send a request to block device.
* @bio: Bio pointer.
@@ -2844,11 +2859,14 @@ void blk_mq_submit_bio(struct bio *bio)
const int is_sync = op_is_sync(bio->bi_opf);
struct request *rq;
unsigned int nr_segs = 1;
+ unsigned int nr_split = 0;
blk_status_t ret;
blk_queue_bounce(q, &bio);
- if (blk_may_split(q, bio))
+ if (blk_may_split(q, bio)) {
+ nr_split = caculate_sectors_split(bio);
__blk_queue_split(q, &bio, &nr_segs);
+ }
if (!bio_integrity_prep(bio))
return;
@@ -2857,7 +2875,7 @@ void blk_mq_submit_bio(struct bio *bio)
if (!rq) {
if (!bio)
return;
- rq = blk_mq_get_new_requests(q, plug, bio, nr_segs);
+ rq = blk_mq_get_new_requests(q, plug, bio, nr_segs, nr_split);
if (unlikely(!rq))
return;
}
@@ -156,6 +156,8 @@ struct blk_mq_alloc_data {
/* allocate multiple requests/tags in one go */
unsigned int nr_tags;
+ /* number of ios left after this io is handled */
+ unsigned int nr_split;
/* true if blk_mq_get_tag() will try to preempt tag */
bool preempt;
struct request **cached_rq;
@@ -596,12 +596,14 @@ void sbitmap_queue_wake_up(struct sbitmap_queue *sbq);
void sbitmap_queue_show(struct sbitmap_queue *sbq, struct seq_file *m);
struct sbq_wait {
+ unsigned int nr_tags;
struct sbitmap_queue *sbq; /* if set, sbq_wait is accounted */
struct wait_queue_entry wait;
};
#define DEFINE_SBQ_WAIT(name) \
struct sbq_wait name = { \
+ .nr_tags = 1, \
.sbq = NULL, \
.wait = { \
.private = current, \
Currently, each time 8(or wake batch) requests is done, 8 waiters will be woken up, this is not necessary because we only need to make sure wakers will use up 8 tags. For example, if we know in advance that a thread need 8 tags, then wake up one thread is enough, and this can also avoid unnecessary context switch. On the other hand, sequential io is much faster than random io, thus it's better to issue split io continuously. This patch tries to provide such information that how many tags will be needed for huge io, and it will be used in next patch. Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- block/blk-mq-tag.c | 1 + block/blk-mq.c | 24 +++++++++++++++++++++--- block/blk-mq.h | 2 ++ include/linux/sbitmap.h | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-)