mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Jianchao <jianchao.wan9@gmail.com>
To: axboe@kernel.dk
Cc: jbacik@fb.com, tj@kernel.org, bvanassche@acm.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 08/13] blk-iocost: make iocost pluggable and modular
Date: Mon, 10 Jan 2022 17:10:41 +0800	[thread overview]
Message-ID: <20220110091046.17010-9-jianchao.wan9@gmail.com> (raw)
In-Reply-To: <20220110091046.17010-1-jianchao.wan9@gmail.com>

From: Wang Jianchao <wangjianchao@kuaishou.com>

Make blk-iocost pluggable and modular. Then we can close or open
it through /sys/block/xxx/queue/qos and rmmod the module if we don't
need it which can release one blkcg policy slot.

Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
---
 block/Kconfig          |  2 +-
 block/Makefile         |  4 ++--
 block/blk-iocost.c     | 53 ++++++++++++++++++++++++++----------------
 block/blk-mq-debugfs.c |  2 --
 block/blk-rq-qos.h     |  1 -
 5 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/block/Kconfig b/block/Kconfig
index e1b1bff5c1e9..3e1a3487b55a 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -134,7 +134,7 @@ config BLK_CGROUP_FC_APPID
 	  application specific identification into the FC frame.
 
 config BLK_CGROUP_IOCOST
-	bool "Enable support for cost model based cgroup IO controller"
+	tristate "Enable support for cost model based cgroup IO controller"
 	depends on BLK_CGROUP
 	select BLK_RQ_ALLOC_TIME
 	select BLK_BIO_IOCOST
diff --git a/block/Makefile b/block/Makefile
index ccf61c57e1d4..8950913cbcc9 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -20,8 +20,8 @@ obj-$(CONFIG_BLK_DEV_THROTTLING)	+= blk-throttle.o
 obj-$(CONFIG_BLK_CGROUP_IOPRIO)	+= blk-ioprio.o
 iolat-y 				:= blk-iolatency.o
 obj-$(CONFIG_BLK_CGROUP_IOLATENCY)	+= iolat.o
-
-obj-$(CONFIG_BLK_CGROUP_IOCOST)	+= blk-iocost.o
+iocost-y 			:= blk-iocost.o
+obj-$(CONFIG_BLK_CGROUP_IOCOST)	+= iocost.o
 obj-$(CONFIG_MQ_IOSCHED_DEADLINE)	+= mq-deadline.o
 obj-$(CONFIG_MQ_IOSCHED_KYBER)	+= kyber-iosched.o
 bfq-y				:= bfq-iosched.o bfq-wf2q.o bfq-cgroup.o
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index cfc0e305c32e..afa52354d42b 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -660,9 +660,10 @@ static struct ioc *rqos_to_ioc(struct rq_qos *rqos)
 	return container_of(rqos, struct ioc, rqos);
 }
 
+static struct rq_qos_ops ioc_rqos_ops;
 static struct ioc *q_to_ioc(struct request_queue *q)
 {
-	return rqos_to_ioc(rq_qos_by_id(q, RQ_QOS_COST));
+	return rqos_to_ioc(rq_qos_by_id(q, ioc_rqos_ops.id));
 }
 
 static const char *q_name(struct request_queue *q)
@@ -2810,6 +2811,7 @@ static void ioc_rqos_exit(struct rq_qos *rqos)
 	struct ioc *ioc = rqos_to_ioc(rqos);
 
 	blkcg_deactivate_policy(rqos->q, &blkcg_policy_iocost);
+	rq_qos_deactivate(rqos);
 
 	spin_lock_irq(&ioc->lock);
 	ioc->running = IOC_STOP;
@@ -2820,13 +2822,20 @@ static void ioc_rqos_exit(struct rq_qos *rqos)
 	kfree(ioc);
 }
 
