Skip to content

Commit 7ca4643

Browse files
htejunaxboe
authored andcommitted
blk-throtl: stop using blkg->stat_bytes and ->stat_ios
When used on cgroup1, blk-throtl uses the blkg->stat_bytes and ->stat_ios from blk-cgroup core to populate four stat knobs. blk-cgroup core is moving away from blkg_rwstat to improve scalability and won't be able to support this usage. It isn't like the sharing gains all that much. Let's break them out to dedicated rwstat counters which are updated when on cgroup1. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fd41e60 commit 7ca4643

1 file changed

Lines changed: 61 additions & 9 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ struct throtl_grp {
176176
unsigned int bio_cnt; /* total bios */
177177
unsigned int bad_bio_cnt; /* bios exceeding latency threshold */
178178
unsigned long bio_cnt_reset_time;
179+
180+
struct blkg_rwstat stat_bytes;
181+
struct blkg_rwstat stat_ios;
179182
};
180183

181184
/* We measure latency for request size from <= 4k to >= 1M */
@@ -489,6 +492,12 @@ static struct blkg_policy_data *throtl_pd_alloc(gfp_t gfp,
489492
if (!tg)
490493
return NULL;
491494

495+
if (blkg_rwstat_init(&tg->stat_bytes, gfp))
496+
goto err_free_tg;
497+
498+
if (blkg_rwstat_init(&tg->stat_ios, gfp))
499+
goto err_exit_stat_bytes;
500+
492501
throtl_service_queue_init(&tg->service_queue);
493502

494503
for (rw = READ; rw <= WRITE; rw++) {
@@ -513,6 +522,12 @@ static struct blkg_policy_data *throtl_pd_alloc(gfp_t gfp,
513522
tg->idletime_threshold_conf = DFL_IDLE_THRESHOLD;
514523

515524
return &tg->pd;
525+
526+
err_exit_stat_bytes:
527+
blkg_rwstat_exit(&tg->stat_bytes);
528+
err_free_tg:
529+
kfree(tg);
530+
return NULL;
516531
}
517532

518533
static void throtl_pd_init(struct blkg_policy_data *pd)
@@ -611,6 +626,8 @@ static void throtl_pd_free(struct blkg_policy_data *pd)
611626
struct throtl_grp *tg = pd_to_tg(pd);
612627

613628
del_timer_sync(&tg->service_queue.pending_timer);
629+
blkg_rwstat_exit(&tg->stat_bytes);
630+
blkg_rwstat_exit(&tg->stat_ios);
614631
kfree(tg);
615632
}
616633

@@ -1464,6 +1481,32 @@ static ssize_t tg_set_conf_uint(struct kernfs_open_file *of,
14641481
return tg_set_conf(of, buf, nbytes, off, false);
14651482
}
14661483

1484+
static int tg_print_rwstat(struct seq_file *sf, void *v)
1485+
{
1486+
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
1487+
blkg_prfill_rwstat, &blkcg_policy_throtl,
1488+
seq_cft(sf)->private, true);
1489+
return 0;
1490+
}
1491+
1492+
static u64 tg_prfill_rwstat_recursive(struct seq_file *sf,
1493+
struct blkg_policy_data *pd, int off)
1494+
{
1495+
struct blkg_rwstat_sample sum;
1496+
1497+
blkg_rwstat_recursive_sum(pd_to_blkg(pd), &blkcg_policy_throtl, off,
1498+
&sum);
1499+
return __blkg_prfill_rwstat(sf, pd, &sum);
1500+
}
1501+
1502+
static int tg_print_rwstat_recursive(struct seq_file *sf, void *v)
1503+
{
1504+
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
1505+
tg_prfill_rwstat_recursive, &blkcg_policy_throtl,
1506+
seq_cft(sf)->private, true);
1507+
return 0;
1508+
}
1509+
14671510
static struct cftype throtl_legacy_files[] = {
14681511
{
14691512
.name = "throttle.read_bps_device",
@@ -1491,23 +1534,23 @@ static struct cftype throtl_legacy_files[] = {
14911534
},
14921535
{
14931536
.name = "throttle.io_service_bytes",
1494-
.private = (unsigned long)&blkcg_policy_throtl,
1495-
.seq_show = blkg_print_stat_bytes,
1537+
.private = offsetof(struct throtl_grp, stat_bytes),
1538+
.seq_show = tg_print_rwstat,
14961539
},
14971540
{
14981541
.name = "throttle.io_service_bytes_recursive",
1499-
.private = (unsigned long)&blkcg_policy_throtl,
1500-
.seq_show = blkg_print_stat_bytes_recursive,
1542+
.private = offsetof(struct throtl_grp, stat_bytes),
1543+
.seq_show = tg_print_rwstat_recursive,
15011544
},
15021545
{
15031546
.name = "throttle.io_serviced",
1504-
.private = (unsigned long)&blkcg_policy_throtl,
1505-
.seq_show = blkg_print_stat_ios,
1547+
.private = offsetof(struct throtl_grp, stat_ios),
1548+
.seq_show = tg_print_rwstat,
15061549
},
15071550
{
15081551
.name = "throttle.io_serviced_recursive",
1509-
.private = (unsigned long)&blkcg_policy_throtl,
1510-
.seq_show = blkg_print_stat_ios_recursive,
1552+
.private = offsetof(struct throtl_grp, stat_ios),
1553+
.seq_show = tg_print_rwstat_recursive,
15111554
},
15121555
{ } /* terminate */
15131556
};
@@ -2127,7 +2170,16 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
21272170
WARN_ON_ONCE(!rcu_read_lock_held());
21282171

21292172
/* see throtl_charge_bio() */
2130-
if (bio_flagged(bio, BIO_THROTTLED) || !tg->has_rules[rw])
2173+
if (bio_flagged(bio, BIO_THROTTLED))
2174+
goto out;
2175+
2176+
if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) {
2177+
blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf,
2178+
bio->bi_iter.bi_size);
2179+
blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1);
2180+
}
2181+
2182+
if (!tg->has_rules[rw])
21312183
goto out;
21322184

21332185
spin_lock_irq(&q->queue_lock);

0 commit comments

Comments
 (0)