Add a cgroup.stat interface to the base cgroup control files with the following metrics: nr_descendants total number of descendant cgroups nr_dying_descendants total number of dying descendant cgroups max_descendant_depth maximum descent depth below the current cgroup Signed-off-by: Roman Gushchin <guro@xxxxxx> Cc: Tejun Heo <tj@xxxxxxxxxx> Cc: Zefan Li <lizefan@xxxxxxxxxx> Cc: Waiman Long <longman@xxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: kernel-team@xxxxxx Cc: cgroups@xxxxxxxxxxxxxxx Cc: linux-doc@xxxxxxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx --- Documentation/cgroup-v2.txt | 12 ++++++++++++ kernel/cgroup/cgroup.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt index dec5afdaa36d..ae9cc0d917b3 100644 --- a/Documentation/cgroup-v2.txt +++ b/Documentation/cgroup-v2.txt @@ -854,6 +854,18 @@ All cgroup core files are prefixed with "cgroup." 1 if the cgroup or its descendants contains any live processes; otherwise, 0. + cgroup.stat + A read-only flat-keyed file with the following entries: + + nr_descendants + Total number of descendant cgroups. + + nr_dying_descendants + Total number of dying descendant cgroups. + + max_descendant_depth + Maximum descent depth below the current cgroup. + Controllers =========== diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 85f6a112344b..b7af1745d46c 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3216,6 +3216,33 @@ static int cgroup_events_show(struct seq_file *seq, void *v) return 0; } +static int cgroup_stats_show(struct seq_file *seq, void *v) +{ + struct cgroup_subsys_state *css; + unsigned long total = 0; + unsigned long offline = 0; + int max_level = 0; + + rcu_read_lock(); + css_for_each_descendant_pre(css, seq_css(seq)) { + if (css == seq_css(seq)) + continue; + ++total; + if (!(css->flags & CSS_ONLINE)) + ++offline; + if (css->cgroup->level > max_level) + max_level = css->cgroup->level; + } + rcu_read_unlock(); + + seq_printf(seq, "nr_descendants %lu\n", total); + seq_printf(seq, "nr_dying_descendants %lu\n", offline); + seq_printf(seq, "max_descendant_depth %d\n", + max_level - seq_css(seq)->cgroup->level); + + return 0; +} + static int cgroup_file_open(struct kernfs_open_file *of) { struct cftype *cft = of->kn->priv; @@ -4309,6 +4336,10 @@ static struct cftype cgroup_base_files[] = { .file_offset = offsetof(struct cgroup, events_file), .seq_show = cgroup_events_show, }, + { + .name = "cgroup.stat", + .seq_show = cgroup_stats_show, + }, { } /* terminate */ }; -- 2.13.3 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html