Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753775AbbDXOHh (ORCPT ); Fri, 24 Apr 2015 10:07:37 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]:33970 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541AbbDXOHe (ORCPT ); Fri, 24 Apr 2015 10:07:34 -0400 MIME-Version: 1.0 X-Originating-IP: [122.106.150.15] Date: Sat, 25 Apr 2015 00:07:34 +1000 Message-ID: Subject: Re: [PATCH v10 4/4] cgroups: implement the PIDs subsystem From: Aleksa Sarai To: Tejun Heo Cc: lizefan@huawei.com, mingo@redhat.com, peterz@infradead.org, richard@nod.at, =?UTF-8?B?RnLDqWTDqXJpYyBXZWlzYmVja2Vy?= , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1637 Lines: 48 >>> + rcu_read_lock(); >>> + css = task_css(current, pids_cgrp_id); >>> + if (!css_tryget_online(css)) { >>> + retval = -EBUSY; >>> + goto err_rcu_unlock; >>> + } >>> + rcu_read_unlock(); >> >> Hmmm... so, the above is guaranteed to succeed in finite amount of >> time (the race window is actually very narrow) and it'd be silly to >> fail fork because a task was being moved across cgroups. >> >> I think it'd be a good idea to implement task_get_css() which loops >> and returns the current css for the requested subsystem with reference >> count bumped and it can use css_tryget() too. Holding a ref doesn't >> prevent css from dying anyway, so it doesn't make any difference. > > Hmmm, okay. I'll work on this later. Would something like this suffice? struct cgroup_subsys_state *task_get_css(struct task_struct *task, int subsys_id) { bool have_ref = false; struct cgroup_subsys_state *css; while(!have_ref) { rcu_read_lock(); css = task_css(task, subsys_id); have_ref = !css_tryget(css); rcu_read_unlock(); } return css; } Also, as a side note (in the same vein I guess), does a ref on a css_set give you an implicit ref on a css inside that css_set, or are those two orthogonal operations? -- Aleksa Sarai (cyphar) www.cyphar.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/