All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: lizefan@huawei.com
Cc: containers@lists.linux-foundation.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 11/12] cgroup: prepare migration path for unified hierarchy
Date: Thu, 27 Mar 2014 22:41:00 -0400	[thread overview]
Message-ID: <1395974461-12735-12-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1395974461-12735-1-git-send-email-tj@kernel.org>

Unified hierarchy implementation would require re-migrating tasks onto
the same cgroup on the default hierarchy to reflect updated effective
csses.  Update cgroup_migrate_prepare_dst() so that it accepts NULL as
the destination cgrp.  When NULL is specified, the destination is
considered to be the cgroup on the default hierarchy associated with
each css_set.

After this change, the identity check in cgroup_migrate_add_src()
isn't sufficient for noop detection as the associated csses may change
without any cgroup association changing.  The only way to tell whether
a migration is noop or not is testing whether the source and
destination csets are identical.  The noop check in
cgroup_migrate_add_src() is removed and cset identity test is added to
cgroup_migreate_prepare_dst().  If it's detected that source and
destination csets are identical, the cset is removed removed from
@preloaded_csets and all the migration nodes are cleared which makes
cgroup_migrate() ignore the cset.

Also, make the function append the destination css_sets to
@preloaded_list so that destination css_sets always come after source
css_sets.

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

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0c67141..5faa115 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1901,10 +1901,6 @@ static void cgroup_migrate_add_src(struct css_set *src_cset,
 
 	src_cgrp = cset_cgroup_from_root(src_cset, dst_cgrp->root);
 
-	/* nothing to do if this cset already belongs to the cgroup */
-	if (src_cgrp == dst_cgrp)
-		return;
-
 	if (!list_empty(&src_cset->mg_preload_node))
 		return;
 
@@ -1919,13 +1915,14 @@ static void cgroup_migrate_add_src(struct css_set *src_cset,
 
 /**
  * cgroup_migrate_prepare_dst - prepare destination css_sets for migration
- * @dst_cgrp: the destination cgroup
+ * @dst_cgrp: the destination cgroup (may be %NULL)
  * @preloaded_csets: list of preloaded source css_sets
  *
  * Tasks are about to be moved to @dst_cgrp and all the source css_sets
  * have been preloaded to @preloaded_csets.  This function looks up and
- * pins all destination css_sets, links each to its source, and put them on
- * @preloaded_csets.
+ * pins all destination css_sets, links each to its source, and append them
+ * to @preloaded_csets.  If @dst_cgrp is %NULL, the destination of each
+ * source css_set is assumed to be its cgroup on the default hierarchy.
  *
  * This function must be called after cgroup_migrate_add_src() has been
  * called on each migration source css_set.  After migration is performed
@@ -1936,19 +1933,34 @@ static int cgroup_migrate_prepare_dst(struct cgroup *dst_cgrp,
 				      struct list_head *preloaded_csets)
 {
 	LIST_HEAD(csets);
-	struct css_set *src_cset;
+	struct css_set *src_cset, *tmp_cset;
 
 	lockdep_assert_held(&cgroup_mutex);
 
 	/* look up the dst cset for each src cset and link it to src */
-	list_for_each_entry(src_cset, preloaded_csets, mg_preload_node) {
+	list_for_each_entry_safe(src_cset, tmp_cset, preloaded_csets, mg_preload_node) {
 		struct css_set *dst_cset;
 
-		dst_cset = find_css_set(src_cset, dst_cgrp);
+		dst_cset = find_css_set(src_cset,
+					dst_cgrp ?: src_cset->dfl_cgrp);
 		if (!dst_cset)
 			goto err;
 
 		WARN_ON_ONCE(src_cset->mg_dst_cset || dst_cset->mg_dst_cset);
+
+		/*
+		 * If src cset equals dst, it's noop.  Drop the src.
+		 * cgroup_migrate() will skip the cset too.  Note that we
+		 * can't handle src == dst as some nodes are used by both.
+		 */
+		if (src_cset == dst_cset) {
+			src_cset->mg_src_cgrp = NULL;
+			list_del_init(&src_cset->mg_preload_node);
+			put_css_set(src_cset, false);
+			put_css_set(dst_cset, false);
+			continue;
+		}
+
 		src_cset->mg_dst_cset = dst_cset;
 
 		if (list_empty(&dst_cset->mg_preload_node))
@@ -1957,7 +1969,7 @@ static int cgroup_migrate_prepare_dst(struct cgroup *dst_cgrp,
 			put_css_set(dst_cset, false);
 	}
 
-	list_splice(&csets, preloaded_csets);
+	list_splice_tail(&csets, preloaded_csets);
 	return 0;
 err:
 	cgroup_migrate_finish(&csets);
-- 
1.8.5.3


  parent reply	other threads:[~2014-03-28  2:42 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-28  2:40 [PATCHSET cgroup/for-3.15] cgroup: implement unified hierarchy Tejun Heo
2014-03-28  2:40 ` Tejun Heo
2014-03-28  2:40 ` [PATCH 04/12] cgroup: make css_next_child() skip missing csses Tejun Heo
2014-03-28  2:40 ` [PATCH 06/12] cgroup: teach css_task_iter about effective csses Tejun Heo
2014-03-28  2:40 ` [PATCH 10/12] cgroup: update subsystem rebind restrictions Tejun Heo
2014-03-28  2:41 ` Tejun Heo [this message]
2014-03-28  2:41 ` [PATCH 12/12] cgroup: implement dynamic subtree controller enable/disable on the default hierarchy Tejun Heo
2014-03-28  2:41   ` Tejun Heo
     [not found] ` <1395974461-12735-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-03-28  2:40   ` [PATCH 01/12] cgroup: update cgroup->subsys_mask to ->child_subsys_mask and restore cgroup_root->subsys_mask Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 02/12] cgroup: introduce effective cgroup_subsys_state Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 03/12] cgroup: implement cgroup->e_csets[] Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 04/12] cgroup: make css_next_child() skip missing csses Tejun Heo
2014-03-28  2:40   ` [PATCH 05/12] cgroup: reorganize css_task_iter Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 06/12] cgroup: teach css_task_iter about effective csses Tejun Heo
2014-03-28  2:40   ` [PATCH 07/12] cgroup: cgroup->subsys[] should be cleared after the css is offlined Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 08/12] cgroup: allow cgroup creation and suppress automatic css creation in the unified hierarchy Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 09/12] cgroup: add css_set->dfl_cgrp Tejun Heo
2014-03-28  2:40     ` Tejun Heo
2014-03-28  2:40   ` [PATCH 10/12] cgroup: update subsystem rebind restrictions Tejun Heo
2014-03-28  2:41   ` [PATCH 11/12] cgroup: prepare migration path for unified hierarchy Tejun Heo
2014-03-28  2:41   ` [PATCH 12/12] cgroup: implement dynamic subtree controller enable/disable on the default hierarchy Tejun Heo
2014-04-14 15:45   ` [PATCHSET cgroup/for-3.15] cgroup: implement unified hierarchy Vivek Goyal
2014-04-14 15:45     ` Vivek Goyal
     [not found]     ` <20140414154556.GA9552-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-04-14 17:52       ` Tejun Heo
2014-04-14 17:52         ` Tejun Heo
     [not found]         ` <20140414175236.GB15249-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-04-14 18:14           ` Vivek Goyal
2014-04-14 18:14             ` Vivek Goyal
     [not found]             ` <20140414181421.GC9552-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-04-14 19:21               ` Tejun Heo
2014-04-14 19:21                 ` Tejun Heo
     [not found]                 ` <20140414192139.GB16835-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-04-15  2:58                   ` Li Zefan
2014-04-15  2:58                     ` Li Zefan
     [not found]                     ` <534CA050.8060709-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-04-15  4:57                       ` Tejun Heo
2014-04-15  4:57                         ` Tejun Heo
2014-04-30 10:57           ` Raghavendra KT
2014-04-30 10:57             ` Raghavendra KT
     [not found]             ` <CAC4Lta0qd2vW4ENSOpzK+0i06MorzfmsZZZuW9xUtpZ_gWA9gA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-02 15:12               ` Tejun Heo
2014-05-02 15:12                 ` Tejun Heo
2014-05-05 16:37                 ` Raghavendra KT
2014-05-05 16:37                   ` Raghavendra KT
2014-04-14 21:31   ` Tejun Heo
2014-04-14 21:31     ` Tejun Heo
2014-04-15 22:05   ` [PATCH 0.5/12] cgroup: cgroup_apply_cftypes() shouldn't skip the default hierarhcy Tejun Heo
2014-04-15 22:05 ` Tejun Heo
2014-04-15 22:05   ` Tejun Heo
     [not found]   ` <20140415220504.GA13099-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2014-04-15 22:05     ` Tejun Heo
2014-04-15 22:05       ` Tejun Heo
2014-04-14 21:36 [PATCHSET cgroup/for-3.16] cgroup: implement unified hierarchy, v2 Tejun Heo
     [not found] ` <1397511430-2673-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-04-14 21:37   ` [PATCH 11/12] cgroup: prepare migration path for unified hierarchy Tejun Heo
2014-04-14 21:37     ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395974461-12735-12-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.