+static int blk_iocost_init(struct request_queue *q);
 static struct rq_qos_ops ioc_rqos_ops = {
+#if IS_MODULE(CONFIG_BLK_CGROUP_IOCOST)
+	.owner = THIS_MODULE,
+#endif
+	.name = "iocost",
+	.flags = RQOS_FLAG_CGRP_POL | RQOS_FLAG_RQ_ALLOC_TIME,
 	.throttle = ioc_rqos_throttle,
 	.merge = ioc_rqos_merge,
 	.done_bio = ioc_rqos_done_bio,
 	.done = ioc_rqos_done,
 	.queue_depth_changed = ioc_rqos_queue_depth_changed,
 	.exit = ioc_rqos_exit,
+	.init = blk_iocost_init,
 };
 
 static int blk_iocost_init(struct request_queue *q)
@@ -2856,10 +2865,7 @@ static int blk_iocost_init(struct request_queue *q)
 	}
 
 	rqos = &ioc->rqos;
-	rqos->id = RQ_QOS_COST;
-	rqos->ops = &ioc_rqos_ops;
-	rqos->q = q;
-
+	rq_qos_activate(q, rqos, &ioc_rqos_ops);
 	spin_lock_init(&ioc->lock);
 	timer_setup(&ioc->timer, ioc_timer_fn, 0);
 	INIT_LIST_HEAD(&ioc->active_iocgs);
@@ -2883,10 +2889,9 @@ static int blk_iocost_init(struct request_queue *q)
 	 * called before policy activation completion, can't assume that the
 	 * target bio has an iocg associated and need to test for NULL iocg.
 	 */
