From patchwork Fri Aug 26 01:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Jialin X-Patchwork-Id: 12955420 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F05CAECAAA2 for ; Fri, 26 Aug 2022 01:18:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D5EB6B0074; Thu, 25 Aug 2022 21:18:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88363940009; Thu, 25 Aug 2022 21:18:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74DAE6B0078; Thu, 25 Aug 2022 21:18:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 66DF66B0074 for ; Thu, 25 Aug 2022 21:18:42 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3C8CE12060C for ; Fri, 26 Aug 2022 01:18:42 +0000 (UTC) X-FDA: 79839984084.25.288AAFB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf12.hostedemail.com (Postfix) with ESMTP id 6766240018 for ; Fri, 26 Aug 2022 01:18:41 +0000 (UTC) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MDMMF5WJbzkWgX; Fri, 26 Aug 2022 09:15:05 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 26 Aug 2022 09:18:38 +0800 Received: from ubuntu1804.huawei.com (10.67.174.175) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 26 Aug 2022 09:18:37 +0800 From: Lu Jialin To: Zefan Li , Tejun Heo , "Johannes Weiner" , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song CC: Lu Jialin , Xiu Jianfeng , , , Subject: [RFC 1/2] cgroup: Introduce per-cgroup resource top show interface Date: Fri, 26 Aug 2022 09:15:02 +0800 Message-ID: <20220826011503.103894-2-lujialin4@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220826011503.103894-1-lujialin4@huawei.com> References: <20220826011503.103894-1-lujialin4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.175] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661476721; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JmRV06yxriXdEmN8w/JnuFB6P6hei2eUi2dcIUSiu50=; b=0XpLGfHGBtdmWvespl7650Vwl2Tp4RDxoNDhdnXJqm5PPGYRFuJaUS76Lrjuy61+IULo+W GbxjMbaceXu+OMN696XEgyIVApyrbpO11L83u8xR95n7hdDfEV1XC75K8acsu7wxVpvpAj 9dnTQdr7mIaRFdZvyp8aCECD4zae4n8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of lujialin4@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=lujialin4@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661476721; a=rsa-sha256; cv=none; b=KkO6OdcVN3DnwCdAMb+DtJOZVf3ZPeZ5jmj5XPthgn6mQp7MtAHq8sU6B3mOrD6gKu/qkq roJptkv8UFwUqXZOW9LPmPUzm4WQwue6MSF87x8Vk8DKc9NNm1h81SGIbiXUmPA9f50ACh 19bvHc4Zpvi7dGCgDXujoDyUGUb/DPU= Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of lujialin4@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=lujialin4@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Stat-Signature: 6gcb77gy5bwhcbuzqeyqt8cckasd17e9 X-Rspamd-Queue-Id: 6766240018 X-Rspamd-Server: rspam03 X-HE-Tag: 1661476721-628227 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Xiu Jianfeng This patch introduces cgroup.top interface for each cgroup. When accessed by userspace, cgroup.top is able to: 1. Sort cgroups by their usage on various resources(e.g. memory, cpu, etc.) 2. Display resource usage status on all child cgroups. Signed-off-by: Xiu Jianfeng Co-developed-by: Lu Jialin Signed-off-by: Lu Jialin --- include/linux/cgroup-defs.h | 1 + kernel/cgroup/cgroup.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 4bcf56b3491c..ba11e09f8f03 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -651,6 +651,7 @@ struct cgroup_subsys { int (*css_extra_stat_show)(struct seq_file *seq, struct cgroup_subsys_state *css); + void (*css_top)(struct cgroup_subsys_state *css, struct seq_file *seq); int (*can_attach)(struct cgroup_taskset *tset); void (*cancel_attach)(struct cgroup_taskset *tset); void (*attach)(struct cgroup_taskset *tset); diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index ffaccd6373f1..01bd1a734a01 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3867,6 +3867,22 @@ static ssize_t cgroup_kill_write(struct kernfs_open_file *of, char *buf, return ret ?: nbytes; } +static int cgroup_top_show(struct seq_file *seq, void *v) +{ + struct cgroup *cgrp = seq_css(seq)->cgroup; + struct cgroup_subsys_state *css; + int ssid; + + rcu_read_lock(); + for_each_css(css, ssid, cgrp) { + if (css->ss->css_top) + css->ss->css_top(css, seq); + } + rcu_read_unlock(); + + return 0; +} + static int cgroup_file_open(struct kernfs_open_file *of) { struct cftype *cft = of_cft(of); @@ -5125,6 +5141,10 @@ static struct cftype cgroup_base_files[] = { .release = cgroup_pressure_release, }, #endif /* CONFIG_PSI */ + { + .name = "cgroup.top", + .seq_show = cgroup_top_show, + }, { } /* terminate */ };