From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757304Ab2IDOWi (ORCPT ); Tue, 4 Sep 2012 10:22:38 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4810 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757262Ab2IDOWF (ORCPT ); Tue, 4 Sep 2012 10:22:05 -0400 From: Glauber Costa To: Cc: , , davej@redhat.com, ben@decadent.org.uk, a.p.zijlstra@chello.nl, pjt@google.com, lennart@poettering.net, kay.sievers@vrfy.org, tj@kernel.org, Glauber Costa Subject: [RFC 4/5] cpuacct: do not gather cpuacct statistics when not mounted Date: Tue, 4 Sep 2012 18:18:19 +0400 Message-Id: <1346768300-10282-5-git-send-email-glommer@parallels.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1346768300-10282-1-git-send-email-glommer@parallels.com> References: <1346768300-10282-1-git-send-email-glommer@parallels.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the only test that prevents us from running the expensive cpuacct_charge() is cpuacct_subsys.active == true. This will hold at all times after the subsystem is activated, even if it is not mounted. IOW, use it or not, you pay it. By hooking with the bind() callback, we can detect when cpuacct is mounted or umounted, and stop collecting statistics when this cgroup is not in use. Signed-off-by: Glauber Costa CC: Dave Jones CC: Ben Hutchings CC: Peter Zijlstra CC: Paul Turner CC: Lennart Poettering CC: Kay Sievers CC: Tejun Heo --- kernel/sched/core.c | 8 ++++++++ kernel/sched/sched.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e46871d..d654bd1 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8595,6 +8595,13 @@ static struct cftype files[] = { { } /* terminate */ }; +bool cpuacct_mounted; + +void cpuacct_bind(struct cgroup *root) +{ + cpuacct_mounted = root->root == root_cpuacct.css.cgroup->root; +} + /* * charge this task's execution time to its accounting group. * @@ -8628,6 +8635,7 @@ struct cgroup_subsys cpuacct_subsys = { .destroy = cpuacct_destroy, .subsys_id = cpuacct_subsys_id, .base_cftypes = files, + .bind = cpuacct_bind, #ifdef CONFIG_CGROUP_FORCE_COMOUNT_CPU .comounts = 1, .must_comount = { cpu_cgroup_subsys_id, }, diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 1da9fa8..d33f777 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -887,6 +887,7 @@ extern void update_idle_cpu_load(struct rq *this_rq); #include extern bool cpuacct_from_cpu; +extern bool cpuacct_mounted; /* track cpu usage of a group of tasks and its child groups */ struct cpuacct { @@ -921,6 +922,8 @@ extern void __cpuacct_charge(struct task_struct *tsk, u64 cputime); static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) { + if (unlikely(!cpuacct_mounted)) + return; #ifdef CONFIG_CGROUP_FORCE_COMOUNT_CPU if (likely(!cpuacct_from_cpu)) return; -- 1.7.11.4