From patchwork Mon Aug 13 06:58:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10563903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 345C81515 for ; Mon, 13 Aug 2018 06:58:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29B4028EC6 for ; Mon, 13 Aug 2018 06:58:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D77628F1E; Mon, 13 Aug 2018 06:58:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B52128EC6 for ; Mon, 13 Aug 2018 06:58:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 315816B0005; Mon, 13 Aug 2018 02:58:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C3FA6B0006; Mon, 13 Aug 2018 02:58:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18D436B0007; Mon, 13 Aug 2018 02:58:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id 9AAFE6B0005 for ; Mon, 13 Aug 2018 02:58:12 -0400 (EDT) Received: by mail-lf1-f72.google.com with SMTP id v14-v6so3044868lfe.9 for ; Sun, 12 Aug 2018 23:58:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:dkim-signature:subject:from:to:cc :date:message-id:user-agent:mime-version:content-transfer-encoding; bh=8ZtFv2UZmB81xn7HuqqAyGejETJ7l+kWbtMQf+KmMIc=; b=os5XGOi/vmVpq+hFX1AFk2wXDoFi0TDwH8TbgRgjreg8WeFcSOXDlwPQQdsO3duw3z RsAOQ0hoLRmmSp0mpOzWv2OGM46IutRuXn+RhJjh7DjuHeVLcoQRH/RRj2mu0e/Ay7BY b5rH9AYTD60/FILs+5H839onnMOvbIgQ/YH8BsVKH6YTqu7qQPwoFq0eNZcRr6igVLvZ Cvnf/AJo1+tnzjnjIF/qGPYFXHOTRzzYK/XvH/v8UDBzUaLSn1z+CJiawH9WBevXGVAK ZI18g9u7PlN5gaw2B7TnjbyjycLCLyAqnYGRgRyuDxX0UT1uP5pqND8oWFN85RiyVrys iCjg== X-Gm-Message-State: AOUpUlHV4Hqh2w8WXHaa/FhTenYJLmEBEzgrY/oYTzF7iGiaJ6FNk4XT yPphgTOnUuTNpISJbfF/WWqcnHZWAl3me3ruW13RIj4sxgwpYxGi9zClJmIFdjvkYdnMDsYIaJJ nO9Kx1JbmYqnQFGGcloy21TLTSYYyZ+mPQ4PYu3BOjYqS7O8x0fi/a2KAFFyJw6Zesg== X-Received: by 2002:a2e:9144:: with SMTP id q4-v6mr10754068ljg.121.1534143491951; Sun, 12 Aug 2018 23:58:11 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwwSsYG2us9iAQ2p0wtN6ZAUs33n1/SrMSFW/VYqBLfVPY2+MgZRmj8B4gFGXNXMSlGteKj X-Received: by 2002:a2e:9144:: with SMTP id q4-v6mr10754022ljg.121.1534143490868; Sun, 12 Aug 2018 23:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534143490; cv=none; d=google.com; s=arc-20160816; b=ENuFxYxoY0+qKGHNLjaD5zRRlmiQqWSc3Ki/W72pPx9eTYXvuudFoSmbhZuYyeJVLu SwL4cBIQE6Ob3+CW1YCTTp65mLrSLex/FBDziC3ZOfowgYD3P3jHUv1XxMrd1I0kJ1k5 ZpHOmddKCKGuxp1AzHcHaQCjAztpsb2W+MHu+4DObUKvtleon7vm5skQTllfJTpN2Gg2 ED2GPx1q+vJfuwU+XebLIYdMxyG8fK+08ughJK370VHRAhZrEZNqk3mGWWUNR1AZXVbB 1rCopoQz/oH30UIAYTnVGJeX0QaRbna5FZpvuLnEEluEPmCBgiufseA65v64LzQ5bnTg 0gxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:message-id:date :cc:to:from:subject:dkim-signature:dkim-signature :arc-authentication-results; bh=8ZtFv2UZmB81xn7HuqqAyGejETJ7l+kWbtMQf+KmMIc=; b=ZKoASSGAMaiFwZJGAEu8VLcpEZTyhkE2QU3IvgljXoKplzGU8km5l4XFWf9KNHzkSK cNQRmInDoRTCVCAujfGFge7FUG9IfkyKfZT7nUhuGYYM6qiOC0jlkJTQZFdigXY6Nwxq SHr9qY/NqtEIAtyBmHYUxqN+9RmrpZq+a0vsylVwfHSSCBxVSS2ZAvUAOVzthLk+B+Te Y/b4wBdyxQcqPjnxj2qhp9PfKGUtB2Yu4ihZ1IAjGzu9tr5Ap9+eyNwIZ5ki23mtLVb7 aPOT1gHc/FDRhEMQWuxwCCWWXyxtLFivxUdjUTKWn/fabf57kw3aD92y3EU6Gtwrtofj g0nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=Trt2gfZs; dkim=pass header.i=@yandex-team.ru header.s=default header.b=Trt2gfZs; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a72::290 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1o.cmail.yandex.net (forwardcorp1o.cmail.yandex.net. [2a02:6b8:0:1a72::290]) by mx.google.com with ESMTPS id z5-v6si8337469lje.386.2018.08.12.23.58.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 23:58:10 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a72::290 as permitted sender) client-ip=2a02:6b8:0:1a72::290; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=Trt2gfZs; dkim=pass header.i=@yandex-team.ru header.s=default header.b=Trt2gfZs; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a72::290 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.cmail.yandex.net (Yandex) with ESMTP id 0D23B20E7E; Mon, 13 Aug 2018 09:58:10 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id YYu3dH7YBb-w9Nimf5Z; Mon, 13 Aug 2018 09:58:09 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1534143489; bh=8ZtFv2UZmB81xn7HuqqAyGejETJ7l+kWbtMQf+KmMIc=; h=Subject:From:To:Cc:Date:Message-ID; b=Trt2gfZsIhydfpZMDowuOOUH4YLMQcag6yAMewYSM7zY5U4ozfAooEeaAMedsZC7m aiYb0jgfwTFNKMKGzXV6o3bKHKWPgj9BCBHqxgyfJQByx7Zch19DDPGmXvI6QFHAYw J3WVR+/GFEeMpYY6dioCl9Eife8g28hQ1HS3KyaY= Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:854c:7dcd:9203:76a5]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 2thuRniehf-w98eXtFY; Mon, 13 Aug 2018 09:58:09 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1534143489; bh=8ZtFv2UZmB81xn7HuqqAyGejETJ7l+kWbtMQf+KmMIc=; h=Subject:From:To:Cc:Date:Message-ID; b=Trt2gfZsIhydfpZMDowuOOUH4YLMQcag6yAMewYSM7zY5U4ozfAooEeaAMedsZC7m aiYb0jgfwTFNKMKGzXV6o3bKHKWPgj9BCBHqxgyfJQByx7Zch19DDPGmXvI6QFHAYw J3WVR+/GFEeMpYY6dioCl9Eife8g28hQ1HS3KyaY= Authentication-Results: smtpcorp1p.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH RFC 1/3] cgroup: list all subsystem states in debugfs files From: Konstantin Khlebnikov To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Cc: Tejun Heo , Michal Hocko , Vladimir Davydov , Roman Gushchin , Johannes Weiner Date: Mon, 13 Aug 2018 09:58:05 +0300 Message-ID: <153414348591.737150.14229960913953276515.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP After removing cgroup subsystem state could leak or live in background forever because it is pinned by some reference. For example memory cgroup could be pinned by pages in cache or tmpfs. This patch adds common debugfs interface for listing basic state for each controller. Controller could define callback for dumping own attributes. In file /sys/kernel/debug/cgroup/ each line shows state in format: =... [-- =... ] Common attributes: css - css pointer cgroup - cgroup pointer id - css id ino - cgroup inode flags - css flags refcnt - css atomic refcount, for online shows huge bias path - cgroup path This patch adds memcg attributes: mem_id - 16-bit memory cgroup id memory - charged pages swap - charged swap Signed-off-by: Konstantin Khlebnikov --- include/linux/cgroup-defs.h | 1 kernel/cgroup/cgroup.c | 99 +++++++++++++++++++++++++++++++++++++++++++ mm/memcontrol.c | 12 +++++ 3 files changed, 112 insertions(+) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index c0e68f903011..c828820e160f 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -595,6 +595,7 @@ struct cgroup_subsys { void (*exit)(struct task_struct *task); void (*free)(struct task_struct *task); void (*bind)(struct cgroup_subsys_state *root_css); + void (*css_dump)(struct cgroup_subsys_state *css, struct seq_file *); bool early_init:1; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 077370bf8964..b7be190daffe 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -5978,3 +5979,101 @@ static int __init cgroup_sysfs_init(void) } subsys_initcall(cgroup_sysfs_init); #endif /* CONFIG_SYSFS */ + +#ifdef CONFIG_DEBUG_FS +void *css_debugfs_seqfile_start(struct seq_file *m, loff_t *pos) +{ + struct cgroup_subsys *ss = m->private; + struct cgroup_subsys_state *css; + int id = *pos; + + rcu_read_lock(); + css = idr_get_next(&ss->css_idr, &id); + *pos = id; + return css; +} + +void *css_debugfs_seqfile_next(struct seq_file *m, void *v, loff_t *pos) +{ + struct cgroup_subsys *ss = m->private; + struct cgroup_subsys_state *css; + int id = *pos + 1; + + css = idr_get_next(&ss->css_idr, &id); + *pos = id; + return css; +} + +void css_debugfs_seqfile_stop(struct seq_file *m, void *v) +{ + rcu_read_unlock(); +} + +int css_debugfs_seqfile_show(struct seq_file *m, void *v) +{ + struct cgroup_subsys *ss = m->private; + struct cgroup_subsys_state *css = v; + size_t buflen; + char *buf; + int len; + + seq_printf(m, "css=%pK cgroup=%pK id=%d ino=%lu flags=%#x refcnt=%lu path=", + css, css->cgroup, css->id, cgroup_ino(css->cgroup), + css->flags, atomic_long_read(&css->refcnt.count)); + + buflen = seq_get_buf(m, &buf); + if (buf) { + len = cgroup_path(css->cgroup, buf, buflen); + seq_commit(m, len < buflen ? len : -1); + } + + if (ss->css_dump) { + seq_puts(m, " -- "); + ss->css_dump(css, m); + } + + seq_puts(m, "\n"); + return 0; +} + +static const struct seq_operations css_debug_seq_ops = { + .start = css_debugfs_seqfile_start, + .next = css_debugfs_seqfile_next, + .stop = css_debugfs_seqfile_stop, + .show = css_debugfs_seqfile_show, +}; + +static int css_debugfs_open(struct inode *inode, struct file *file) +{ + int ret = seq_open(file, &css_debug_seq_ops); + struct seq_file *m = file->private_data; + + if (!ret) + m->private = inode->i_private; + return ret; +} + +static const struct file_operations css_debugfs_fops = { + .open = css_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +static int __init css_debugfs_init(void) +{ + struct cgroup_subsys *ss; + struct dentry *dir; + int ssid; + + dir = debugfs_create_dir("cgroup", NULL); + if (dir) { + for_each_subsys(ss, ssid) + debugfs_create_file(ss->name, 0644, dir, ss, + &css_debugfs_fops); + } + + return 0; +} +late_initcall(css_debugfs_init); +#endif /* CONFIG_DEBUG_FS */ diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b2173f7e5164..19a4348974a4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4345,6 +4345,17 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) memcg_wb_domain_size_changed(memcg); } +static void mem_cgroup_css_dump(struct cgroup_subsys_state *css, + struct seq_file *m) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(css); + + seq_printf(m, "mem_id=%u memory=%lu swap=%lu", + mem_cgroup_id(memcg), + page_counter_read(&memcg->memory), + page_counter_read(&memcg->swap)); +} + #ifdef CONFIG_MMU /* Handlers for move charge at task migration. */ static int mem_cgroup_do_precharge(unsigned long count) @@ -5386,6 +5397,7 @@ struct cgroup_subsys memory_cgrp_subsys = { .css_released = mem_cgroup_css_released, .css_free = mem_cgroup_css_free, .css_reset = mem_cgroup_css_reset, + .css_dump = mem_cgroup_css_dump, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .post_attach = mem_cgroup_move_task,