Commit 82b74cac authored by Jan Kara's avatar Jan Kara Committed by Jens Axboe

blk-ioprio: Convert from rqos policy to direct call

Convert blk-ioprio handling from a rqos policy to a direct call from
blk_mq_submit_bio(). Firstly, blk-ioprio is not much of a rqos policy
anyway, it just needs a hook in bio submission path to set the bio's IO
priority. Secondly, the rqos .track hook gets actually called too late
for blk-ioprio purposes and introducing a special rqos hook just for
blk-ioprio looks even weirder.
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Tested-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220623074840.5960-7-jack@suse.czSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f2586544
...@@ -1299,6 +1299,7 @@ int blkcg_init_queue(struct request_queue *q) ...@@ -1299,6 +1299,7 @@ int blkcg_init_queue(struct request_queue *q)
ret = blk_iolatency_init(q); ret = blk_iolatency_init(q);
if (ret) { if (ret) {
blk_throtl_exit(q); blk_throtl_exit(q);
blk_ioprio_exit(q);
goto err_destroy_all; goto err_destroy_all;
} }
......
...@@ -181,17 +181,12 @@ static struct blkcg_policy ioprio_policy = { ...@@ -181,17 +181,12 @@ static struct blkcg_policy ioprio_policy = {
.pd_free_fn = ioprio_free_pd, .pd_free_fn = ioprio_free_pd,
}; };
struct blk_ioprio { void blkcg_set_ioprio(struct bio *bio)
struct rq_qos rqos;
};
static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
struct bio *bio)
{ {
struct ioprio_blkcg *blkcg = ioprio_blkcg_from_bio(bio); struct ioprio_blkcg *blkcg = ioprio_blkcg_from_bio(bio);
u16 prio; u16 prio;
if (blkcg->prio_policy == POLICY_NO_CHANGE) if (!blkcg || blkcg->prio_policy == POLICY_NO_CHANGE)
return; return;
/* /*
...@@ -207,49 +202,14 @@ static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq, ...@@ -207,49 +202,14 @@ static void blkcg_ioprio_track(struct rq_qos *rqos, struct request *rq,
bio->bi_ioprio = prio; bio->bi_ioprio = prio;
} }
static void blkcg_ioprio_exit(struct rq_qos *rqos) void blk_ioprio_exit(struct request_queue *q)
{ {
struct blk_ioprio *blkioprio_blkg = blkcg_deactivate_policy(q, &ioprio_policy);
container_of(rqos, typeof(*blkioprio_blkg), rqos);
blkcg_deactivate_policy(rqos->q, &ioprio_policy);
kfree(blkioprio_blkg);
} }
static struct rq_qos_ops blkcg_ioprio_ops = {
.track = blkcg_ioprio_track,
.exit = blkcg_ioprio_exit,
};
int blk_ioprio_init(struct request_queue *q) int blk_ioprio_init(struct request_queue *q)
{ {
struct blk_ioprio *blkioprio_blkg; return blkcg_activate_policy(q, &ioprio_policy);
struct rq_qos *rqos;
int ret;
blkioprio_blkg = kzalloc(sizeof(*blkioprio_blkg), GFP_KERNEL);
if (!blkioprio_blkg)
return -ENOMEM;
ret = blkcg_activate_policy(q, &ioprio_policy);
if (ret) {
kfree(blkioprio_blkg);
return ret;
}
rqos = &blkioprio_blkg->rqos;
rqos->id = RQ_QOS_IOPRIO;
rqos->ops = &blkcg_ioprio_ops;
rqos->q = q;
/*
* Registering the rq-qos policy after activating the blk-cgroup
* policy guarantees that ioprio_blkcg_from_bio(bio) != NULL in the
* rq-qos callbacks.
*/
rq_qos_add(q, rqos);
return 0;
} }
static int __init ioprio_init(void) static int __init ioprio_init(void)
......
...@@ -6,14 +6,23 @@ ...@@ -6,14 +6,23 @@
#include <linux/kconfig.h> #include <linux/kconfig.h>
struct request_queue; struct request_queue;
struct bio;
#ifdef CONFIG_BLK_CGROUP_IOPRIO #ifdef CONFIG_BLK_CGROUP_IOPRIO
int blk_ioprio_init(struct request_queue *q); int blk_ioprio_init(struct request_queue *q);
void blk_ioprio_exit(struct request_queue *q);
void blkcg_set_ioprio(struct bio *bio);
#else #else
static inline int blk_ioprio_init(struct request_queue *q) static inline int blk_ioprio_init(struct request_queue *q)
{ {
return 0; return 0;
} }
static inline void blk_ioprio_exit(struct request_queue *q)
{
}
static inline void blkcg_set_ioprio(struct bio *bio)
{
}
#endif #endif
#endif /* _BLK_IOPRIO_H_ */ #endif /* _BLK_IOPRIO_H_ */
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "blk-stat.h" #include "blk-stat.h"
#include "blk-mq-sched.h" #include "blk-mq-sched.h"
#include "blk-rq-qos.h" #include "blk-rq-qos.h"
#include "blk-ioprio.h"
static DEFINE_PER_CPU(struct llist_head, blk_cpu_done); static DEFINE_PER_CPU(struct llist_head, blk_cpu_done);
...@@ -2779,6 +2780,11 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q, ...@@ -2779,6 +2780,11 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
return rq; return rq;
} }
static void bio_set_ioprio(struct bio *bio)
{
blkcg_set_ioprio(bio);
}
/** /**
* blk_mq_submit_bio - Create and send a request to block device. * blk_mq_submit_bio - Create and send a request to block device.
* @bio: Bio pointer. * @bio: Bio pointer.
...@@ -2819,6 +2825,8 @@ void blk_mq_submit_bio(struct bio *bio) ...@@ -2819,6 +2825,8 @@ void blk_mq_submit_bio(struct bio *bio)
trace_block_getrq(bio); trace_block_getrq(bio);
bio_set_ioprio(bio);
rq_qos_track(q, rq, bio); rq_qos_track(q, rq, bio);
blk_mq_bio_to_request(rq, bio, nr_segs); blk_mq_bio_to_request(rq, bio, nr_segs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment