@@ -1522,6 +1522,9 @@ static void cfq_init_cfqg_base(struct cfq_group *cfqg)
1522
1522
}
1523
1523
1524
1524
#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
+
1525
1528
static void cfqg_stats_exit (struct cfqg_stats * stats )
1526
1529
{
1527
1530
blkg_rwstat_exit (& stats -> merged );
@@ -1578,21 +1581,34 @@ static struct blkcg_policy_data *cfq_cpd_alloc(gfp_t gfp)
1578
1581
static void cfq_cpd_init (struct blkcg_policy_data * cpd )
1579
1582
{
1580
1583
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 ;
1581
1586
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 ;
1589
1592
}
1590
1593
1591
1594
static void cfq_cpd_free (struct blkcg_policy_data * cpd )
1592
1595
{
1593
1596
kfree (cpd_to_cfqgd (cpd ));
1594
1597
}
1595
1598
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
+
1596
1612
static struct blkg_policy_data * cfq_pd_alloc (gfp_t gfp , int node )
1597
1613
{
1598
1614
struct cfq_group * cfqg ;
@@ -1742,6 +1758,8 @@ static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
1742
1758
char * buf , size_t nbytes , loff_t off ,
1743
1759
bool on_dfl , bool is_leaf_weight )
1744
1760
{
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 ;
1745
1763
struct blkcg * blkcg = css_to_blkcg (of_css (of ));
1746
1764
struct blkg_conf_ctx ctx ;
1747
1765
struct cfq_group * cfqg ;
@@ -1769,7 +1787,7 @@ static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
1769
1787
cfqgd = blkcg_to_cfqgd (blkcg );
1770
1788
1771
1789
ret = - ERANGE ;
1772
- if (!v || (v >= CFQ_WEIGHT_LEGACY_MIN && v <= CFQ_WEIGHT_LEGACY_MAX )) {
1790
+ if (!v || (v >= min && v <= max )) {
1773
1791
if (!is_leaf_weight ) {
1774
1792
cfqg -> dev_weight = v ;
1775
1793
cfqg -> new_weight = v ?: cfqgd -> weight ;
@@ -1797,15 +1815,17 @@ static ssize_t cfqg_set_leaf_weight_device(struct kernfs_open_file *of,
1797
1815
}
1798
1816
1799
1817
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 )
1801
1819
{
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 ;
1802
1822
struct blkcg * blkcg = css_to_blkcg (css );
1803
1823
struct blkcg_gq * blkg ;
1804
1824
struct cfq_group_data * cfqgd ;
1805
1825
int ret = 0 ;
1806
1826
1807
- if (val < CFQ_WEIGHT_LEGACY_MIN || val > CFQ_WEIGHT_LEGACY_MAX )
1808
- return - EINVAL ;
1827
+ if (val < min || val > max )
1828
+ return - ERANGE ;
1809
1829
1810
1830
spin_lock_irq (& blkcg -> lock );
1811
1831
cfqgd = blkcg_to_cfqgd (blkcg );
@@ -1826,9 +1846,13 @@ static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
1826
1846
continue ;
1827
1847
1828
1848
if (!is_leaf_weight ) {
1849
+ if (reset_dev )
1850
+ cfqg -> dev_weight = 0 ;
1829
1851
if (!cfqg -> dev_weight )
1830
1852
cfqg -> new_weight = cfqgd -> weight ;
1831
1853
} else {
1854
+ if (reset_dev )
1855
+ cfqg -> dev_leaf_weight = 0 ;
1832
1856
if (!cfqg -> dev_leaf_weight )
1833
1857
cfqg -> new_leaf_weight = cfqgd -> leaf_weight ;
1834
1858
}
@@ -1842,13 +1866,13 @@ static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
1842
1866
static int cfq_set_weight (struct cgroup_subsys_state * css , struct cftype * cft ,
1843
1867
u64 val )
1844
1868
{
1845
- return __cfq_set_weight (css , val , false);
1869
+ return __cfq_set_weight (css , val , false, false, false );
1846
1870
}
1847
1871
1848
1872
static int cfq_set_leaf_weight (struct cgroup_subsys_state * css ,
1849
1873
struct cftype * cft , u64 val )
1850
1874
{
1851
- return __cfq_set_weight (css , val , true);
1875
+ return __cfq_set_weight (css , val , false, false, true);
1852
1876
}
1853
1877
1854
1878
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,
2135
2159
/* "WEIGHT" or "default WEIGHT" sets the default weight */
2136
2160
v = simple_strtoull (buf , & endp , 0 );
2137
2161
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);
2139
2163
return ret ?: nbytes ;
2140
2164
}
2141
2165
@@ -4512,9 +4536,9 @@ static int cfq_init_queue(struct request_queue *q, struct elevator_type *e)
4512
4536
goto out_free ;
4513
4537
4514
4538
cfq_init_cfqg_base (cfqd -> root_group );
4515
- #endif
4516
4539
cfqd -> root_group -> weight = 2 * CFQ_WEIGHT_LEGACY_DFL ;
4517
4540
cfqd -> root_group -> leaf_weight = 2 * CFQ_WEIGHT_LEGACY_DFL ;
4541
+ #endif
4518
4542
4519
4543
/*
4520
4544
* Not strictly needed (since RB_ROOT just clears the node and we
@@ -4715,6 +4739,7 @@ static struct blkcg_policy blkcg_policy_cfq = {
4715
4739
.cpd_alloc_fn = cfq_cpd_alloc ,
4716
4740
.cpd_init_fn = cfq_cpd_init ,
4717
4741
.cpd_free_fn = cfq_cpd_free ,
4742
+ .cpd_bind_fn = cfq_cpd_bind ,
4718
4743
4719
4744
.pd_alloc_fn = cfq_pd_alloc ,
4720
4745
.pd_init_fn = cfq_pd_init ,
0 commit comments