-	rq_qos_add(q, rqos);
 	ret = blkcg_activate_policy(q, &blkcg_policy_iocost);
 	if (ret) {
-		rq_qos_del(q, rqos);
+		rq_qos_deactivate(rqos);
 		free_percpu(ioc->pcpu_stat);
 		kfree(ioc);
 		return ret;
@@ -3173,12 +3178,10 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
 	if (IS_ERR(bdev))
 		return PTR_ERR(bdev);
 
-	rqos = rq_qos_get(bdev_get_queue(bdev), RQ_QOS_COST);
+	rqos = rq_qos_get(bdev_get_queue(bdev), ioc_rqos_ops.id);
 	if (!rqos) {
-		ret = blk_iocost_init(bdev_get_queue(bdev));
-		if (ret)
-			goto err;
-		rqos = rq_qos_get(bdev_get_queue(bdev), RQ_QOS_COST);
+		ret = -EOPNOTSUPP;
+		goto err;
 	}
 
 	ioc = rqos_to_ioc(rqos);
@@ -3257,10 +3260,8 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
 
 	if (enable) {
 		blk_stat_enable_accounting(ioc->rqos.q);
-		blk_queue_flag_set(QUEUE_FLAG_RQ_ALLOC_TIME, ioc->rqos.q);
 		ioc->enabled = true;
 	} else {
-		blk_queue_flag_clear(QUEUE_FLAG_RQ_ALLOC_TIME, ioc->rqos.q);
 		ioc->enabled = false;
 	}
 
@@ -3344,12 +3345,10 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
 	if (IS_ERR(bdev))
 		return PTR_ERR(bdev);
 
-	rqos = rq_qos_get(bdev_get_queue(bdev), RQ_QOS_COST);
+	rqos = rq_qos_get(bdev_get_queue(bdev), ioc_rqos_ops.id);
 	if (!ioc) {
-		ret = blk_iocost_init(bdev_get_queue(bdev));
-		if (ret)
-			goto err;
-		rqos = rq_qos_get(bdev_get_queue(bdev), RQ_QOS_COST);
+		ret = -EOPNOTSUPP;
+		goto err;
 	}
 
 	ioc = rqos_to_ioc(rqos);
@@ -3449,13 +3448,27 @@ static struct blkcg_policy blkcg_policy_iocost = {
 
 static int __init ioc_init(void)
 {
-	return blkcg_policy_register(&blkcg_policy_iocost);
+	int ret;
+
+	ret = rq_qos_register(&ioc_rqos_ops);
+	if (ret)
+		return ret;
+
+	ret = blkcg_policy_register(&blkcg_policy_iocost);
+	if (ret)
+		rq_qos_unregister(&ioc_rqos_ops);
+
+	return ret;
 }
 
 static void __exit ioc_exit(void)
 {
 	blkcg_policy_unregister(&blkcg_policy_iocost);
+	rq_qos_unregister(&ioc_rqos_ops);
 }
 
 module_init(ioc_init);
 module_exit(ioc_exit);
+MODULE_AUTHOR("Tejun Heo");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Cost model based cgroup IO controller");
diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 57c33f4730f2..14fda9a5e552 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -820,8 +820,6 @@ void blk_mq_debugfs_unregister_sched(struct request_queue *q)
 static const char *rq_qos_id_to_name(enum rq_qos_id id)
 {
 	switch (id) {
-	case RQ_QOS_COST:
-		return "cost";
 	case RQ_QOS_IOPRIO:
 		return "ioprio";
 	}
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 6ca46c69e325..4eef53f2c290 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -14,7 +14,6 @@
 struct blk_mq_debugfs_attr;
 
 enum rq_qos_id {
-	RQ_QOS_COST,
 	RQ_QOS_IOPRIO,
 };
 
-- 
2.17.1


  parent reply	other threads:[~2022-01-10  9:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10  9:10 [PATCH 0/13] blk: make blk-rq-qos policies " Wang Jianchao
2022-01-10  9:10 ` [PATCH 01/13] blk: make blk-rq-qos support pluggable and modular policy Wang Jianchao
2022-01-13  1:49   ` kernel test robot
2022-01-13  3:52     ` Wang Jianchao
2022-01-10  9:10 ` [PATCH 02/13] blk-wbt: make wbt pluggable Wang Jianchao
2022-01-10  9:10 ` [PATCH 03/13] blk: export following interfaces Wang Jianchao
2022-01-10  9:10 ` [PATCH 04/13] cgroup: export following two interfaces Wang Jianchao
2022-01-10  9:10 ` [PATCH 05/13] blk-iolatency: make iolatency pluggable and modular Wang Jianchao
2022-01-10  9:10 ` [PATCH 06/13] blk: remove unused BLK_RQ_IO_DATA_LEN Wang Jianchao
2022-01-10  9:10 ` [PATCH 07/13] blk: use standalone macro to control bio.bi_iocost_cost Wang Jianchao
2022-01-10  9:10 ` Wang Jianchao [this message]
2022-01-10  9:10 ` [PATCH 09/13] blk: rename ioprio.c to ioprio-common.c Wang Jianchao
2022-01-10  9:10 ` [PATCH 10/13] blk-ioprio: make ioprio pluggable and modular Wang Jianchao
2022-01-10  9:10 ` [PATCH 11/13] blk: remove unused interfaces of blk-rq-qos Wang Jianchao
2022-01-10  9:10 ` [PATCH 12/13] blk: make request able to carry blkcg_gq Wang Jianchao
2022-01-10  9:10 ` [PATCH 13/13] blk: introduce iostat per cgroup module Wang Jianchao
2022-01-12 20:13   ` Tejun Heo
2022-01-13  2:40     ` Wang Jianchao
2022-01-13 17:01       ` Tejun Heo
2022-01-14  2:01         ` Wang Jianchao
2022-01-10 17:36 ` [PATCH 0/13] blk: make blk-rq-qos policies pluggable and modular Christoph Hellwig
2022-01-11  1:53   ` Wang Jianchao
2022-01-11  3:25   ` Bart Van Assche

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=20220110091046.17010-9-jianchao.wan9@gmail.com \
    --to=jianchao.wan9@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=jbacik@fb.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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

Powered by JetHome