Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1348369 > unrolled thread

[cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized

Started byTejun Heo <tj@kernel.org>
First post2016-03-02 19:10 +0100
Last post2016-03-03 16:10 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems  are initialized Tejun Heo <tj@kernel.org> - 2016-03-02 19:10 +0100
    [cgroup/for-4.6 2/2] cgroup: suppress spurious de-populated events Tejun Heo <tj@kernel.org> - 2016-03-02 19:10 +0100
    Re: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after  subsystems are initialized Zefan Li <lizefan@huawei.com> - 2016-03-03 04:20 +0100
    Re: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after  subsystems are initialized Tejun Heo <tj@kernel.org> - 2016-03-03 16:10 +0100

#1348369 — [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized

FromTejun Heo <tj@kernel.org>
Date2016-03-02 19:10 +0100
Subject[cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized
Message-ID<r8jnH-3gr-1@gated-at.bofh.it>
css_sets are hashed by their subsys[] contents and in cgroup_init()
init_css_set is hashed early, before subsystem inits, when all entries
in its subsys[] are NULL, so that cgroup_dfl_root initialization can
find and link to it.  As subsystems are initialized,
init_css_set.subsys[] is filled up but the hashing is never updated
making init_css_set hashed in the wrong place.  While incorrect, this
doesn't cause a critical failure as css_set management code would
create an identical css_set dynamically.

Fix it by rehashing init_css_set after subsystems are initialized.
While at it, drop unnecessary @key local variable.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/cgroup.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5263,7 +5263,6 @@ static u16 cgroup_disable_mask __initdat
 int __init cgroup_init(void)
 {
 	struct cgroup_subsys *ss;
-	unsigned long key;
 	int ssid;
 
 	BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
@@ -5273,9 +5272,12 @@ int __init cgroup_init(void)
 
 	mutex_lock(&cgroup_mutex);
 
-	/* Add init_css_set to the hash table */
-	key = css_set_hash(init_css_set.subsys);
-	hash_add(css_set_table, &init_css_set.hlist, key);
+	/*
+	 * Add init_css_set to the hash table so that dfl_root can link to
+	 * it during init.
+	 */
+	hash_add(css_set_table, &init_css_set.hlist,
+		 css_set_hash(init_css_set.subsys));
 
 	BUG_ON(cgroup_setup_root(&cgrp_dfl_root, 0));
 
@@ -5328,6 +5330,11 @@ int __init cgroup_init(void)
 			ss->bind(init_css_set.subsys[ssid]);
 	}
 
+	/* init_css_set.subsys[] has been updated, re-hash */
+	hash_del(&init_css_set.hlist);
+	hash_add(css_set_table, &init_css_set.hlist,
+		 css_set_hash(init_css_set.subsys));
+
 	WARN_ON(sysfs_create_mount_point(fs_kobj, "cgroup"));
 	WARN_ON(register_filesystem(&cgroup_fs_type));
 	WARN_ON(register_filesystem(&cgroup2_fs_type));

[toc] | [next] | [standalone]


#1348370 — [cgroup/for-4.6 2/2] cgroup: suppress spurious de-populated events

FromTejun Heo <tj@kernel.org>
Date2016-03-02 19:10 +0100
Subject[cgroup/for-4.6 2/2] cgroup: suppress spurious de-populated events
Message-ID<r8jnI-3gr-17@gated-at.bofh.it>
In reply to#1348369
During task migration, tasks may transfer between two css_sets which
are associated with the same cgroup.  If those tasks are the only
tasks in the cgroup, this currently triggers a spurious de-populated
event on the cgroup.

Fix it by bumping up populated count before bumping it down during
migration to ensure that it doesn't reach zero spuriously.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/cgroup.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -678,6 +678,9 @@ static void css_set_move_task(struct tas
 {
 	lockdep_assert_held(&css_set_lock);
 
+	if (to_cset && !css_set_populated(to_cset))
+		css_set_update_populated(to_cset, true);
+
 	if (from_cset) {
 		struct css_task_iter *it, *pos;
 
@@ -711,8 +714,6 @@ static void css_set_move_task(struct tas
 		 */
 		WARN_ON_ONCE(task->flags & PF_EXITING);
 
-		if (!css_set_populated(to_cset))
-			css_set_update_populated(to_cset, true);
 		rcu_assign_pointer(task->cgroups, to_cset);
 		list_add_tail(&task->cg_list, use_mg_tasks ? &to_cset->mg_tasks :
 							     &to_cset->tasks);

[toc] | [prev] | [next] | [standalone]


#1348733 — Re: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized

FromZefan Li <lizefan@huawei.com>
Date2016-03-03 04:20 +0100
SubjectRe: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized
Message-ID<r8rXY-Ry-21@gated-at.bofh.it>
In reply to#1348369
On 2016/3/3 2:07, Tejun Heo wrote:
> css_sets are hashed by their subsys[] contents and in cgroup_init()
> init_css_set is hashed early, before subsystem inits, when all entries
> in its subsys[] are NULL, so that cgroup_dfl_root initialization can
> find and link to it.  As subsystems are initialized,
> init_css_set.subsys[] is filled up but the hashing is never updated
> making init_css_set hashed in the wrong place.  While incorrect, this
> doesn't cause a critical failure as css_set management code would
> create an identical css_set dynamically.
> 
> Fix it by rehashing init_css_set after subsystems are initialized.
> While at it, drop unnecessary @key local variable.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>

For both patches:

Acked-by: Zefan Li <lizefan@huawei.com>

[toc] | [prev] | [next] | [standalone]


#1349265 — Re: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized

FromTejun Heo <tj@kernel.org>
Date2016-03-03 16:10 +0100
SubjectRe: [cgroup/for-4.6 1/2] cgroup: re-hash init_css_set after subsystems are initialized
Message-ID<r8D34-k8-21@gated-at.bofh.it>
In reply to#1348369
Applied to cgroup/for-4.6.

Thanks.

-- 
tejun

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web