Skip to content

Commit 69d7fde

Browse files
htejunaxboe
authored andcommitted
blkcg: use CGROUP_WEIGHT_* scale for io.weight on the unified hierarchy
cgroup is trying to make interface consistent across different controllers. For weight based resource control, the knob should have the range [1, 10000] and default to 100. This patch updates cfq-iosched so that the weight range conforms. The internal calculations have enough range and the widening of the weight range shouldn't cause any problem. * blkcg_policy->cpd_bind_fn() is added. If present, this is invoked when blkcg is attached to a hierarchy. * cfq_cpd_init() is updated to use the new default value on the unified hierarchy. * cfq_cpd_bind() callback is implemented to clear per-blkg configs and apply the default config matching the hierarchy type. * cfqd->root_group->[leaf_]weight initialization in cfq_init_queue() is moved into !CONFIG_CFQ_GROUP_IOSCHED block. cfq_cpd_bind() is now responsible for initializing the initial weights when blkcg is enabled. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Arianna Avanzini <avanzini.arianna@gmail.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 3ecca62 commit 69d7fde

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

Documentation/cgroups/unified-hierarchy.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ may be specified in any order and not all pairs have to be specified.
464464

465465
The weight setting, currently only available and effective if
466466
cfq-iosched is in use for the target device. The weight is
467-
between 10 and 1000 and defaults to 500. The first line
467+
between 1 and 10000 and defaults to 100. The first line
468468
always contains the default weight in the following format to
469469
use when per-device setting is missing.
470470

block/blk-cgroup.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,11 +1143,32 @@ static int blkcg_can_attach(struct cgroup_subsys_state *css,
11431143
return ret;
11441144
}
11451145

1146+
static void blkcg_bind(struct cgroup_subsys_state *root_css)
1147+
{
1148+
int i;
1149+
1150+
mutex_lock(&blkcg_pol_mutex);
1151+
1152+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
1153+
struct blkcg_policy *pol = blkcg_policy[i];
1154+
struct blkcg *blkcg;
1155+
1156+
if (!pol || !pol->cpd_bind_fn)
1157+
continue;
1158+
1159+
list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node)
1160+
if (blkcg->cpd[pol->plid])
1161+
pol->cpd_bind_fn(blkcg->cpd[pol->plid]);
1162+
}
1163+
mutex_unlock(&blkcg_pol_mutex);
1164+
}
1165+
11461166
struct cgroup_subsys io_cgrp_subsys = {
11471167
.css_alloc = blkcg_css_alloc,
11481168
.css_offline = blkcg_css_offline,
11491169
.css_free = blkcg_css_free,
11501170
.can_attach = blkcg_can_attach,
1171+
.bind = blkcg_bind,
11511172
.dfl_cftypes = blkcg_files,
11521173
.legacy_cftypes = blkcg_legacy_files,
11531174
.legacy_name = "blkio",

block/cfq-iosched.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,9 @@ static void cfq_init_cfqg_base(struct cfq_group *cfqg)
15221522
}
15231523

