aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorMandeep Singh Baines <msb@chromium.org>2011-12-21 23:18:35 -0500
committerTejun Heo <tj@kernel.org>2011-12-22 10:32:57 -0500
commit026085ef5ae07c3197f2baacc091ce067b86ed11 (patch)
tree0497b6414f79efff5b1ba855ddae70a2d850a2b4 /kernel/cgroup.c
parentc84cdf75ccb2845f690579e838f13f7e744e3d23 (diff)
cgroup: remove redundant get/put of old css_set from migrate
We can now assume that the css_set reference held by the task will not go away for an exiting task. PF_EXITING state can be trusted throughout migration by checking it after locking threadgroup. Changes in V4: * https://lkml.org/lkml/2011/12/20/368 (Tejun Heo) * Fix typo in commit message * Undid the rename of css_set_check_fetched * https://lkml.org/lkml/2011/12/20/427 (Li Zefan) * Fix comment in cgroup_task_migrate() Changes in V3: * https://lkml.org/lkml/2011/12/20/255 (Frederic Weisbecker) * Fixed to put error in retval Changes in V2: * https://lkml.org/lkml/2011/12/19/289 (Tejun Heo) * Updated commit message -tj: removed stale patch description about dropped function rename. Signed-off-by: Mandeep Singh Baines <msb@chromium.org> Acked-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Tejun Heo <tj@kernel.org> Cc: containers@lists.linux-foundation.org Cc: cgroups@vger.kernel.org Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Paul Menage <paul@paulmenage.org>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 4936d8886b4f..82288088f6a5 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1850,14 +1850,12 @@ static int cgroup_task_migrate(struct cgroup *cgrp, struct cgroup *oldcgrp,
1850 struct css_set *newcg; 1850 struct css_set *newcg;
1851 1851
1852 /* 1852 /*
1853 * get old css_set. We are synchronized through threadgroup_lock() 1853 * We are synchronized through threadgroup_lock() against PF_EXITING
1854 * against PF_EXITING setting such that we can't race against 1854 * setting such that we can't race against cgroup_exit() changing the
1855 * cgroup_exit() changing the css_set to init_css_set and dropping the 1855 * css_set to init_css_set and dropping the old one.
1856 * old one.
1857 */ 1856 */
1858 WARN_ON_ONCE(tsk->flags & PF_EXITING); 1857 WARN_ON_ONCE(tsk->flags & PF_EXITING);
1859 oldcg = tsk->cgroups; 1858 oldcg = tsk->cgroups;
1860 get_css_set(oldcg);
1861 1859
1862 /* locate or allocate a new css_set for this task. */ 1860 /* locate or allocate a new css_set for this task. */
1863 if (guarantee) { 1861 if (guarantee) {
@@ -1872,12 +1870,9 @@ static int cgroup_task_migrate(struct cgroup *cgrp, struct cgroup *oldcgrp,
1872 might_sleep(); 1870 might_sleep();
1873 /* find_css_set will give us newcg already referenced. */ 1871 /* find_css_set will give us newcg already referenced. */
1874 newcg = find_css_set(oldcg, cgrp); 1872 newcg = find_css_set(oldcg, cgrp);
1875 if (!newcg) { 1873 if (!newcg)
1876 put_css_set(oldcg);
1877 return -ENOMEM; 1874 return -ENOMEM;
1878 }
1879 } 1875 }
1880 put_css_set(oldcg);
1881 1876
1882 task_lock(tsk); 1877 task_lock(tsk);
1883 rcu_assign_pointer(tsk->cgroups, newcg); 1878 rcu_assign_pointer(tsk->cgroups, newcg);
@@ -2186,18 +2181,11 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
2186 * init_css_set. 2181 * init_css_set.
2187 */ 2182 */
2188 oldcg = tc->task->cgroups; 2183 oldcg = tc->task->cgroups;
2189 get_css_set(oldcg); 2184
2190 /* see if the new one for us is already in the list? */ 2185 /* if we don't already have it in the list get a new one */
2191 if (css_set_check_fetched(cgrp, tc->task, oldcg, &newcg_list)) { 2186 if (!css_set_check_fetched(cgrp, tc->task, oldcg, &newcg_list))
2192 /* was already there, nothing to do. */ 2187 if (retval = css_set_prefetch(cgrp, oldcg, &newcg_list))
2193 put_css_set(oldcg);
2194 } else {
2195 /* we don't already have it. get new one. */
2196 retval = css_set_prefetch(cgrp, oldcg, &newcg_list);
2197 put_css_set(oldcg);
2198 if (retval)
2199 goto out_list_teardown; 2188 goto out_list_teardown;
2200 }
2201 } 2189 }
2202 2190
2203 /* 2191 /*