Skip to content

Commit 84d7d46

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-cgroup: pin the gendisk in struct blkcg_gq
Currently each blkcg_gq holds a request_queue reference, which is what is used in the policies. But a lot of these interfaces will move over to use a gendisk, so store a disk in struct blkcg_gq and hold a reference to it. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Andreas Herrmann <aherrmann@suse.de> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20230203150400.3199230-7-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 180b04d commit 84d7d46

7 files changed

Lines changed: 31 additions & 33 deletions

File tree

block/bfq-cgroup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static void bfqg_stats_xfer_dead(struct bfq_group *bfqg)
405405

406406
parent = bfqg_parent(bfqg);
407407

408-
lockdep_assert_held(&bfqg_to_blkg(bfqg)->q->queue_lock);
408+
lockdep_assert_held(&bfqg_to_blkg(bfqg)->disk->queue->queue_lock);
409409

410410
if (unlikely(!parent))
411411
return;
@@ -536,7 +536,7 @@ static void bfq_pd_init(struct blkg_policy_data *pd)
536536
{
537537
struct blkcg_gq *blkg = pd_to_blkg(pd);
538538
struct bfq_group *bfqg = blkg_to_bfqg(blkg);
539-
struct bfq_data *bfqd = blkg->q->elevator->elevator_data;
539+
struct bfq_data *bfqd = blkg->disk->queue->elevator->elevator_data;
540540
struct bfq_entity *entity = &bfqg->entity;
541541
struct bfq_group_data *d = blkcg_to_bfqgd(blkg->blkcg);
542542

@@ -1201,7 +1201,7 @@ static u64 bfqg_prfill_stat_recursive(struct seq_file *sf,
12011201
struct cgroup_subsys_state *pos_css;
12021202
u64 sum = 0;
12031203

1204-
lockdep_assert_held(&blkg->q->queue_lock);
1204+
lockdep_assert_held(&blkg->disk->queue->queue_lock);
12051205

12061206
rcu_read_lock();
12071207
blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {

block/blk-cgroup-rwstat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void blkg_rwstat_recursive_sum(struct blkcg_gq *blkg, struct blkcg_policy *pol,
107107
struct cgroup_subsys_state *pos_css;
108108
unsigned int i;
109109

110-
lockdep_assert_held(&blkg->q->queue_lock);
110+
lockdep_assert_held(&blkg->disk->queue->queue_lock);
111111

112112
memset(sum, 0, sizeof(*sum));
113113
rcu_read_lock();

block/blk-cgroup.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ static bool blkcg_policy_enabled(struct request_queue *q,
116116

117117
static void blkg_free(struct blkcg_gq *blkg)
118118
{
119-
struct request_queue *q = blkg->q;
120119
int i;
121120

122121
/*
@@ -126,16 +125,16 @@ static void blkg_free(struct blkcg_gq *blkg)
126125
* blkcg_mutex is used to synchronize blkg_free_workfn() and
127126
* blkcg_deactivate_policy().
128127
*/
129-
mutex_lock(&q->blkcg_mutex);
128+
mutex_lock(&blkg->disk->queue->blkcg_mutex);
130129
for (i = 0; i < BLKCG_MAX_POLS; i++)
131130
if (blkg->pd[i])
132131
blkcg_policy[i]->pd_free_fn(blkg->pd[i]);
133132
if (blkg->parent)
134133
blkg_put(blkg->parent);
135134
list_del_init(&blkg->q_node);
136-
mutex_unlock(&q->blkcg_mutex);
135+
mutex_unlock(&blkg->disk->queue->blkcg_mutex);
137136

138-
blk_put_queue(q);
137+
put_disk(blkg->disk);
139138
free_percpu(blkg->iostat_cpu);
140139
percpu_ref_exit(&blkg->refcnt);
141140
kfree(blkg);
@@ -251,10 +250,12 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
251250
blkg->iostat_cpu = alloc_percpu_gfp(struct blkg_iostat_set, gfp_mask);
252251
if (!blkg->iostat_cpu)
253252
goto out_exit_refcnt;
254-
if (!blk_get_queue(disk->queue))
253+
254+
if (test_bit(GD_DEAD, &disk->state))
255255
goto out_free_iostat;
256+
get_device(disk_to_dev(disk));
257+
blkg->disk = disk;
256258

257-
blkg->q = disk->queue;
258259
INIT_LIST_HEAD(&blkg->q_node);
259260
spin_lock_init(&blkg->async_bio_lock);
260261
bio_list_init(&blkg->async_bios);
@@ -290,7 +291,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
290291
while (--i >= 0)
291292
if (blkg->pd[i])
292293
blkcg_policy[i]->pd_free_fn(blkg->pd[i]);
293-
blk_put_queue(disk->queue);
294+
put_disk(blkg->disk);
294295
out_free_iostat:
295296
free_percpu(blkg->iostat_cpu);
296297
out_exit_refcnt:
@@ -461,7 +462,7 @@ static void blkg_destroy(struct blkcg_gq *blkg)
461462
struct blkcg *blkcg = blkg->blkcg;
462463
int i;
463464

464-
lockdep_assert_held(&blkg->q->queue_lock);
465+
lockdep_assert_held(&blkg->disk->queue->queue_lock);
465466
lockdep_assert_held(&blkcg->lock);
466467

467468
/*
@@ -485,7 +486,7 @@ static void blkg_destroy(struct blkcg_gq *blkg)
485486

486487
blkg->online = false;
487488

488-
radix_tree_delete(&blkcg->blkg_tree, blkg->q->id);
489+
radix_tree_delete(&blkcg->blkg_tree, blkg->disk->queue->id);
489490
hlist_del_init_rcu(&blkg->blkcg_node);
490491

491492
/*
@@ -572,9 +573,7 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
572573

573574
const char *blkg_dev_name(struct blkcg_gq *blkg)
574575
{
575-
if (!blkg->q->disk)
576-
return NULL;
577-
return bdi_dev_name(blkg->q->disk->bdi);
576+
return bdi_dev_name(blkg->disk->bdi);
578577
}
579578

580579
/**
@@ -606,10 +605,10 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
606605

607606
rcu_read_lock();
608607
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
609-
spin_lock_irq(&blkg->q->queue_lock);
610-
if (blkcg_policy_enabled(blkg->q, pol))
608+
spin_lock_irq(&blkg->disk->queue->queue_lock);
609+
if (blkcg_policy_enabled(blkg->disk->queue, pol))
611610
total += prfill(sf, blkg->pd[pol->plid], data);
612-
spin_unlock_irq(&blkg->q->queue_lock);
611+
spin_unlock_irq(&blkg->disk->queue->queue_lock);
613612
}
614613
rcu_read_unlock();
615614

@@ -1033,9 +1032,9 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
10331032

10341033
rcu_read_lock();
10351034
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
1036-
spin_lock_irq(&blkg->q->queue_lock);
1035+
spin_lock_irq(&blkg->disk->queue->queue_lock);
10371036
blkcg_print_one_stat(blkg, sf);
1038-
spin_unlock_irq(&blkg->q->queue_lock);
1037+
spin_unlock_irq(&blkg->disk->queue->queue_lock);
10391038
}
10401039
rcu_read_unlock();
10411040
return 0;
@@ -1105,7 +1104,7 @@ static void blkcg_destroy_blkgs(struct blkcg *blkcg)
11051104
while (!hlist_empty(&blkcg->blkg_list)) {
11061105
struct blkcg_gq *blkg = hlist_entry(blkcg->blkg_list.first,
11071106
struct blkcg_gq, blkcg_node);
1108-
struct request_queue *q = blkg->q;
1107+
struct request_queue *q = blkg->disk->queue;
11091108

11101109
if (need_resched() || !spin_trylock(&q->queue_lock)) {
11111110
/*

block/blk-cgroup.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ struct blkg_iostat_set {
5353

5454
/* association between a blk cgroup and a request queue */
5555
struct blkcg_gq {
56-
/* Pointer to the associated request_queue */
57-
struct request_queue *q;
56+
struct gendisk *disk;
5857
struct list_head q_node;
5958
struct hlist_node blkcg_node;
6059
struct blkcg *blkcg;
@@ -255,11 +254,11 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
255254
return q->root_blkg;
256255

257256
blkg = rcu_dereference(blkcg->blkg_hint);
258-
if (blkg && blkg->q == q)
257+
if (blkg && blkg->disk->queue == q)
259258
return blkg;
260259

261260
blkg = radix_tree_lookup(&blkcg->blkg_tree, q->id);
262-
if (blkg && blkg->q != q)
261+
if (blkg && blkg->disk->queue != q)
263262
blkg = NULL;
264263
return blkg;
265264
}
@@ -359,7 +358,7 @@ static inline void blkg_put(struct blkcg_gq *blkg)
359358
#define blkg_for_each_descendant_pre(d_blkg, pos_css, p_blkg) \
360359
css_for_each_descendant_pre((pos_css), &(p_blkg)->blkcg->css) \
361360
if (((d_blkg) = blkg_lookup(css_to_blkcg(pos_css), \
362-
(p_blkg)->q)))
361+
(p_blkg)->disk->queue)))
363362

364363
/**
365364
* blkg_for_each_descendant_post - post-order walk of a blkg's descendants
@@ -374,7 +373,7 @@ static inline void blkg_put(struct blkcg_gq *blkg)
374373
#define blkg_for_each_descendant_post(d_blkg, pos_css, p_blkg) \
375374
css_for_each_descendant_post((pos_css), &(p_blkg)->blkcg->css) \
376375
if (((d_blkg) = blkg_lookup(css_to_blkcg(pos_css), \
377-
(p_blkg)->q)))
376+
(p_blkg)->disk->queue)))
378377

379378
bool __blkcg_punt_bio_submit(struct bio *bio);
380379

block/blk-iocost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ static void ioc_pd_init(struct blkg_policy_data *pd)
29532953
{
29542954
struct ioc_gq *iocg = pd_to_iocg(pd);
29552955
struct blkcg_gq *blkg = pd_to_blkg(&iocg->pd);
2956-
struct ioc *ioc = q_to_ioc(blkg->q);
2956+
struct ioc *ioc = q_to_ioc(blkg->disk->queue);
29572957
struct ioc_now now;
29582958
struct blkcg_gq *tblkg;
29592959
unsigned long flags;

block/blk-iolatency.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,12 @@ static void iolatency_pd_init(struct blkg_policy_data *pd)
974974
{
975975
struct iolatency_grp *iolat = pd_to_lat(pd);
976976
struct blkcg_gq *blkg = lat_to_blkg(iolat);
977-
struct rq_qos *rqos = blkcg_rq_qos(blkg->q);
977+
struct rq_qos *rqos = blkcg_rq_qos(blkg->disk->queue);
978978
struct blk_iolatency *blkiolat = BLKIOLATENCY(rqos);
979979
u64 now = ktime_to_ns(ktime_get());
980980
int cpu;
981981

982-
if (blk_queue_nonrot(blkg->q))
982+
if (blk_queue_nonrot(blkg->disk->queue))
983983
iolat->ssd = true;
984984
else
985985
iolat->ssd = false;

block/blk-throttle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static void throtl_pd_init(struct blkg_policy_data *pd)
388388
{
389389
struct throtl_grp *tg = pd_to_tg(pd);
390390
struct blkcg_gq *blkg = tg_to_blkg(tg);
391-
struct throtl_data *td = blkg->q->td;
391+
struct throtl_data *td = blkg->disk->queue->td;
392392
struct throtl_service_queue *sq = &tg->service_queue;
393393

394394
/*
@@ -1175,7 +1175,7 @@ static void throtl_pending_timer_fn(struct timer_list *t)
11751175

11761176
/* throtl_data may be gone, so figure out request queue by blkg */
11771177
if (tg)
1178-
q = tg->pd.blkg->q;
1178+
q = tg->pd.blkg->disk->queue;
11791179
else
11801180
q = td->queue;
11811181

0 commit comments

Comments
 (0)