From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>,
Josef Bacik <josef@toxicpanda.com>
Cc: linux-block@vger.kernel.org, cgroups@vger.kernel.org,
Andreas Herrmann <aherrmann@suse.de>
Subject: [PATCH 15/15] blk-cgroup: move the cgroup information to struct gendisk
Date: Tue, 24 Jan 2023 07:57:15 +0100 [thread overview]
Message-ID: <20230124065716.152286-16-hch@lst.de> (raw)
In-Reply-To: <20230124065716.152286-1-hch@lst.de>
cgroup information only makes sense on a live gendisk that allows
file system I/O (which includes the raw block device). So move over
the cgroup related members.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Andreas Herrmann <aherrmann@suse.de>
---
block/bfq-cgroup.c | 4 ++--
block/blk-cgroup.c | 48 +++++++++++++++++++++---------------------
block/blk-cgroup.h | 2 +-
block/blk-iolatency.c | 2 +-
block/blk-throttle.c | 16 ++++++++------
include/linux/blkdev.h | 10 ++++-----
6 files changed, 43 insertions(+), 39 deletions(-)
diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
index 055f9684c1c502..c13ba851c5221a 100644
--- a/block/bfq-cgroup.c
+++ b/block/bfq-cgroup.c
@@ -1003,7 +1003,7 @@ void bfq_end_wr_async(struct bfq_data *bfqd)
{
struct blkcg_gq *blkg;
- list_for_each_entry(blkg, &bfqd->queue->blkg_list, q_node) {
+ list_for_each_entry(blkg, &bfqd->queue->disk->blkg_list, q_node) {
struct bfq_group *bfqg = blkg_to_bfqg(blkg);
bfq_end_wr_async_queues(bfqd, bfqg);
@@ -1297,7 +1297,7 @@ struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
if (ret)
return NULL;
- return blkg_to_bfqg(bfqd->queue->root_blkg);
+ return blkg_to_bfqg(bfqd->queue->disk->root_blkg);
}
struct blkcg_policy blkcg_policy_bfq = {
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index b9883ea81ad0da..6a0aa51668db62 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -108,10 +108,10 @@ static struct cgroup_subsys_state *blkcg_css(void)
return task_css(current, io_cgrp_id);
}
-static bool blkcg_policy_enabled(struct request_queue *q,
+static bool blkcg_policy_enabled(struct gendisk *disk,
const struct blkcg_policy *pol)
{
- return pol && test_bit(pol->plid, q->blkcg_pols);
+ return pol && test_bit(pol->plid, disk->blkcg_pols);
}
/**
@@ -264,7 +264,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
struct blkcg_policy *pol = blkcg_policy[i];
struct blkg_policy_data *pd;
- if (!blkcg_policy_enabled(disk->queue, pol))
+ if (!blkcg_policy_enabled(disk, pol))
continue;
/* alloc per-policy data and attach it to blkg */
@@ -341,7 +341,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
ret = radix_tree_insert(&blkcg->blkg_tree, disk->queue->id, blkg);
if (likely(!ret)) {
hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
- list_add(&blkg->q_node, &disk->queue->blkg_list);
+ list_add(&blkg->q_node, &disk->blkg_list);
for (i = 0; i < BLKCG_MAX_POLS; i++) {
struct blkcg_policy *pol = blkcg_policy[i];
@@ -410,7 +410,7 @@ static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
while (true) {
struct blkcg *pos = blkcg;
struct blkcg *parent = blkcg_parent(blkcg);
- struct blkcg_gq *ret_blkg = q->root_blkg;
+ struct blkcg_gq *ret_blkg = disk->root_blkg;
while (parent) {
blkg = blkg_lookup(parent, disk);
@@ -485,7 +485,7 @@ static void blkg_destroy_all(struct gendisk *disk)
restart:
spin_lock_irq(&q->queue_lock);
- list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
+ list_for_each_entry_safe(blkg, n, &disk->blkg_list, q_node) {
struct blkcg *blkcg = blkg->blkcg;
spin_lock(&blkcg->lock);
@@ -504,7 +504,7 @@ static void blkg_destroy_all(struct gendisk *disk)
}
}
- q->root_blkg = NULL;
+ disk->root_blkg = NULL;
spin_unlock_irq(&q->queue_lock);
}
@@ -579,7 +579,7 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
rcu_read_lock();
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
spin_lock_irq(&blkg->disk->queue->queue_lock);
- if (blkcg_policy_enabled(blkg->disk->queue, pol))
+ if (blkcg_policy_enabled(blkg->disk, pol))
total += prfill(sf, blkg->pd[pol->plid], data);
spin_unlock_irq(&blkg->disk->queue->queue_lock);
}
@@ -687,7 +687,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
rcu_read_lock();
spin_lock_irq(&q->queue_lock);
- if (!blkcg_policy_enabled(q, pol)) {
+ if (!blkcg_policy_enabled(disk, pol)) {
ret = -EOPNOTSUPP;
goto fail_unlock;
}
@@ -730,7 +730,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
rcu_read_lock();
spin_lock_irq(&q->queue_lock);
- if (!blkcg_policy_enabled(q, pol)) {
+ if (!blkcg_policy_enabled(disk, pol)) {
blkg_free(new_blkg);
ret = -EOPNOTSUPP;
goto fail_preloaded;
@@ -910,7 +910,7 @@ static void blkcg_fill_root_iostats(void)
class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
while ((dev = class_dev_iter_next(&iter))) {
struct block_device *bdev = dev_to_bdev(dev);
- struct blkcg_gq *blkg = bdev->bd_disk->queue->root_blkg;
+ struct blkcg_gq *blkg = bdev->bd_disk->root_blkg;
struct blkg_iostat tmp;
int cpu;
unsigned long flags;
@@ -1257,7 +1257,7 @@ int blkcg_init_disk(struct gendisk *disk)
bool preloaded;
int ret;
- INIT_LIST_HEAD(&q->blkg_list);
+ INIT_LIST_HEAD(&disk->blkg_list);
new_blkg = blkg_alloc(&blkcg_root, disk, GFP_KERNEL);
if (!new_blkg)
@@ -1271,7 +1271,7 @@ int blkcg_init_disk(struct gendisk *disk)
blkg = blkg_create(&blkcg_root, disk, new_blkg);
if (IS_ERR(blkg))
goto err_unlock;
- q->root_blkg = blkg;
+ disk->root_blkg = blkg;
spin_unlock_irq(&q->queue_lock);
if (preloaded)
@@ -1384,7 +1384,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
struct blkcg_gq *blkg, *pinned_blkg = NULL;
int ret;
- if (blkcg_policy_enabled(q, pol))
+ if (blkcg_policy_enabled(disk, pol))
return 0;
if (queue_is_mq(q))
@@ -1393,7 +1393,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
spin_lock_irq(&q->queue_lock);
/* blkg_list is pushed at the head, reverse walk to allocate parents first */
- list_for_each_entry_reverse(blkg, &q->blkg_list, q_node) {
+ list_for_each_entry_reverse(blkg, &disk->blkg_list, q_node) {
struct blkg_policy_data *pd;
if (blkg->pd[pol->plid])
@@ -1437,10 +1437,10 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
/* all allocated, init in the same order */
if (pol->pd_init_fn)
- list_for_each_entry_reverse(blkg, &q->blkg_list, q_node)
+ list_for_each_entry_reverse(blkg, &disk->blkg_list, q_node)
pol->pd_init_fn(blkg->pd[pol->plid]);
- __set_bit(pol->plid, q->blkcg_pols);
+ __set_bit(pol->plid, disk->blkcg_pols);
ret = 0;
spin_unlock_irq(&q->queue_lock);
@@ -1456,7 +1456,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
enomem:
/* alloc failed, nothing's initialized yet, free everything */
spin_lock_irq(&q->queue_lock);
- list_for_each_entry(blkg, &q->blkg_list, q_node) {
+ list_for_each_entry(blkg, &disk->blkg_list, q_node) {
struct blkcg *blkcg = blkg->blkcg;
spin_lock(&blkcg->lock);
@@ -1486,7 +1486,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,
struct request_queue *q = disk->queue;
struct blkcg_gq *blkg;
- if (!blkcg_policy_enabled(q, pol))
+ if (!blkcg_policy_enabled(disk, pol))
return;
if (queue_is_mq(q))
@@ -1494,9 +1494,9 @@ void blkcg_deactivate_policy(struct gendisk *disk,
spin_lock_irq(&q->queue_lock);
- __clear_bit(pol->plid, q->blkcg_pols);
+ __clear_bit(pol->plid, disk->blkcg_pols);
- list_for_each_entry(blkg, &q->blkg_list, q_node) {
+ list_for_each_entry(blkg, &disk->blkg_list, q_node) {
struct blkcg *blkcg = blkg->blkcg;
spin_lock(&blkcg->lock);
@@ -1909,7 +1909,7 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
* Associate @bio with the blkg found by combining the css's blkg and the
* request_queue of the @bio. An association failure is handled by walking up
* the blkg tree. Therefore, the blkg associated can be anything between @blkg
- * and q->root_blkg. This situation only happens when a cgroup is dying and
+ * and disk->root_blkg. This situation only happens when a cgroup is dying and
* then the remaining bios will spill to the closest alive blkg.
*
* A reference will be taken on the blkg and will be released when @bio is
@@ -1924,8 +1924,8 @@ void bio_associate_blkg_from_css(struct bio *bio,
if (css && css->parent) {
bio->bi_blkg = blkg_tryget_closest(bio, css);
} else {
- blkg_get(bdev_get_queue(bio->bi_bdev)->root_blkg);
- bio->bi_blkg = bdev_get_queue(bio->bi_bdev)->root_blkg;
+ blkg_get(bio->bi_bdev->bd_disk->root_blkg);
+ bio->bi_blkg = bio->bi_bdev->bd_disk->root_blkg;
}
}
EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 3e7508907f33d8..81eca9be7f9105 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -246,7 +246,7 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
WARN_ON_ONCE(!rcu_read_lock_held());
if (blkcg == &blkcg_root)
- return disk->queue->root_blkg;
+ return disk->root_blkg;
blkg = rcu_dereference(blkcg->blkg_hint);
if (blkg && blkg->disk == disk)
diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index bc0d217f5c1723..5d5aa1e526b742 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -665,7 +665,7 @@ static void blkiolatency_timer_fn(struct timer_list *t)
rcu_read_lock();
blkg_for_each_descendant_pre(blkg, pos_css,
- blkiolat->rqos.disk->queue->root_blkg) {
+ blkiolat->rqos.disk->root_blkg) {
struct iolatency_grp *iolat;
struct child_latency_info *lat_info;
unsigned long flags;
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 74bb1e753ea09d..902203bdddb4b4 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -451,7 +451,8 @@ static void blk_throtl_update_limit_valid(struct throtl_data *td)
bool low_valid = false;
rcu_read_lock();
- blkg_for_each_descendant_post(blkg, pos_css, td->queue->root_blkg) {
+ blkg_for_each_descendant_post(blkg, pos_css,
+ td->queue->disk->root_blkg) {
struct throtl_grp *tg = blkg_to_tg(blkg);
if (tg->bps[READ][LIMIT_LOW] || tg->bps[WRITE][LIMIT_LOW] ||
@@ -1180,7 +1181,7 @@ static void throtl_pending_timer_fn(struct timer_list *t)
spin_lock_irq(&q->queue_lock);
- if (!q->root_blkg)
+ if (!q->disk->root_blkg)
goto out_unlock;
if (throtl_can_upgrade(td, NULL))
@@ -1322,7 +1323,8 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
* blk-throttle.
*/
blkg_for_each_descendant_pre(blkg, pos_css,
- global ? tg->td->queue->root_blkg : tg_to_blkg(tg)) {
+ global ? tg->td->queue->disk->root_blkg :
+ tg_to_blkg(tg)) {
struct throtl_grp *this_tg = blkg_to_tg(blkg);
struct throtl_grp *parent_tg;
@@ -1717,7 +1719,7 @@ void blk_throtl_cancel_bios(struct gendisk *disk)
* path need RCU protection and to prevent warning from lockdep.
*/
rcu_read_lock();
- blkg_for_each_descendant_post(blkg, pos_css, q->root_blkg) {
+ blkg_for_each_descendant_post(blkg, pos_css, disk->root_blkg) {
struct throtl_grp *tg = blkg_to_tg(blkg);
struct throtl_service_queue *sq = &tg->service_queue;
@@ -1871,7 +1873,8 @@ static bool throtl_can_upgrade(struct throtl_data *td,
return false;
rcu_read_lock();
- blkg_for_each_descendant_post(blkg, pos_css, td->queue->root_blkg) {
+ blkg_for_each_descendant_post(blkg, pos_css,
+ td->queue->disk->root_blkg) {
struct throtl_grp *tg = blkg_to_tg(blkg);
if (tg == this_tg)
@@ -1917,7 +1920,8 @@ static void throtl_upgrade_state(struct throtl_data *td)
td->low_upgrade_time = jiffies;
td->scale = 0;
rcu_read_lock();
- blkg_for_each_descendant_post(blkg, pos_css, td->queue->root_blkg) {
+ blkg_for_each_descendant_post(blkg, pos_css,
+ td->queue->disk->root_blkg) {
struct throtl_grp *tg = blkg_to_tg(blkg);
struct throtl_service_queue *sq = &tg->service_queue;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 89f51d68c68ad6..8d16e3da0d5c68 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -163,6 +163,11 @@ struct gendisk {
struct timer_rand_state *random;
atomic_t sync_io; /* RAID */
struct disk_events *ev;
+#ifdef CONFIG_BLK_CGROUP
+ DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
+ struct blkcg_gq *root_blkg;
+ struct list_head blkg_list;
+#endif
#ifdef CONFIG_BLK_DEV_INTEGRITY
struct kobject integrity_kobj;
#endif /* CONFIG_BLK_DEV_INTEGRITY */
@@ -481,11 +486,6 @@ struct request_queue {
struct blk_mq_tags *sched_shared_tags;
struct list_head icq_list;
-#ifdef CONFIG_BLK_CGROUP
- DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
- struct blkcg_gq *root_blkg;
- struct list_head blkg_list;
-#endif
struct queue_limits limits;
--
2.39.0
next prev parent reply other threads:[~2023-01-24 6:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 6:57 switch blk-cgroup to work on gendisk v2 Christoph Hellwig
2023-01-24 6:57 ` [PATCH 01/15] blk-cgroup: don't defer blkg_free to a workqueue Christoph Hellwig
2023-01-27 22:33 ` Tejun Heo
2023-01-28 15:12 ` Ming Lei
2023-01-30 18:01 ` Tejun Heo
2023-01-29 6:09 ` Yu Kuai
2023-01-24 6:57 ` [PATCH 02/15] block: don't call blk_throtl_stat_add for non-READ/WRITE commands Christoph Hellwig
2023-01-24 6:57 ` [PATCH 03/15] blk-cgroup: delay blk-cgroup initialization until add_disk Christoph Hellwig
2023-01-27 22:59 ` Tejun Heo
2023-01-24 6:57 ` [PATCH 04/15] blk-cgroup: pin the gendisk in struct blkcg_gq Christoph Hellwig
2023-01-27 23:15 ` Tejun Heo
2023-01-24 6:57 ` [PATCH 05/15] blk-cgroup: store a gendisk to throttle in struct task_struct Christoph Hellwig
2023-01-27 23:40 ` Tejun Heo
2023-02-01 8:06 ` Christoph Hellwig
2023-02-02 17:57 ` Tejun Heo
2023-01-24 6:57 ` [PATCH 06/15] blk-wbt: pass a gendisk to wbt_{enable,disable}_default Christoph Hellwig
2023-01-24 6:57 ` [PATCH 07/15] blk-wbt: pass a gendisk to wbt_init Christoph Hellwig
2023-01-24 6:57 ` [PATCH 08/15] blk-wbt: open code wbt_queue_depth_changed in wbt_update_limits Christoph Hellwig
2023-01-27 23:56 ` Tejun Heo
2023-01-24 6:57 ` [PATCH 09/15] blk-rq-qos: make rq_qos_add and rq_qos_del more useful Christoph Hellwig
2023-01-28 0:01 ` Tejun Heo
2023-01-24 6:57 ` [PATCH 10/15] blk-rq-qos: constify rq_qos_ops Christoph Hellwig
2023-01-24 6:57 ` [PATCH 11/15] blk-rq-qos: store a gendisk instead of request_queue in struct rq_qos Christoph Hellwig
2023-01-24 6:57 ` [PATCH 12/15] blk-cgroup: pass a gendisk to blkcg_{de,}activate_policy Christoph Hellwig
2023-01-24 6:57 ` [PATCH 13/15] blk-cgroup: pass a gendisk to pd_alloc_fn Christoph Hellwig
2023-01-24 6:57 ` [PATCH 14/15] blk-cgroup: pass a gendisk to blkg_lookup Christoph Hellwig
2023-01-24 6:57 ` Christoph Hellwig [this message]
2023-01-28 0:13 ` [PATCH 15/15] blk-cgroup: move the cgroup information to struct gendisk Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2023-01-17 8:12 switch blk-cgroup to work on gendisk Christoph Hellwig
2023-01-17 8:12 ` [PATCH 15/15] blk-cgroup: move the cgroup information to struct gendisk Christoph Hellwig
2023-01-20 11:07 ` Andreas Herrmann
2023-01-27 7:12 ` Hannes Reinecke
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=20230124065716.152286-16-hch@lst.de \
--to=hch@lst.de \
--cc=aherrmann@suse.de \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-block@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