Skip to content

Commit 4c9eefa

Browse files
rhvgoyalJens Axboe
authored andcommitted
blk-cgroup: Introduce cgroup changes for throttling policy
o cgroup chagnes for throttle policy. o Introduces READ and WRITE bytes per second throttling rules. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 062a644 commit 4c9eefa

2 files changed

Lines changed: 167 additions & 8 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 138 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight)
128128
}
129129
}
130130

131+
static inline void blkio_update_group_bps(struct blkio_group *blkg, u64 bps,
132+
int fileid)
133+
{
134+
struct blkio_policy_type *blkiop;
135+
136+
list_for_each_entry(blkiop, &blkio_list, list) {
137+
138+
/* If this policy does not own the blkg, do not send updates */
139+
if (blkiop->plid != blkg->plid)
140+
continue;
141+
142+
if (fileid == BLKIO_THROTL_read_bps_device
143+
&& blkiop->ops.blkio_update_group_read_bps_fn)
144+
blkiop->ops.blkio_update_group_read_bps_fn(blkg, bps);
145+
146+
if (fileid == BLKIO_THROTL_write_bps_device
147+
&& blkiop->ops.blkio_update_group_write_bps_fn)
148+
blkiop->ops.blkio_update_group_write_bps_fn(blkg, bps);
149+
}
150+
}
151+
131152
/*
132153
* Add to the appropriate stat variable depending on the request type.
133154
* This should be called with the blkg->stats_lock held.
@@ -612,6 +633,7 @@ static int blkio_policy_parse_and_set(char *buf,
612633
unsigned long major, minor, temp;
613634
int i = 0;
614635
dev_t dev;
636+
u64 bps;
615637

616638
memset(s, 0, sizeof(s));
617639

@@ -667,7 +689,16 @@ static int blkio_policy_parse_and_set(char *buf,
667689

668690
newpn->plid = plid;
669691
newpn->fileid = fileid;
670-
newpn->weight = temp;
692+
newpn->val.weight = temp;
693+
break;
694+
case BLKIO_POLICY_THROTL:
695+
ret = strict_strtoull(s[1], 10, &bps);
696+
if (ret)
697+
return -EINVAL;
698+
699+
newpn->plid = plid;
700+
newpn->fileid = fileid;
701+
newpn->val.bps = bps;
671702
break;
672703
default:
673704
BUG();
@@ -684,18 +715,45 @@ unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
684715
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_PROP,
685716
BLKIO_PROP_weight_device);
686717
if (pn)
687-
return pn->weight;
718+
return pn->val.weight;
688719
else
689720
return blkcg->weight;
690721
}
691722
EXPORT_SYMBOL_GPL(blkcg_get_weight);
692723

724+
uint64_t blkcg_get_read_bps(struct blkio_cgroup *blkcg, dev_t dev)
725+
{
726+
struct blkio_policy_node *pn;
727+
728+
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
729+
BLKIO_THROTL_read_bps_device);
730+
if (pn)
731+
return pn->val.bps;
732+
else
733+
return -1;
734+
}
735+
736+
uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg, dev_t dev)
737+
{
738+
struct blkio_policy_node *pn;
739+
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
740+
BLKIO_THROTL_write_bps_device);
741+
if (pn)
742+
return pn->val.bps;
743+
else
744+
return -1;
745+
}
746+
693747
/* Checks whether user asked for deleting a policy rule */
694748
static bool blkio_delete_rule_command(struct blkio_policy_node *pn)
695749
{
696750
switch(pn->plid) {
697751
case BLKIO_POLICY_PROP:
698-
if (pn->weight == 0)
752+
if (pn->val.weight == 0)
753+
return 1;
754+
break;
755+
case BLKIO_POLICY_THROTL:
756+
if (pn->val.bps == 0)
699757
return 1;
700758
break;
701759
default:
@@ -710,7 +768,10 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn,
710768
{
711769
switch(oldpn->plid) {
712770
case BLKIO_POLICY_PROP:
713-
oldpn->weight = newpn->weight;
771+
oldpn->val.weight = newpn->val.weight;
772+
break;
773+
case BLKIO_POLICY_THROTL:
774+
oldpn->val.bps = newpn->val.bps;
714775
break;
715776
default:
716777
BUG();
@@ -725,13 +786,23 @@ static void blkio_update_blkg_policy(struct blkio_cgroup *blkcg,
725786
struct blkio_group *blkg, struct blkio_policy_node *pn)
726787
{
727788
unsigned int weight;
789+
u64 bps;
728790

729791
switch(pn->plid) {
730792
case BLKIO_POLICY_PROP:
731-
weight = pn->weight ? pn->weight :
793+
weight = pn->val.weight ? pn->val.weight :
732794
blkcg->weight;
733795
blkio_update_group_weight(blkg, weight);
734796
break;
797+
case BLKIO_POLICY_THROTL:
798+
switch(pn->fileid) {
799+
case BLKIO_THROTL_read_bps_device:
800+
case BLKIO_THROTL_write_bps_device:
801+
bps = pn->val.bps ? pn->val.bps : (-1);
802+
blkio_update_group_bps(blkg, bps, pn->fileid);
803+
break;
804+
}
805+
break;
735806
default:
736807
BUG();
737808
}
@@ -826,7 +897,17 @@ blkio_print_policy_node(struct seq_file *m, struct blkio_policy_node *pn)
826897
case BLKIO_POLICY_PROP:
827898
if (pn->fileid == BLKIO_PROP_weight_device)
828899
seq_printf(m, "%u:%u\t%u\n", MAJOR(pn->dev),
829-
MINOR(pn->dev), pn->weight);
900+
MINOR(pn->dev), pn->val.weight);
901+
break;
902+
case BLKIO_POLICY_THROTL:
903+
if (pn->fileid == BLKIO_THROTL_read_bps_device)
904+
seq_printf(m, "%u:%u\t%llu\n", MAJOR(pn->dev),
905+
MINOR(pn->dev), pn->val.bps);
906+
else if (pn->fileid == BLKIO_THROTL_write_bps_device)
907+
seq_printf(m, "%u:%u\t%llu\n", MAJOR(pn->dev),
908+
MINOR(pn->dev), pn->val.bps);
909+
else
910+
BUG();
830911
break;
831912
default:
832913
BUG();
@@ -869,6 +950,16 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
869950
BUG();
870951
}
871952
break;
953+
case BLKIO_POLICY_THROTL:
954+
switch(name){
955+
case BLKIO_THROTL_read_bps_device:
956+
case BLKIO_THROTL_write_bps_device:
957+
blkio_read_policy_node_files(cft, blkcg, m);
958+
return 0;
959+
default:
960+
BUG();
961+
}
962+
break;
872963
default:
873964
BUG();
874965
}
@@ -959,7 +1050,18 @@ static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
9591050
BUG();
9601051
}
9611052
break;
962-
1053+
case BLKIO_POLICY_THROTL:
1054+
switch(name){
1055+
case BLKIO_THROTL_io_service_bytes:
1056+
return blkio_read_blkg_stats(blkcg, cft, cb,
1057+
BLKIO_STAT_SERVICE_BYTES, 1);
1058+
case BLKIO_THROTL_io_serviced:
1059+
return blkio_read_blkg_stats(blkcg, cft, cb,
1060+
BLKIO_STAT_SERVICED, 1);
1061+
default:
1062+
BUG();
1063+
}
1064+
break;
9631065
default:
9641066
BUG();
9651067
}
@@ -1052,6 +1154,23 @@ struct cftype blkio_files[] = {
10521154
.read_u64 = blkiocg_file_read_u64,
10531155
.write_u64 = blkiocg_file_write_u64,
10541156
},
1157+
{
1158+
.name = "throttle.read_bps_device",
1159+
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
1160+
BLKIO_THROTL_read_bps_device),
1161+
.read_seq_string = blkiocg_file_read,
1162+
.write_string = blkiocg_file_write,
1163+
.max_write_len = 256,
1164+
},
1165+
1166+
{
1167+
.name = "throttle.write_bps_device",
1168+
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
1169+
BLKIO_THROTL_write_bps_device),
1170+
.read_seq_string = blkiocg_file_read,
1171+
.write_string = blkiocg_file_write,
1172+
.max_write_len = 256,
1173+
},
10551174
{
10561175
.name = "time",
10571176
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
@@ -1070,12 +1189,24 @@ struct cftype blkio_files[] = {
10701189
BLKIO_PROP_io_service_bytes),
10711190
.read_map = blkiocg_file_read_map,
10721191
},
1192+
{
1193+
.name = "throttle.io_service_bytes",
1194+
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
1195+
BLKIO_THROTL_io_service_bytes),
1196+
.read_map = blkiocg_file_read_map,
1197+
},
10731198
{
10741199
.name = "io_serviced",
10751200
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
10761201
BLKIO_PROP_io_serviced),
10771202
.read_map = blkiocg_file_read_map,
10781203
},
1204+
{
1205+
.name = "throttle.io_serviced",
1206+
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
1207+
BLKIO_THROTL_io_serviced),
1208+
.read_map = blkiocg_file_read_map,
1209+
},
10791210
{
10801211
.name = "io_service_time",
10811212
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,

‎block/blk-cgroup.h‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
enum blkio_policy_id {
1919
BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */
20+
BLKIO_POLICY_THROTL, /* Throttling */
2021
};
2122

2223
#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
@@ -88,6 +89,14 @@ enum blkcg_file_name_prop {
8889
BLKIO_PROP_dequeue,
8990
};
9091

92+
/* cgroup files owned by throttle policy */
93+
enum blkcg_file_name_throtl {
94+
BLKIO_THROTL_read_bps_device,
95+
BLKIO_THROTL_write_bps_device,
96+
BLKIO_THROTL_io_service_bytes,
97+
BLKIO_THROTL_io_serviced,
98+
};
99+
91100
struct blkio_cgroup {
92101
struct cgroup_subsys_state css;
93102
unsigned int weight;
@@ -146,23 +155,42 @@ struct blkio_group {
146155
struct blkio_policy_node {
147156
struct list_head node;
148157
dev_t dev;
149-
unsigned int weight;
150158
/* This node belongs to max bw policy or porportional weight policy */
151159
enum blkio_policy_id plid;
152160
/* cgroup file to which this rule belongs to */
153161
int fileid;
162+
163+
union {
164+
unsigned int weight;
165+
/*
166+
* Rate read/write in terms of byptes per second
167+
* Whether this rate represents read or write is determined
168+
* by file type "fileid".
169+
*/
170+
u64 bps;
171+
} val;
154172
};
155173

156174
extern unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
157175
dev_t dev);
176+
extern uint64_t blkcg_get_read_bps(struct blkio_cgroup *blkcg,
177+
dev_t dev);
178+
extern uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg,
179+
dev_t dev);
158180

159181
typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
160182
typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
161183
unsigned int weight);
184+
typedef void (blkio_update_group_read_bps_fn) (struct blkio_group *blkg,
185+
u64 read_bps);
186+
typedef void (blkio_update_group_write_bps_fn) (struct blkio_group *blkg,
187+
u64 write_bps);
162188

163189
struct blkio_policy_ops {
164190
blkio_unlink_group_fn *blkio_unlink_group_fn;
165191
blkio_update_group_weight_fn *blkio_update_group_weight_fn;
192+
blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn;
193+
blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn;
166194
};
167195

168196
struct blkio_policy_type {

0 commit comments

Comments
 (0)