15241524
#ifdef CONFIG_CFQ_GROUP_IOSCHED
1525+
static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
1526+
bool on_dfl, bool reset_dev, bool is_leaf_weight);
1527+
15251528
static void cfqg_stats_exit(struct cfqg_stats *stats)
15261529
{
15271530
blkg_rwstat_exit(&stats->merged);
@@ -1578,21 +1581,34 @@ static struct blkcg_policy_data *cfq_cpd_alloc(gfp_t gfp)
15781581
static void cfq_cpd_init(struct blkcg_policy_data *cpd)
15791582
{
15801583
struct cfq_group_data *cgd = cpd_to_cfqgd(cpd);
1584+
unsigned int weight = cgroup_on_dfl(blkcg_root.css.cgroup) ?
1585+
CGROUP_WEIGHT_DFL : CFQ_WEIGHT_LEGACY_DFL;
15811586

1582-
if (cpd_to_blkcg(cpd) == &blkcg_root) {
1583-
cgd->weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
1584-
cgd->leaf_weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
1585-
} else {
1586-
cgd->weight = CFQ_WEIGHT_LEGACY_DFL;
1587-
cgd->leaf_weight = CFQ_WEIGHT_LEGACY_DFL;
1588-
}
1587+
if (cpd_to_blkcg(cpd) == &blkcg_root)
1588+
weight *= 2;
1589+
1590+
cgd->weight = weight;
1591+
cgd->leaf_weight = weight;
15891592
}
15901593

15911594
static void cfq_cpd_free(struct blkcg_policy_data *cpd)
15921595
{
15931596
kfree(cpd_to_cfqgd(cpd));
15941597
}
15951598

1599+
static void cfq_cpd_bind(struct blkcg_policy_data *cpd)
1600+
{
1601+
struct blkcg *blkcg = cpd_to_blkcg(cpd);
1602+
bool on_dfl = cgroup_on_dfl(blkcg_root.css.cgroup);
1603+
unsigned int weight = on_dfl ? CGROUP_WEIGHT_DFL : CFQ_WEIGHT_LEGACY_DFL;
1604+
1605+
if (blkcg == &blkcg_root)
1606+
weight *= 2;
1607+
1608+
WARN_ON_ONCE(__cfq_set_weight(&blkcg->css, weight, on_dfl, true, false));
1609+
WARN_ON_ONCE(__cfq_set_weight(&blkcg->css, weight, on_dfl, true, true));
1610+
}
1611+
15961612
static struct blkg_policy_data *cfq_pd_alloc(gfp_t gfp, int node)
15971613
{
15981614
struct cfq_group *cfqg;
@@ -1742,6 +1758,8 @@ static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
17421758
char *buf, size_t nbytes, loff_t off,
17431759
bool on_dfl, bool is_leaf_weight)
17441760
{
1761+
unsigned int min = on_dfl ? CGROUP_WEIGHT_MIN : CFQ_WEIGHT_LEGACY_MIN;
1762+
unsigned int max = on_dfl ? CGROUP_WEIGHT_MAX : CFQ_WEIGHT_LEGACY_MAX;
17451763
struct blkcg *blkcg = css_to_blkcg(of_css(of));
17461764
struct blkg_conf_ctx ctx;
17471765
struct cfq_group *cfqg;
@@ -1769,7 +1787,7 @@ static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
17691787
cfqgd = blkcg_to_cfqgd(blkcg);
17701788

17711789
ret = -ERANGE;
1772-
if (!v || (v >= CFQ_WEIGHT_LEGACY_MIN && v <= CFQ_WEIGHT_LEGACY_MAX)) {
1790+
if (!v || (v >= min && v <= max)) {
17731791
if (!is_leaf_weight) {
17741792
cfqg->dev_weight = v;
17751793
cfqg->new_weight = v ?: cfqgd->weight;
@@ -1797,15 +1815,17 @@ static ssize_t cfqg_set_leaf_weight_device(struct kernfs_open_file *of,
17971815
}
17981816

17991817
static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
1800-
bool is_leaf_weight)
1818+
bool on_dfl, bool reset_dev, bool is_leaf_weight)
18011819
{
1820+
unsigned int min = on_dfl ? CGROUP_WEIGHT_MIN : CFQ_WEIGHT_LEGACY_MIN;
1821+
unsigned int max = on_dfl ? CGROUP_WEIGHT_MAX : CFQ_WEIGHT_LEGACY_MAX;
18021822
struct blkcg *blkcg = css_to_blkcg(css);
18031823
struct blkcg_gq *blkg;
18041824
struct cfq_group_data *cfqgd;
18051825
int ret = 0;
18061826

1807-
if (val < CFQ_WEIGHT_LEGACY_MIN || val > CFQ_WEIGHT_LEGACY_MAX)
1808-
return -EINVAL;
1827+
if (val < min || val > max)
1828+
return -ERANGE;
18091829

18101830
spin_lock_irq(&blkcg->lock);
18111831
cfqgd = blkcg_to_cfqgd(blkcg);
@@ -1826,9 +1846,13 @@ static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
18261846
continue;
18271847

18281848
if (!is_leaf_weight) {
1849+
if (reset_dev)
1850+
cfqg->dev_weight = 0;
18291851
if (!cfqg->dev_weight)
18301852
cfqg->new_weight = cfqgd->weight;
18311853
} else {
1854+
if (reset_dev)
1855+
cfqg->dev_leaf_weight = 0;
18321856
if (!cfqg->dev_leaf_weight)
18331857
cfqg->new_leaf_weight = cfqgd->leaf_weight;
18341858
}
@@ -1842,13 +1866,13 @@ static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
18421866
static int cfq_set_weight(struct cgroup_subsys_state *css, struct cftype *cft,
18431867
u64 val)
18441868
{
1845-
return __cfq_set_weight(css, val, false);
1869+
return __cfq_set_weight(css, val, false, false, false);
18461870
}
18471871

18481872
static int cfq_set_leaf_weight(struct cgroup_subsys_state *css,
18491873
struct cftype *cft, u64 val)
18501874
{
1851-
return __cfq_set_weight(css, val, true);
1875+
return __cfq_set_weight(css, val, false, false, true);
18521876
}
18531877

18541878
static int cfqg_print_stat(struct seq_file *sf, void *v)
@@ -2135,7 +2159,7 @@ static ssize_t cfq_set_weight_on_dfl(struct kernfs_open_file *of,
21352159
/* "WEIGHT" or "default WEIGHT" sets the default weight */
21362160
v = simple_strtoull(buf, &endp, 0);
21372161
if (*endp == '\0' || sscanf(buf, "default %llu", &v) == 1) {
2138-
ret = __cfq_set_weight(of_css(of), v, false);
2162+
ret = __cfq_set_weight(of_css(of), v, true, false, false);
21392163
return ret ?: nbytes;
21402164
}
21412165

@@ -4512,9 +4536,9 @@ static int cfq_init_queue(struct request_queue *q, struct elevator_type *e)
45124536
goto out_free;
45134537

45144538
cfq_init_cfqg_base(cfqd->root_group);
4515-
#endif
45164539
cfqd->root_group->weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
45174540
cfqd->root_group->leaf_weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
4541+
#endif
45184542

45194543
/*
45204544
* Not strictly needed (since RB_ROOT just clears the node and we
@@ -4715,6 +4739,7 @@ static struct blkcg_policy blkcg_policy_cfq = {
47154739
.cpd_alloc_fn = cfq_cpd_alloc,
47164740
.cpd_init_fn = cfq_cpd_init,
47174741
.cpd_free_fn = cfq_cpd_free,
4742+
.cpd_bind_fn = cfq_cpd_bind,
47184743

47194744
.pd_alloc_fn = cfq_pd_alloc,
47204745
.pd_init_fn = cfq_pd_init,

include/linux/blk-cgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct blkcg_gq {
138138
typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp);
139139
typedef void (blkcg_pol_init_cpd_fn)(struct blkcg_policy_data *cpd);
140140
typedef void (blkcg_pol_free_cpd_fn)(struct blkcg_policy_data *cpd);
141+
typedef void (blkcg_pol_bind_cpd_fn)(struct blkcg_policy_data *cpd);
141142
typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn)(gfp_t gfp, int node);
142143
typedef void (blkcg_pol_init_pd_fn)(struct blkg_policy_data *pd);
143144
typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
@@ -155,6 +156,7 @@ struct blkcg_policy {
155156
blkcg_pol_alloc_cpd_fn *cpd_alloc_fn;
156157
blkcg_pol_init_cpd_fn *cpd_init_fn;
157158
blkcg_pol_free_cpd_fn *cpd_free_fn;
159+
blkcg_pol_bind_cpd_fn *cpd_bind_fn;
158160

159161
blkcg_pol_alloc_pd_fn *pd_alloc_fn;
160162
blkcg_pol_init_pd_fn *pd_init_fn;

0 commit comments

Comments
 (0)