Skip to content

Commit fd41e60

Browse files
htejunaxboe
authored andcommitted
bfq-iosched: stop using blkg->stat_bytes and ->stat_ios
When used on cgroup1, bfq uses the blkg->stat_bytes and ->stat_ios from blk-cgroup core to populate six 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 it out to dedicated rwstat counters which are updated when on cgroup1. This makes use of bfqg_*rwstat*() helpers outside of CONFIG_BFQ_CGROUP_DEBUG. Move them out. v2: Compile fix when !CONFIG_BFQ_CGROUP_DEBUG. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Paolo Valente <paolo.valente@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a557f1c commit fd41e60

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

‎block/bfq-cgroup.c‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ void bfqg_and_blkg_put(struct bfq_group *bfqg)
347347
bfqg_put(bfqg);
348348
}
349349

350+
void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq)
351+
{
352+
struct bfq_group *bfqg = blkg_to_bfqg(rq->bio->bi_blkg);
353+
354+
blkg_rwstat_add(&bfqg->stats.bytes, rq->cmd_flags, blk_rq_bytes(rq));
355+
blkg_rwstat_add(&bfqg->stats.ios, rq->cmd_flags, 1);
356+
}
357+
350358
/* @stats = 0 */
351359
static void bfqg_stats_reset(struct bfqg_stats *stats)
352360
{
@@ -431,6 +439,8 @@ void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
431439

432440
static void bfqg_stats_exit(struct bfqg_stats *stats)
433441
{
442+
blkg_rwstat_exit(&stats->bytes);
443+
blkg_rwstat_exit(&stats->ios);
434444
#ifdef CONFIG_BFQ_CGROUP_DEBUG
435445
blkg_rwstat_exit(&stats->merged);
436446
blkg_rwstat_exit(&stats->service_time);
@@ -448,6 +458,10 @@ static void bfqg_stats_exit(struct bfqg_stats *stats)
448458

449459
static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
450460
{
461+
if (blkg_rwstat_init(&stats->bytes, gfp) ||
462+
blkg_rwstat_init(&stats->ios, gfp))
463+
return -ENOMEM;
464+
451465
#ifdef CONFIG_BFQ_CGROUP_DEBUG
452466
if (blkg_rwstat_init(&stats->merged, gfp) ||
453467
blkg_rwstat_init(&stats->service_time, gfp) ||
@@ -1057,7 +1071,6 @@ static ssize_t bfq_io_set_weight(struct kernfs_open_file *of,
10571071
return bfq_io_set_device_weight(of, buf, nbytes, off);
10581072
}
10591073

1060-
#ifdef CONFIG_BFQ_CGROUP_DEBUG
10611074
static int bfqg_print_rwstat(struct seq_file *sf, void *v)
10621075
{
10631076
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_rwstat,
@@ -1082,6 +1095,7 @@ static int bfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
10821095
return 0;
10831096
}
10841097

1098+
#ifdef CONFIG_BFQ_CGROUP_DEBUG
10851099
static int bfqg_print_stat(struct seq_file *sf, void *v)
10861100
{
10871101
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_stat,
@@ -1125,7 +1139,8 @@ static int bfqg_print_stat_recursive(struct seq_file *sf, void *v)
11251139
static u64 bfqg_prfill_sectors(struct seq_file *sf, struct blkg_policy_data *pd,
11261140
int off)
11271141
{
1128-
u64 sum = blkg_rwstat_total(&pd->blkg->stat_bytes);
1142+
struct bfq_group *bfqg = blkg_to_bfqg(pd->blkg);
1143+
u64 sum = blkg_rwstat_total(&bfqg->stats.bytes);
11291144

11301145
return __blkg_prfill_u64(sf, pd, sum >> 9);
11311146
}
@@ -1142,8 +1157,8 @@ static u64 bfqg_prfill_sectors_recursive(struct seq_file *sf,
11421157
{
11431158
struct blkg_rwstat_sample tmp;
11441159

1145-
blkg_rwstat_recursive_sum(pd->blkg, NULL,
1146-
offsetof(struct blkcg_gq, stat_bytes), &tmp);
1160+
blkg_rwstat_recursive_sum(pd->blkg, &blkcg_policy_bfq,
1161+
offsetof(struct bfq_group, stats.bytes), &tmp);
11471162

11481163
return __blkg_prfill_u64(sf, pd,
11491164
(tmp.cnt[BLKG_RWSTAT_READ] + tmp.cnt[BLKG_RWSTAT_WRITE]) >> 9);
@@ -1226,13 +1241,13 @@ struct cftype bfq_blkcg_legacy_files[] = {
12261241
/* statistics, covers only the tasks in the bfqg */
12271242
{
12281243
.name = "bfq.io_service_bytes",
1229-
.private = (unsigned long)&blkcg_policy_bfq,
1230-
.seq_show = blkg_print_stat_bytes,
1244+
.private = offsetof(struct bfq_group, stats.bytes),
1245+
.seq_show = bfqg_print_rwstat,
12311246
},
12321247
{
12331248
.name = "bfq.io_serviced",
1234-
.private = (unsigned long)&blkcg_policy_bfq,
1235-
.seq_show = blkg_print_stat_ios,
1249+
.private = offsetof(struct bfq_group, stats.ios),
1250+
.seq_show = bfqg_print_rwstat,
12361251
},
12371252
#ifdef CONFIG_BFQ_CGROUP_DEBUG
12381253
{
@@ -1269,13 +1284,13 @@ struct cftype bfq_blkcg_legacy_files[] = {
12691284
/* the same statistics which cover the bfqg and its descendants */
12701285
{
12711286
.name = "bfq.io_service_bytes_recursive",
1272-
.private = (unsigned long)&blkcg_policy_bfq,
1273-
.seq_show = blkg_print_stat_bytes_recursive,
1287+
.private = offsetof(struct bfq_group, stats.bytes),
1288+
.seq_show = bfqg_print_rwstat_recursive,
12741289
},
12751290
{
12761291
.name = "bfq.io_serviced_recursive",
1277-
.private = (unsigned long)&blkcg_policy_bfq,
1278-
.seq_show = blkg_print_stat_ios_recursive,
1292+
.private = offsetof(struct bfq_group, stats.ios),
1293+
.seq_show = bfqg_print_rwstat_recursive,
12791294
},
12801295
#ifdef CONFIG_BFQ_CGROUP_DEBUG
12811296
{

‎block/bfq-iosched.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,6 +5464,10 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
54645464
bool idle_timer_disabled = false;
54655465
unsigned int cmd_flags;
54665466

5467+
#ifdef CONFIG_BFQ_GROUP_IOSCHED
5468+
if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio)
5469+
bfqg_stats_update_legacy_io(q, rq);
5470+
#endif
54675471
spin_lock_irq(&bfqd->lock);
54685472
if (blk_mq_sched_try_insert_merge(q, rq)) {
54695473
spin_unlock_irq(&bfqd->lock);

‎block/bfq-iosched.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@ struct bfq_stat {
809809
};
810810

811811
struct bfqg_stats {
812+
/* basic stats */
813+
struct blkg_rwstat bytes;
814+
struct blkg_rwstat ios;
812815
#ifdef CONFIG_BFQ_CGROUP_DEBUG
813816
/* number of ios merged */
814817
struct blkg_rwstat merged;
@@ -956,6 +959,7 @@ void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
956959

957960
/* ---------------- cgroups-support interface ---------------- */
958961

962+
void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq);
959963
void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
960964
unsigned int op);
961965
void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op);

0 commit comments

Comments
 (0)