Commit 4c9eefa1 authored by Vivek Goyal's avatar Vivek Goyal Committed by Jens Axboe

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: default avatarVivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarJens Axboe <jaxboe@fusionio.com>
parent 062a644d
...@@ -128,6 +128,27 @@ blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight) ...@@ -128,6 +128,27 @@ blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight)
} }
} }
static inline void blkio_update_group_bps(struct blkio_group *blkg, u64 bps,
int fileid)
{
struct blkio_policy_type *blkiop;
list_for_each_entry(blkiop, &blkio_list, list) {
/* If this policy does not own the blkg, do not send updates */
if (blkiop->plid != blkg->plid)
continue;
if (fileid == BLKIO_THROTL_read_bps_device
&& blkiop->ops.blkio_update_group_read_bps_fn)
blkiop->ops.blkio_update_group_read_bps_fn(blkg, bps);
if (fileid == BLKIO_THROTL_write_bps_device
&& blkiop->ops.blkio_update_group_write_bps_fn)
blkiop->ops.blkio_update_group_write_bps_fn(blkg, bps);
}
}
/* /*
* Add to the appropriate stat variable depending on the request type. * Add to the appropriate stat variable depending on the request type.
* This should be called with the blkg->stats_lock held. * This should be called with the blkg->stats_lock held.
...@@ -612,6 +633,7 @@ static int blkio_policy_parse_and_set(char *buf, ...@@ -612,6 +633,7 @@ static int blkio_policy_parse_and_set(char *buf,
unsigned long major, minor, temp; unsigned long major, minor, temp;
int i = 0; int i = 0;
dev_t dev; dev_t dev;
u64 bps;
memset(s, 0, sizeof(s)); memset(s, 0, sizeof(s));
...@@ -667,7 +689,16 @@ static int blkio_policy_parse_and_set(char *buf, ...@@ -667,7 +689,16 @@ static int blkio_policy_parse_and_set(char *buf,
newpn->plid = plid; newpn->plid = plid;
newpn->fileid = fileid; newpn->fileid = fileid;
newpn->weight = temp; newpn->val.weight = temp;
break;
case BLKIO_POLICY_THROTL:
ret = strict_strtoull(s[1], 10, &bps);
if (ret)
return -EINVAL;
newpn->plid = plid;
newpn->fileid = fileid;
newpn->val.bps = bps;
break; break;
default: default:
BUG(); BUG();
...@@ -684,18 +715,45 @@ unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg, ...@@ -684,18 +715,45 @@ unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_PROP, pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_PROP,
BLKIO_PROP_weight_device); BLKIO_PROP_weight_device);
if (pn) if (pn)
return pn->weight; return pn->val.weight;
else else
return blkcg->weight; return blkcg->weight;
} }
EXPORT_SYMBOL_GPL(blkcg_get_weight); EXPORT_SYMBOL_GPL(blkcg_get_weight);
uint64_t blkcg_get_read_bps(struct blkio_cgroup *blkcg, dev_t dev)
{
struct blkio_policy_node *pn;
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
BLKIO_THROTL_read_bps_device);
if (pn)
return pn->val.bps;
else
return -1;
}
uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg, dev_t dev)
{
struct blkio_policy_node *pn;
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
BLKIO_THROTL_write_bps_device);
if (pn)
return pn->val.bps;
else
return -1;
}
/* Checks whether user asked for deleting a policy rule */ /* Checks whether user asked for deleting a policy rule */
static bool blkio_delete_rule_command(struct blkio_policy_node *pn) static bool blkio_delete_rule_command(struct blkio_policy_node *pn)
{ {
switch(pn->plid) { switch(pn->plid) {
case BLKIO_POLICY_PROP: case BLKIO_POLICY_PROP:
if (pn->weight == 0) if (pn->val.weight == 0)
return 1;
break;
case BLKIO_POLICY_THROTL:
if (pn->val.bps == 0)
return 1; return 1;
break; break;
default: default:
...@@ -710,7 +768,10 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn, ...@@ -710,7 +768,10 @@ static void blkio_update_policy_rule(struct blkio_policy_node *oldpn,
{ {
switch(oldpn->plid) { switch(oldpn->plid) {
case BLKIO_POLICY_PROP: case BLKIO_POLICY_PROP:
oldpn->weight = newpn->weight; oldpn->val.weight = newpn->val.weight;
break;
case BLKIO_POLICY_THROTL:
oldpn->val.bps = newpn->val.bps;
break; break;
default: default:
BUG(); BUG();
...@@ -725,13 +786,23 @@ static void blkio_update_blkg_policy(struct blkio_cgroup *blkcg, ...@@ -725,13 +786,23 @@ static void blkio_update_blkg_policy(struct blkio_cgroup *blkcg,
struct blkio_group *blkg, struct blkio_policy_node *pn) struct blkio_group *blkg, struct blkio_policy_node *pn)
{ {
unsigned int weight; unsigned int weight;
u64 bps;
switch(pn->plid) { switch(pn->plid) {
case BLKIO_POLICY_PROP: case BLKIO_POLICY_PROP:
weight = pn->weight ? pn->weight : weight = pn->val.weight ? pn->val.weight :
blkcg->weight; blkcg->weight;
blkio_update_group_weight(blkg, weight); blkio_update_group_weight(blkg, weight);
break; break;
case BLKIO_POLICY_THROTL:
switch(pn->fileid) {
case BLKIO_THROTL_read_bps_device:
case BLKIO_THROTL_write_bps_device:
bps = pn->val.bps ? pn->val.bps : (-1);
blkio_update_group_bps(blkg, bps, pn->fileid);
break;
}
break;
default: default:
BUG(); BUG();
} }
...@@ -826,7 +897,17 @@ blkio_print_policy_node(struct seq_file *m, struct blkio_policy_node *pn) ...@@ -826,7 +897,17 @@ blkio_print_policy_node(struct seq_file *m, struct blkio_policy_node *pn)
case BLKIO_POLICY_PROP: case BLKIO_POLICY_PROP:
if (pn->fileid == BLKIO_PROP_weight_device) if (pn->fileid == BLKIO_PROP_weight_device)
seq_printf(m, "%u:%u\t%u\n", MAJOR(pn->dev), seq_printf(m, "%u:%u\t%u\n", MAJOR(pn->dev),
MINOR(pn->dev), pn->weight); MINOR(pn->dev), pn->val.weight);
break;
case BLKIO_POLICY_THROTL:
if (pn->fileid == BLKIO_THROTL_read_bps_device)
seq_printf(m, "%u:%u\t%llu\n", MAJOR(pn->dev),
MINOR(pn->dev), pn->val.bps);
else if (pn->fileid == BLKIO_THROTL_write_bps_device)
seq_printf(m, "%u:%u\t%llu\n", MAJOR(pn->dev),
MINOR(pn->dev), pn->val.bps);
else
BUG();
break; break;
default: default:
BUG(); BUG();
...@@ -869,6 +950,16 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft, ...@@ -869,6 +950,16 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
BUG(); BUG();
} }
break; break;
case BLKIO_POLICY_THROTL:
switch(name){
case BLKIO_THROTL_read_bps_device:
case BLKIO_THROTL_write_bps_device:
blkio_read_policy_node_files(cft, blkcg, m);
return 0;
default:
BUG();
}
break;
default: default:
BUG(); BUG();
} }
...@@ -959,7 +1050,18 @@ static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft, ...@@ -959,7 +1050,18 @@ static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
BUG(); BUG();
} }
break; break;
case BLKIO_POLICY_THROTL:
switch(name){
case BLKIO_THROTL_io_service_bytes:
return blkio_read_blkg_stats(blkcg, cft, cb,
BLKIO_STAT_SERVICE_BYTES, 1);
case BLKIO_THROTL_io_serviced:
return blkio_read_blkg_stats(blkcg, cft, cb,
BLKIO_STAT_SERVICED, 1);
default:
BUG();
}
break;
default: default:
BUG(); BUG();
} }
...@@ -1052,6 +1154,23 @@ struct cftype blkio_files[] = { ...@@ -1052,6 +1154,23 @@ struct cftype blkio_files[] = {
.read_u64 = blkiocg_file_read_u64, .read_u64 = blkiocg_file_read_u64,
.write_u64 = blkiocg_file_write_u64, .write_u64 = blkiocg_file_write_u64,
}, },
{
.name = "throttle.read_bps_device",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
BLKIO_THROTL_read_bps_device),
.read_seq_string = blkiocg_file_read,
.write_string = blkiocg_file_write,
.max_write_len = 256,
},
{
.name = "throttle.write_bps_device",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
BLKIO_THROTL_write_bps_device),
.read_seq_string = blkiocg_file_read,
.write_string = blkiocg_file_write,
.max_write_len = 256,
},
{ {
.name = "time", .name = "time",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
...@@ -1070,12 +1189,24 @@ struct cftype blkio_files[] = { ...@@ -1070,12 +1189,24 @@ struct cftype blkio_files[] = {
BLKIO_PROP_io_service_bytes), BLKIO_PROP_io_service_bytes),
.read_map = blkiocg_file_read_map, .read_map = blkiocg_file_read_map,
}, },
{
.name = "throttle.io_service_bytes",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
BLKIO_THROTL_io_service_bytes),
.read_map = blkiocg_file_read_map,
},
{ {
.name = "io_serviced", .name = "io_serviced",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
BLKIO_PROP_io_serviced), BLKIO_PROP_io_serviced),
.read_map = blkiocg_file_read_map, .read_map = blkiocg_file_read_map,
}, },
{
.name = "throttle.io_serviced",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
BLKIO_THROTL_io_serviced),
.read_map = blkiocg_file_read_map,
},
{ {
.name = "io_service_time", .name = "io_service_time",
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
enum blkio_policy_id { enum blkio_policy_id {
BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */ BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */
BLKIO_POLICY_THROTL, /* Throttling */
}; };
#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE) #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
...@@ -88,6 +89,14 @@ enum blkcg_file_name_prop { ...@@ -88,6 +89,14 @@ enum blkcg_file_name_prop {
BLKIO_PROP_dequeue, BLKIO_PROP_dequeue,
}; };
/* cgroup files owned by throttle policy */
enum blkcg_file_name_throtl {
BLKIO_THROTL_read_bps_device,
BLKIO_THROTL_write_bps_device,
BLKIO_THROTL_io_service_bytes,
BLKIO_THROTL_io_serviced,
};
struct blkio_cgroup { struct blkio_cgroup {
struct cgroup_subsys_state css; struct cgroup_subsys_state css;
unsigned int weight; unsigned int weight;
...@@ -146,23 +155,42 @@ struct blkio_group { ...@@ -146,23 +155,42 @@ struct blkio_group {
struct blkio_policy_node { struct blkio_policy_node {
struct list_head node; struct list_head node;
dev_t dev; dev_t dev;
unsigned int weight;
/* This node belongs to max bw policy or porportional weight policy */ /* This node belongs to max bw policy or porportional weight policy */
enum blkio_policy_id plid; enum blkio_policy_id plid;
/* cgroup file to which this rule belongs to */ /* cgroup file to which this rule belongs to */
int fileid; int fileid;
union {
unsigned int weight;
/*
* Rate read/write in terms of byptes per second
* Whether this rate represents read or write is determined
* by file type "fileid".
*/
u64 bps;
} val;
}; };
extern unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg, extern unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
dev_t dev); dev_t dev);
extern uint64_t blkcg_get_read_bps(struct blkio_cgroup *blkcg,
dev_t dev);
extern uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg,
dev_t dev);
typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg); typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg, typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
unsigned int weight); unsigned int weight);
typedef void (blkio_update_group_read_bps_fn) (struct blkio_group *blkg,
u64 read_bps);
typedef void (blkio_update_group_write_bps_fn) (struct blkio_group *blkg,
u64 write_bps);
struct blkio_policy_ops { struct blkio_policy_ops {
blkio_unlink_group_fn *blkio_unlink_group_fn; blkio_unlink_group_fn *blkio_unlink_group_fn;
blkio_update_group_weight_fn *blkio_update_group_weight_fn; blkio_update_group_weight_fn *blkio_update_group_weight_fn;
blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn;
blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn;
}; };
struct blkio_policy_type { struct blkio_policy_type {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment