[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <49BDFC22.6090202@cn.fujitsu.com>
Date: Mon, 16 Mar 2009 15:13:38 +0800
From: Li Zefan <lizf@...fujitsu.com>
To: bharata@...ux.vnet.ibm.com
CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>,
linux-kernel@...r.kernel.org, Balaji Rao <balajirrao@...il.com>,
Dhaval Giani <dhaval@...ux.vnet.ibm.com>,
Balbir Singh <balbir@...ux.vnet.ibm.com>,
Paul Menage <menage@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Ingo Molnar <mingo@...e.hu>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
linux-arch@...r.kernel.org
Subject: Re: [RFC PATCH -tip] cpuacct: per-cgroup utime/stime statistics -
v2
>>> +/*
>>> + * Account the system/user time to the task's accounting group.
>>> + */
>>> +static void cpuacct_update_stats(struct task_struct *tsk,
>>> + enum cpuacct_stat_index idx, cputime_t val)
>>> +{
>>> + struct cpuacct *ca;
>>> +
>>> + if (unlikely(!cpuacct_subsys.active))
>>> + return;
>>> +
>>> + ca = task_ca(tsk);
>>> +
>>> + do {
>>> + percpu_counter_add(&ca->cpustat[idx], val);
>>> + ca = ca->parent;
>>> + } while (ca);
>>> +}
>>> +
>> IIUC, to make sure accessing "ca" to be safe, we need some condition.
>> (task_lock() or some other.....
>
> task_lock() protects tsk->cgroups->subsys[]. So can we hold task_lock()
> to protect this walk ? But we do this cpuacct hierarchy walk for the
> current task here. So can a current task's ca or ca's parents disappear
> from under us ?
>
task_ca() should be protected by task_lock() or rcu_read_lock(), otherwise
there is a very small race:
ca = task_ca(tsk)
move @tsk to another cgroup
rmdir old_cgrp (thus ca is freed)
ca->cpustat <--- accessing freed memory
As KAMEZAWA-san said all updates are called under preempt-disabled, and
classic and tree rcu's rcu_read_lock does preempt disable only, so above
code is ok, except for rcupreempt.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists