From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934635Ab1JEMi0 (ORCPT ); Wed, 5 Oct 2011 08:38:26 -0400 Received: from casper.infradead.org ([85.118.1.10]:53764 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934243Ab1JEMi0 convert rfc822-to-8bit (ORCPT ); Wed, 5 Oct 2011 08:38:26 -0400 Subject: Re: [PATCH 04/10] Display /proc/stat information per cgroup From: Peter Zijlstra To: Glauber Costa Cc: linux-kernel@vger.kernel.org, paul@paulmenage.org, lizf@cn.fujitsu.com, daniel.lezcano@free.fr, jbottomley@parallels.com Date: Wed, 05 Oct 2011 14:38:14 +0200 In-Reply-To: <4E8C494F.8020804@parallels.com> References: <1317583287-18300-1-git-send-email-glommer@parallels.com> <1317583287-18300-5-git-send-email-glommer@parallels.com> <1317804965.6766.2.camel@twins> <4E8C494F.8020804@parallels.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Mailer: Evolution 3.0.3- Message-ID: <1317818294.6766.16.camel@twins> Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2011-10-05 at 16:10 +0400, Glauber Costa wrote: > On 10/05/2011 12:56 PM, Peter Zijlstra wrote: > > On Sun, 2011-10-02 at 23:21 +0400, Glauber Costa wrote: > >> +struct kernel_stat *task_group_kstat(struct task_struct *p) > >> +{ > >> + struct task_group *tg; > >> + struct kernel_stat *kstat; > >> + > >> + rcu_read_lock(); > >> + tg = task_group(p); > >> + kstat = tg->cpustat; > >> + rcu_read_unlock(); > >> + return kstat; > >> +} > > > > Who keeps tg alive and kicking while you poke at its (cpustat) member? > > * All calls to this function currently pass current as a parameter > (Okay, maybe it is too generic and we should pass nothing at all, and > grab current within it) > * rcu_read_lock() guarantees that current will exist during this call, > and task_group won't change. (right?) The thing I worry about is: A (pid n) B kstat = task_group_kstat() echo n > /cgroup/something-else/pid rmdir /cgroup/group-that-had-A RCU complete kfree(tg) etc.. kstat->foo++; <-- *BOOM* The only way to avoid someone moving you around is by holding some cgroup lock, task->alloc_lock, task->pi_lock or the rq->lock where task runs. Alternatively keep rcu_read_lock() around the entire kstat usage.