public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: bharata@linux.vnet.ibm.com
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	linux-kernel@vger.kernel.org, Balaji Rao <balajirrao@gmail.com>,
	Dhaval Giani <dhaval@linux.vnet.ibm.com>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	Paul Menage <menage@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	linux-arch@vger.kernel.org
Subject: Re: [RFC PATCH -tip] cpuacct: per-cgroup utime/stime statistics - v2
Date: Mon, 16 Mar 2009 16:58:45 +0800	[thread overview]
Message-ID: <49BE14C5.2020109@cn.fujitsu.com> (raw)
In-Reply-To: <20090316084756.GD3449@in.ibm.com>

Bharata B Rao wrote:
> On Mon, Mar 16, 2009 at 03:13:38PM +0800, Li Zefan wrote:
>>>>> +/*
>>>>> + * 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.
> 
> So I will protect task_ca() and ca hierarchy walk with explicit
> rcu_read_lock() to be fully safe.
> 

either:

rcu_read_lock();
ca = task_ca(tsk);
do {
	percpu_counter_add(&ca->cpustat[idx], val);
	ca = ca->parent;
} while (ca);
rcu_read_unlock();

or:

rcu_read_lock();
ca = task_ca(tsk);
css_get(&ca->css);
rcu_read_unlock();
do {
	percpu_counter_add(&ca->cpustat[idx], val);
	ca = ca->parent;
} while (ca);
css_put(&ca->css);

which is more efficient?

> By the same logic, hierarchy walk in cpuacct_charge() is also
> not safe with rcupreempt. It is under preempt disabled section due
> to rq->lock. Does cpuacct_charge() also need a fix then ?
> 

I guess so..

  reply	other threads:[~2009-03-16  8:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12 11:09 [RFC PATCH -tip] cpuacct: per-cgroup utime/stime statistics - v2 Bharata B Rao
2009-03-16  1:35 ` KAMEZAWA Hiroyuki
2009-03-16  4:37   ` Bharata B Rao
2009-03-16  5:01     ` KAMEZAWA Hiroyuki
2009-03-16  7:13     ` Li Zefan
2009-03-16  8:47       ` Bharata B Rao
2009-03-16  8:58         ` Li Zefan [this message]
2009-03-16  8:58           ` Li Zefan
2009-03-17  6:23           ` Bharata B Rao

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=49BE14C5.2020109@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=balajirrao@gmail.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=dhaval@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menage@google.com \
    --cc=mingo@elte.hu \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox