[PATCH V2 08/13] blk-throttle: add cgroup2 interface

From: Shaohua Li
Date: Mon Feb 22 2016 - 17:02:42 EST


Example usage of the cgroup2 interface:
$echo "+io" > /sys/fs/cgroup/cgroup.subtree_control
set bandwidth based proporation mode
$echo "8:0 weight_bw" > /sys/fs/cgroup/io.throttle.mode_device
$mkdir /sys/fs/cgroup/test
set cgroup weight
$echo "8:0 200" > /sys/fs/cgroup/test/io.throttle.weight
$echo $$ > /sys/fs/cgroup/test/cgroup.procs

Signed-off-by: Shaohua Li <shli@xxxxxx>
---
block/blk-throttle.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index a594000..01ca04e 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1912,6 +1912,35 @@ static ssize_t tg_set_max(struct kernfs_open_file *of,
return ret ?: nbytes;
}

+static int tg_print_cg2_weight(struct seq_file *sf, void *v)
+{
+ struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
+ struct throtl_group_data *tgd = blkcg_to_tgd(blkcg);
+
+ seq_printf(sf, "default %u\n", tgd->weight);
+ return tg_print_weight_device(sf, v);
+}
+
+static ssize_t tg_set_cg2_weight(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ char *endp;
+ int ret;
+ u64 v;
+
+ buf = strim(buf);
+
+ /* "WEIGHT" or "default WEIGHT" sets the default weight */
+ v = simple_strtoull(buf, &endp, 0);
+ if (*endp == '\0' || sscanf(buf, "default %llu", &v) == 1) {
+ ret = tg_set_weight(of_css(of), of_cft(of), v);
+ return ret ?: nbytes;
+ }
+
+ /* "MAJ:MIN WEIGHT" */
+ return tg_set_weight_device(of, buf, nbytes, off);
+}
+
static struct cftype throtl_files[] = {
{
.name = "max",
@@ -1919,6 +1948,19 @@ static struct cftype throtl_files[] = {
.seq_show = tg_print_max,
.write = tg_set_max,
},
+ {
+ .name = "throttle.weight",
+ .flags = CFTYPE_NOT_ON_ROOT,
+ .private = offsetof(struct throtl_grp, service_queue.weight),
+ .seq_show = tg_print_cg2_weight,
+ .write = tg_set_cg2_weight,
+ },
+ {
+ .name = "throttle.mode_device",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .seq_show = throtl_print_mode_device,
+ .write = tg_set_mode_device,
+ },
{ } /* terminate */
};

--
2.6.5