From: Topi Miettinen <toiwoton@gmail.com> To: linux-kernel@vger.kernel.org Cc: Topi Miettinen <toiwoton@gmail.com>, Jonathan Corbet <corbet@lwn.net>, Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>, Johannes Weiner <hannes@cmpxchg.org>, Markus Elfring <elfring@users.sourceforge.net>, "David S. Miller" <davem@davemloft.net>, Nicolas Dichtel <nicolas.dichtel@6wind.com>, linux-doc@vger.kernel.org (open list:DOCUMENTATION), cgroups@vger.kernel.org (open list:CONTROL GROUP (CGROUP)) Subject: [PATCH 02/14] resource limits: aggregate task highwater marks to cgroup level Date: Fri, 15 Jul 2016 13:35:49 +0300 [thread overview] Message-ID: <1468578983-28229-3-git-send-email-toiwoton@gmail.com> (raw) In-Reply-To: <1468578983-28229-1-git-send-email-toiwoton@gmail.com> Collect resource usage highwater marks of a task to cgroup statistics when the task exits. Signed-off-by: Topi Miettinen <toiwoton@gmail.com> --- Documentation/accounting/getdelays.c | 10 ++++++- include/linux/cgroup-defs.h | 5 ++++ include/uapi/linux/cgroupstats.h | 3 ++ kernel/cgroup.c | 55 ++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c index 489f1b7..7c86279 100644 --- a/Documentation/accounting/getdelays.c +++ b/Documentation/accounting/getdelays.c @@ -27,7 +27,7 @@ #include <linux/genetlink.h> #include "include/uapi/linux/taskstats.h" -#include <linux/cgroupstats.h> +#include "include/uapi/linux/cgroupstats.h" /* * Generic macros for dealing with netlink sockets. Might be duplicated @@ -258,12 +258,20 @@ static const char *const rlimit_names[] = { static void print_cgroupstats(struct cgroupstats *c) { + int i; + printf("sleeping %llu, blocked %llu, running %llu, stopped %llu, " "uninterruptible %llu\n", (unsigned long long)c->nr_sleeping, (unsigned long long)c->nr_io_wait, (unsigned long long)c->nr_running, (unsigned long long)c->nr_stopped, (unsigned long long)c->nr_uninterruptible); + + if (print_resource_accounting) + for (i = 0; i < RLIM_NLIMITS; i++) + printf("%s=%llu\n", + rlimit_names[i], + (unsigned long long)c->resource_hiwater[i]); } diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 5b17de6..86bbc08 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -16,6 +16,7 @@ #include <linux/percpu-refcount.h> #include <linux/percpu-rwsem.h> #include <linux/workqueue.h> +#include <linux/cgroupstats.h> #ifdef CONFIG_CGROUPS @@ -300,6 +301,10 @@ struct cgroup { /* used to schedule release agent */ struct work_struct release_agent_work; +#ifdef CONFIG_TASK_XACCT + struct cgroupstats stats; +#endif + /* ids of the ancestors at each level including self */ int ancestor_ids[]; }; diff --git a/include/uapi/linux/cgroupstats.h b/include/uapi/linux/cgroupstats.h index 3753c33..18b5b11 100644 --- a/include/uapi/linux/cgroupstats.h +++ b/include/uapi/linux/cgroupstats.h @@ -35,6 +35,9 @@ struct cgroupstats { __u64 nr_uninterruptible; /* Number of tasks in uninterruptible */ /* state */ __u64 nr_io_wait; /* Number of tasks waiting on IO */ + __u64 resource_hiwater[RLIM_NLIMITS]; /* high-watermark of + RLIMIT + resources */ }; /* diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 75c0ff0..9b2d805 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -247,6 +247,7 @@ static void kill_css(struct cgroup_subsys_state *css); static int cgroup_addrm_files(struct cgroup_subsys_state *css, struct cgroup *cgrp, struct cftype cfts[], bool is_add); +static void cgroup_update_stats(void); /** * cgroup_ssid_enabled - cgroup subsys enabled test by subsys ID @@ -2609,6 +2610,8 @@ out_release_tset: list_splice_tail_init(&cset->mg_tasks, &cset->tasks); list_del_init(&cset->mg_node); } + cgroup_update_stats(); + spin_unlock_irq(&css_set_lock); return ret; } @@ -4657,6 +4660,53 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, return 0; } +/* + * Update cgroupstats based on the stats from exiting task + */ +static void cgroup_update_stats_from_task(struct cgroup *cgrp, + struct task_struct *tsk) +{ + struct signal_struct *sig = tsk->signal; + int i; + unsigned int seq, nextseq; + unsigned long flags; + + rcu_read_lock(); + /* Attempt a lockless read on the first round. */ + nextseq = 0; + do { + seq = nextseq; + flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); + for (i = 0; i < RLIM_NLIMITS; i++) + if (cgrp->stats.resource_hiwater[i] < + sig->resource_highwatermark[i]) + cgrp->stats.resource_hiwater[i] = + sig->resource_highwatermark[i]; + + /* If lockless access failed, take the lock. */ + nextseq = 1; + } while (need_seqretry(&sig->stats_lock, seq)); + done_seqretry_irqrestore(&sig->stats_lock, seq, flags); + rcu_read_unlock(); +} + +static void cgroup_update_stats(void) +{ + struct cgroup_root *root; + + for_each_root(root) { + struct cgroup *cgrp; + + if (root == &cgrp_dfl_root && !cgrp_dfl_visible) + continue; + + cgrp = task_cgroup_from_root(current, root); + + if (cgroup_on_dfl(cgrp)) + cgroup_update_stats_from_task(cgrp, current); + } +} + /** * cgroupstats_build - build and fill cgroupstats * @stats: cgroupstats to fill information into @@ -4672,6 +4722,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) struct cgroup *cgrp; struct css_task_iter it; struct task_struct *tsk; + int i; /* it should be kernfs_node belonging to cgroupfs and is a directory */ if (dentry->d_sb->s_type != &cgroup_fs_type || !kn || @@ -4714,9 +4765,13 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) stats->nr_io_wait++; break; } + cgroup_update_stats_from_task(cgrp, tsk); } css_task_iter_end(&it); + for (i = 0; i < RLIM_NLIMITS; i++) + stats->resource_hiwater[i] = cgrp->stats.resource_hiwater[i]; + mutex_unlock(&cgroup_mutex); return 0; } -- 2.8.1
WARNING: multiple messages have this Message-ID (diff)
From: Topi Miettinen <toiwoton@gmail.com> To: linux-kernel@vger.kernel.org Cc: Topi Miettinen <toiwoton@gmail.com>, Jonathan Corbet <corbet@lwn.net>, Tejun Heo <tj@kernel.org>, Li Zefan <lizefan@huawei.com>, Johannes Weiner <hannes@cmpxchg.org>, Markus Elfring <elfring@users.sourceforge.net>, "David S. Miller" <davem@davemloft.net>, Nicolas Dichtel <nicolas.dichtel@6wind.com>, "open list:DOCUMENTATION" <linux-doc@vger.kernel.org>, "open list:CONTROL GROUP CGROUP" <cgroups@vger.kernel.org> Subject: [PATCH 02/14] resource limits: aggregate task highwater marks to cgroup level Date: Fri, 15 Jul 2016 13:35:49 +0300 [thread overview] Message-ID: <1468578983-28229-3-git-send-email-toiwoton@gmail.com> (raw) In-Reply-To: <1468578983-28229-1-git-send-email-toiwoton@gmail.com> Collect resource usage highwater marks of a task to cgroup statistics when the task exits. Signed-off-by: Topi Miettinen <toiwoton@gmail.com> --- Documentation/accounting/getdelays.c | 10 ++++++- include/linux/cgroup-defs.h | 5 ++++ include/uapi/linux/cgroupstats.h | 3 ++ kernel/cgroup.c | 55 ++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c index 489f1b7..7c86279 100644 --- a/Documentation/accounting/getdelays.c +++ b/Documentation/accounting/getdelays.c @@ -27,7 +27,7 @@ #include <linux/genetlink.h> #include "include/uapi/linux/taskstats.h" -#include <linux/cgroupstats.h> +#include "include/uapi/linux/cgroupstats.h" /* * Generic macros for dealing with netlink sockets. Might be duplicated @@ -258,12 +258,20 @@ static const char *const rlimit_names[] = { static void print_cgroupstats(struct cgroupstats *c) { + int i; + printf("sleeping %llu, blocked %llu, running %llu, stopped %llu, " "uninterruptible %llu\n", (unsigned long long)c->nr_sleeping, (unsigned long long)c->nr_io_wait, (unsigned long long)c->nr_running, (unsigned long long)c->nr_stopped, (unsigned long long)c->nr_uninterruptible); + + if (print_resource_accounting) + for (i = 0; i < RLIM_NLIMITS; i++) + printf("%s=%llu\n", + rlimit_names[i], + (unsigned long long)c->resource_hiwater[i]); } diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 5b17de6..86bbc08 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -16,6 +16,7 @@ #include <linux/percpu-refcount.h> #include <linux/percpu-rwsem.h> #include <linux/workqueue.h> +#include <linux/cgroupstats.h> #ifdef CONFIG_CGROUPS @@ -300,6 +301,10 @@ struct cgroup { /* used to schedule release agent */ struct work_struct release_agent_work; +#ifdef CONFIG_TASK_XACCT + struct cgroupstats stats; +#endif + /* ids of the ancestors at each level including self */ int ancestor_ids[]; }; diff --git a/include/uapi/linux/cgroupstats.h b/include/uapi/linux/cgroupstats.h index 3753c33..18b5b11 100644 --- a/include/uapi/linux/cgroupstats.h +++ b/include/uapi/linux/cgroupstats.h @@ -35,6 +35,9 @@ struct cgroupstats { __u64 nr_uninterruptible; /* Number of tasks in uninterruptible */ /* state */ __u64 nr_io_wait; /* Number of tasks waiting on IO */ + __u64 resource_hiwater[RLIM_NLIMITS]; /* high-watermark of + RLIMIT + resources */ }; /* diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 75c0ff0..9b2d805 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -247,6 +247,7 @@ static void kill_css(struct cgroup_subsys_state *css); static int cgroup_addrm_files(struct cgroup_subsys_state *css, struct cgroup *cgrp, struct cftype cfts[], bool is_add); +static void cgroup_update_stats(void); /** * cgroup_ssid_enabled - cgroup subsys enabled test by subsys ID @@ -2609,6 +2610,8 @@ out_release_tset: list_splice_tail_init(&cset->mg_tasks, &cset->tasks); list_del_init(&cset->mg_node); } + cgroup_update_stats(); + spin_unlock_irq(&css_set_lock); return ret; } @@ -4657,6 +4660,53 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, return 0; } +/* + * Update cgroupstats based on the stats from exiting task + */ +static void cgroup_update_stats_from_task(struct cgroup *cgrp, + struct task_struct *tsk) +{ + struct signal_struct *sig = tsk->signal; + int i; + unsigned int seq, nextseq; + unsigned long flags; + + rcu_read_lock(); + /* Attempt a lockless read on the first round. */ + nextseq = 0; + do { + seq = nextseq; + flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); + for (i = 0; i < RLIM_NLIMITS; i++) + if (cgrp->stats.resource_hiwater[i] < + sig->resource_highwatermark[i]) + cgrp->stats.resource_hiwater[i] = + sig->resource_highwatermark[i]; + + /* If lockless access failed, take the lock. */ + nextseq = 1; + } while (need_seqretry(&sig->stats_lock, seq)); + done_seqretry_irqrestore(&sig->stats_lock, seq, flags); + rcu_read_unlock(); +} + +static void cgroup_update_stats(void) +{ + struct cgroup_root *root; + + for_each_root(root) { + struct cgroup *cgrp; + + if (root == &cgrp_dfl_root && !cgrp_dfl_visible) + continue; + + cgrp = task_cgroup_from_root(current, root); + + if (cgroup_on_dfl(cgrp)) + cgroup_update_stats_from_task(cgrp, current); + } +} + /** * cgroupstats_build - build and fill cgroupstats * @stats: cgroupstats to fill information into @@ -4672,6 +4722,7 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) struct cgroup *cgrp; struct css_task_iter it; struct task_struct *tsk; + int i; /* it should be kernfs_node belonging to cgroupfs and is a directory */ if (dentry->d_sb->s_type != &cgroup_fs_type || !kn || @@ -4714,9 +4765,13 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) stats->nr_io_wait++; break; } + cgroup_update_stats_from_task(cgrp, tsk); } css_task_iter_end(&it); + for (i = 0; i < RLIM_NLIMITS; i++) + stats->resource_hiwater[i] = cgrp->stats.resource_hiwater[i]; + mutex_unlock(&cgroup_mutex); return 0; } -- 2.8.1
next prev parent reply other threads:[~2016-07-15 10:37 UTC|newest] Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-07-15 10:35 [PATCH 00/14] Present useful limits to user (v2) Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 01/14] resource limits: foundation for resource highwater tracking Topi Miettinen 2016-07-15 12:12 ` kbuild test robot 2016-07-15 12:49 ` Nicolas Dichtel 2016-07-15 16:27 ` Topi Miettinen 2016-07-15 17:57 ` Nicolas Dichtel 2016-07-15 10:35 ` Topi Miettinen [this message] 2016-07-15 10:35 ` [PATCH 02/14] resource limits: aggregate task highwater marks to cgroup level Topi Miettinen 2016-07-15 12:38 ` kbuild test robot 2016-07-15 14:10 ` Tejun Heo 2016-07-15 17:15 ` Topi Miettinen 2016-07-18 22:52 ` Tejun Heo 2016-07-19 16:57 ` Topi Miettinen 2016-07-19 18:18 ` Tejun Heo 2016-07-15 10:35 ` [PATCH 03/14] resource limits: track highwater mark of file sizes Topi Miettinen 2016-07-15 10:35 ` [PATCH 04/14] resource limits: track highwater mark of VM data segment Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 05/14] resource limits: track highwater mark of stack size Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 06/14] resource limits: track highwater mark of cores dumped Topi Miettinen 2016-07-15 10:35 ` [PATCH 07/14] resource limits: track highwater mark of user processes Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 08/14] resource limits: track highwater mark of number of files Topi Miettinen 2016-07-15 10:35 ` [PATCH 09/14] resource limits: track highwater mark of locked memory Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 15:14 ` Oleg Nesterov 2016-07-15 15:14 ` Oleg Nesterov 2016-07-15 15:14 ` Oleg Nesterov 2016-07-15 17:39 ` Topi Miettinen 2016-07-15 17:39 ` Topi Miettinen 2016-07-15 17:39 ` Topi Miettinen 2016-07-18 15:38 ` Oleg Nesterov 2016-07-18 15:38 ` Oleg Nesterov 2016-07-18 15:38 ` Oleg Nesterov 2016-07-15 17:45 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 10/14] resource limits: track highwater mark of address space size Topi Miettinen 2016-07-15 10:35 ` Topi Miettinen 2016-07-15 10:35 ` [PATCH 11/14] resource limits: track highwater mark of number of pending signals Topi Miettinen 2016-07-15 10:35 ` [PATCH 12/14] resource limits: track highwater mark of size of message queues Topi Miettinen 2016-07-15 10:36 ` [PATCH 13/14] resource limits: track highwater mark of niceness Topi Miettinen 2016-07-15 10:36 ` [PATCH 14/14] resource limits: track highwater mark of RT priority Topi Miettinen 2016-07-15 12:43 ` [PATCH 00/14] Present useful limits to user (v2) Peter Zijlstra 2016-07-15 12:43 ` Peter Zijlstra 2016-07-15 12:43 ` Peter Zijlstra 2016-07-15 13:52 ` Topi Miettinen 2016-07-15 13:52 ` Topi Miettinen 2016-07-15 13:52 ` Topi Miettinen 2016-07-15 13:59 ` Peter Zijlstra 2016-07-15 13:59 ` Peter Zijlstra 2016-07-15 13:59 ` Peter Zijlstra 2016-07-15 13:59 ` Peter Zijlstra 2016-07-15 13:59 ` Peter Zijlstra 2016-07-15 16:57 ` Topi Miettinen 2016-07-15 16:57 ` Topi Miettinen 2016-07-15 16:57 ` Topi Miettinen 2016-07-15 16:57 ` Topi Miettinen 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-18 13:00 ` Austin S. Hemmelgarn [not found] ` <20160715135956.GA3115-ndre7Fmf5hadTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org> 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 20:54 ` H. Peter Anvin 2016-07-15 13:04 ` Balbir Singh 2016-07-15 13:04 ` Balbir Singh 2016-07-15 13:04 ` Balbir Singh 2016-07-15 16:35 ` Topi Miettinen 2016-07-15 16:35 ` Topi Miettinen 2016-07-15 16:35 ` Topi Miettinen 2016-07-18 22:05 ` Doug Ledford 2016-07-18 22:05 ` Doug Ledford 2016-07-19 16:53 ` Topi Miettinen 2016-07-19 16:53 ` Topi Miettinen 2016-07-19 16:53 ` Topi Miettinen 2016-07-15 14:19 ` Richard Weinberger 2016-07-15 14:19 ` Richard Weinberger 2016-07-15 14:19 ` Richard Weinberger 2016-07-15 17:19 ` Topi Miettinen 2016-07-15 17:19 ` Topi Miettinen 2016-07-15 17:19 ` Topi Miettinen 2016-07-18 21:25 ` Doug Ledford 2016-07-18 21:25 ` Doug Ledford 2016-07-15 17:42 ` Topi Miettinen 2016-08-03 18:20 ` Topi Miettinen 2016-08-03 18:20 ` Topi Miettinen 2016-08-04 6:59 ` Fwd: " Topi Miettinen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1468578983-28229-3-git-send-email-toiwoton@gmail.com \ --to=toiwoton@gmail.com \ --cc=cgroups@vger.kernel.org \ --cc=corbet@lwn.net \ --cc=davem@davemloft.net \ --cc=elfring@users.sourceforge.net \ --cc=hannes@cmpxchg.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=lizefan@huawei.com \ --cc=nicolas.dichtel@6wind.com \ --cc=tj@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.