From 9726dea73b24975ad36833ab9ec638fa0ec5ec79 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Wed, 28 Aug 2019 15:05:54 -0700 Subject: [PATCH] block/rq_qos: add rq_qos_merge() commit d3e65ffff61c329fb2d0bf15736c440c2d0cfc97 upstream. Add a merge hook for rq_qos. This will be used by io.weight. Signed-off-by: Tejun Heo Signed-off-by: Jens Axboe Signed-off-by: Joseph Qi Signed-off-by: Jiufei Xue Reviewed-by: Joseph Qi --- block/blk-core.c | 4 ++++ block/blk-rq-qos.c | 9 +++++++++ block/blk-rq-qos.h | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index ea33d6abdcfc..dddb63d67b50 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1812,6 +1812,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req, return false; trace_block_bio_backmerge(q, req, bio); + rq_qos_merge(q, req, bio); if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff) blk_rq_set_mixed_merge(req); @@ -1834,6 +1835,7 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req, return false; trace_block_bio_frontmerge(q, req, bio); + rq_qos_merge(q, req, bio); if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff) blk_rq_set_mixed_merge(req); @@ -1860,6 +1862,8 @@ bool bio_attempt_discard_merge(struct request_queue *q, struct request *req, blk_rq_get_max_sectors(req, blk_rq_pos(req))) goto no_merge; + rq_qos_merge(q, req, bio); + req->biotail->bi_next = bio; req->biotail = bio; req->__data_len += bio->bi_iter.bi_size; diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c index 43bcd4e7a7f9..45df2889c59e 100644 --- a/block/blk-rq-qos.c +++ b/block/blk-rq-qos.c @@ -88,6 +88,15 @@ void rq_qos_track(struct request_queue *q, struct request *rq, struct bio *bio) } } +void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio) +{ + do { + if (rqos->ops->merge) + rqos->ops->merge(rqos, rq, bio); + rqos = rqos->next; + } while (rqos); +} + void rq_qos_done_bio(struct request_queue *q, struct bio *bio) { struct rq_qos *rqos; diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h index 98caba3e962e..7cceed738fe6 100644 --- a/block/blk-rq-qos.h +++ b/block/blk-rq-qos.h @@ -27,6 +27,7 @@ struct rq_qos { struct rq_qos_ops { void (*throttle)(struct rq_qos *, struct bio *, spinlock_t *); void (*track)(struct rq_qos *, struct request *, struct bio *); + void (*merge)(struct rq_qos *, struct request *, struct bio *); void (*issue)(struct rq_qos *, struct request *); void (*requeue)(struct rq_qos *, struct request *); void (*done)(struct rq_qos *, struct request *); @@ -102,5 +103,14 @@ void rq_qos_requeue(struct request_queue *, struct request *); void rq_qos_done_bio(struct request_queue *q, struct bio *bio); void rq_qos_throttle(struct request_queue *, struct bio *, spinlock_t *); void rq_qos_track(struct request_queue *q, struct request *, struct bio *); +void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio); void rq_qos_exit(struct request_queue *); + +static inline void rq_qos_merge(struct request_queue *q, struct request *rq, + struct bio *bio) +{ + if (q->rq_qos) + __rq_qos_merge(q->rq_qos, rq, bio); +} + #endif -- GitLab