From mboxrd@z Thu Jan 1 00:00:00 1970 From: Li Zefan Subject: Re: [RFC PATCH -tip] cpuacct: per-cgroup utime/stime statistics - v2 Date: Mon, 16 Mar 2009 15:13:38 +0800 Message-ID: <49BDFC22.6090202@cn.fujitsu.com> References: <20090312110924.GC3344@in.ibm.com> <20090316103517.b0f8a20c.kamezawa.hiroyu@jp.fujitsu.com> <20090316043754.GA3449@in.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:50659 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752023AbZCPHNd (ORCPT ); Mon, 16 Mar 2009 03:13:33 -0400 In-Reply-To: <20090316043754.GA3449@in.ibm.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: bharata@linux.vnet.ibm.com Cc: KAMEZAWA Hiroyuki , linux-kernel@vger.kernel.org, Balaji Rao , Dhaval Giani , Balbir Singh , Paul Menage , Andrew Morton , Ingo Molnar , Peter Zijlstra , linux-arch@vger.kernel.org >>> +/* >>> + * 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.