From patchwork Mon Feb 22 22:01:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 8383991 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 274A6C0553 for ; Mon, 22 Feb 2016 22:02:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58816203B0 for ; Mon, 22 Feb 2016 22:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65773201EC for ; Mon, 22 Feb 2016 22:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756032AbcBVWCD (ORCPT ); Mon, 22 Feb 2016 17:02:03 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60506 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755996AbcBVWCB (ORCPT ); Mon, 22 Feb 2016 17:02:01 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.15.0.59/8.15.0.59) with SMTP id u1MM1c3E013921 for ; Mon, 22 Feb 2016 14:02:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=nUypKgBmVGGrlzH7PsEhgXiDEf5WbTFesxircAupoC0=; b=naH6DcEgY2vPUzmkK4CRSc6FBhk/s3CVlgLU95sWkfqL6DIw59xQMJKXvWtmnsIV+8Tw oNgvEvkLa8FyI0mzEct5iRoJf8GQEcSmpgFogiyXIHSCWNG2Ee9gCYSiNrHbdD4zbOz+ CVVMi9/E1+5Pu7hJi5RmtuU38e8q41eNrFg= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2189838e8e-6 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Mon, 22 Feb 2016 14:02:00 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB13.TheFacebook.com (192.168.16.23) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 22 Feb 2016 14:01:32 -0800 Received: from facebook.com (2401:db00:11:d0a2:face:0:39:0) by mx-out.facebook.com (10.223.101.97) with ESMTP id d4365f5cd9af11e58f4624be0595f910-c61f8270 for ; Mon, 22 Feb 2016 14:01:30 -0800 Received: by devbig084.prn1.facebook.com (Postfix, from userid 11222) id 3B89E47E31B0; Mon, 22 Feb 2016 14:01:29 -0800 (PST) From: Shaohua Li To: , CC: , , Vivek Goyal , "jmoyer @ redhat . com" , Subject: [PATCH V2 08/13] blk-throttle: add cgroup2 interface Date: Mon, 22 Feb 2016 14:01:23 -0800 Message-ID: X-Mailer: git-send-email 2.6.5 In-Reply-To: References: X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-02-22_08:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 */ };