linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET] cgroup: misc fixes and cleanups
@ 2016-02-22 23:05 Tejun Heo
  2016-02-22 23:05 ` [PATCH 1/6] cgroup: fix error return value of cgroup_addrm_files() Tejun Heo
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team

Hello,

This patchset contains the following six patches.  The first one is a
fix but should be safe to route through for-4.6.  The rest are misc
cleanups and improvements which don't cause notable behavior changes.

 0001-cgroup-fix-error-return-value-of-cgroup_addrm_files.patch
 0002-Revert-cgroup-add-cgroup_subsys-css_e_css_changed.patch
 0003-cgroup-s-child_subsys_mask-subtree_ss_mask.patch
 0004-cgroup-convert-for_each_subsys_which-to-do-while-sty.patch
 0005-cgroup-use-do_each_subsys_mask-where-applicable.patch
 0006-cgroup-make-cgroup-subsystem-masks-u16.patch

The patchset based on top of cgroup/for-4.6 223ffb29f972 ("cgroup:
provide cgroup_nov1= to disable controllers in v1 mounts") and is
available in the following git branch.

 git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-misc

diffstat follows.  I'll pull in the branch into cgroup/for-4.6
soonish.

 include/linux/cgroup-defs.h |   12 +-
 kernel/cgroup.c             |  217 +++++++++++++++++++-------------------------
 2 files changed, 102 insertions(+), 127 deletions(-)

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/6] cgroup: fix error return value of cgroup_addrm_files()
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-22 23:05 ` [PATCH 2/6] Revert "cgroup: add cgroup_subsys->css_e_css_changed()" Tejun Heo
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team, Tejun Heo

cgroup_addrm_files() incorrectly returned 0 after add failure.  Fix
it.

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

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7ad6191..68b032d 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3369,7 +3369,7 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
 			      bool is_add)
 {
 	struct cftype *cft, *cft_end = NULL;
-	int ret;
+	int ret = 0;
 
 	lockdep_assert_held(&cgroup_mutex);
 
@@ -3398,7 +3398,7 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
 			cgroup_rm_file(cgrp, cft);
 		}
 	}
-	return 0;
+	return ret;
 }
 
 static int cgroup_apply_cftypes(struct cftype *cfts, bool is_add)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/6] Revert "cgroup: add cgroup_subsys->css_e_css_changed()"
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
  2016-02-22 23:05 ` [PATCH 1/6] cgroup: fix error return value of cgroup_addrm_files() Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-22 23:05 ` [PATCH 3/6] cgroup: s/child_subsys_mask/subtree_ss_mask/ Tejun Heo
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team, Tejun Heo

This reverts commit 56c807ba4e91f0980567b6a69de239677879b17f.

cgroup_subsys->css_e_css_changed() was supposed to be used by cgroup
writeback support; however, the change to per-inode cgroup association
made it unnecessary and the callback doesn't have any user.  Remove
it.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 include/linux/cgroup-defs.h |  1 -
 kernel/cgroup.c             | 18 ------------------
 2 files changed, 19 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 789471d..4f3c0da 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -434,7 +434,6 @@ struct cgroup_subsys {
 	void (*css_released)(struct cgroup_subsys_state *css);
 	void (*css_free)(struct cgroup_subsys_state *css);
 	void (*css_reset)(struct cgroup_subsys_state *css);
-	void (*css_e_css_changed)(struct cgroup_subsys_state *css);
 
 	int (*can_attach)(struct cgroup_taskset *tset);
 	void (*cancel_attach)(struct cgroup_taskset *tset);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 68b032d..7727b6e 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3127,24 +3127,6 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 		}
 	}
 
-	/*
-	 * The effective csses of all the descendants (excluding @cgrp) may
-	 * have changed.  Subsystems can optionally subscribe to this event
-	 * by implementing ->css_e_css_changed() which is invoked if any of
-	 * the effective csses seen from the css's cgroup may have changed.
-	 */
-	for_each_subsys(ss, ssid) {
-		struct cgroup_subsys_state *this_css = cgroup_css(cgrp, ss);
-		struct cgroup_subsys_state *css;
-
-		if (!ss->css_e_css_changed || !this_css)
-			continue;
-
-		css_for_each_descendant_pre(css, this_css)
-			if (css != this_css)
-				ss->css_e_css_changed(css);
-	}
-
 	kernfs_activate(cgrp->kn);
 	ret = 0;
 out_unlock:
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/6] cgroup: s/child_subsys_mask/subtree_ss_mask/
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
  2016-02-22 23:05 ` [PATCH 1/6] cgroup: fix error return value of cgroup_addrm_files() Tejun Heo
  2016-02-22 23:05 ` [PATCH 2/6] Revert "cgroup: add cgroup_subsys->css_e_css_changed()" Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-22 23:05 ` [PATCH 4/6] cgroup: convert for_each_subsys_which() to do-while style Tejun Heo
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team, Tejun Heo

For consistency with cgroup->subtree_control.

* cgroup->child_subsys_mask -> cgroup->subtree_ss_mask
* cgroup_calc_child_subsys_mask() -> cgroup_calc_subtree_ss_mask()
* cgroup_refresh_child_subsys_mask() -> cgroup_refresh_subtree_ss_mask()

No functional changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 include/linux/cgroup-defs.h | 11 +++++------
 kernel/cgroup.c             | 48 ++++++++++++++++++++++-----------------------
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 4f3c0da..c68ae7f 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -253,13 +253,12 @@ struct cgroup {
 	/*
 	 * The bitmask of subsystems enabled on the child cgroups.
 	 * ->subtree_control is the one configured through
-	 * "cgroup.subtree_control" while ->child_subsys_mask is the
-	 * effective one which may have more subsystems enabled.
-	 * Controller knobs are made available iff it's enabled in
-	 * ->subtree_control.
+	 * "cgroup.subtree_control" while ->child_ss_mask is the effective
+	 * one which may have more subsystems enabled.  Controller knobs
+	 * are made available iff it's enabled in ->subtree_control.
 	 */
-	unsigned int subtree_control;
-	unsigned int child_subsys_mask;
+	unsigned long subtree_control;
+	unsigned long subtree_ss_mask;
 
 	/* Private pointers for each registered subsystem */
 	struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 7727b6e..f3cd67b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -391,10 +391,10 @@ static struct cgroup_subsys_state *cgroup_e_css(struct cgroup *cgrp,
 
 	/*
 	 * This function is used while updating css associations and thus
-	 * can't test the csses directly.  Use ->child_subsys_mask.
+	 * can't test the csses directly.  Use ->subtree_ss_mask.
 	 */
 	while (cgroup_parent(cgrp) &&
-	       !(cgroup_parent(cgrp)->child_subsys_mask & (1 << ss->id)))
+	       !(cgroup_parent(cgrp)->subtree_ss_mask & (1 << ss->id)))
 		cgrp = cgroup_parent(cgrp);
 
 	return cgroup_css(cgrp, ss);
@@ -1256,7 +1256,7 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
 }
 
 /**
- * cgroup_calc_child_subsys_mask - calculate child_subsys_mask
+ * cgroup_calc_subtree_ss_mask - calculate subtree_ss_mask
  * @cgrp: the target cgroup
  * @subtree_control: the new subtree_control mask to consider
  *
@@ -1268,8 +1268,8 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
  * @subtree_control is to be applied to @cgrp.  The returned mask is always
  * a superset of @subtree_control and follows the usual hierarchy rules.
  */
-static unsigned long cgroup_calc_child_subsys_mask(struct cgroup *cgrp,
-						  unsigned long subtree_control)
+static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
+						 unsigned long subtree_control)
 {
 	struct cgroup *parent = cgroup_parent(cgrp);
 	unsigned long cur_ss_mask = subtree_control;
@@ -1293,7 +1293,7 @@ static unsigned long cgroup_calc_child_subsys_mask(struct cgroup *cgrp,
 		 * to non-default hierarchies.
 		 */
 		if (parent)
-			new_ss_mask &= parent->child_subsys_mask;
+			new_ss_mask &= parent->subtree_ss_mask;
 		else
 			new_ss_mask &= cgrp->root->subsys_mask;
 
@@ -1306,16 +1306,16 @@ static unsigned long cgroup_calc_child_subsys_mask(struct cgroup *cgrp,
 }
 
 /**
- * cgroup_refresh_child_subsys_mask - update child_subsys_mask
+ * cgroup_refresh_subtree_ss_mask - update subtree_ss_mask
  * @cgrp: the target cgroup
  *
- * Update @cgrp->child_subsys_mask according to the current
- * @cgrp->subtree_control using cgroup_calc_child_subsys_mask().
+ * Update @cgrp->subtree_ss_mask according to the current
+ * @cgrp->subtree_control using cgroup_calc_subtree_ss_mask().
  */
-static void cgroup_refresh_child_subsys_mask(struct cgroup *cgrp)
+static void cgroup_refresh_subtree_ss_mask(struct cgroup *cgrp)
 {
-	cgrp->child_subsys_mask =
-		cgroup_calc_child_subsys_mask(cgrp, cgrp->subtree_control);
+	cgrp->subtree_ss_mask =
+		cgroup_calc_subtree_ss_mask(cgrp, cgrp->subtree_control);
 }
 
 /**
@@ -1542,7 +1542,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 
 		src_root->subsys_mask &= ~(1 << ssid);
 		scgrp->subtree_control &= ~(1 << ssid);
-		cgroup_refresh_child_subsys_mask(scgrp);
+		cgroup_refresh_subtree_ss_mask(scgrp);
 
 		/* default hierarchy doesn't enable controllers by default */
 		dst_root->subsys_mask |= 1 << ssid;
@@ -1550,7 +1550,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 			static_branch_enable(cgroup_subsys_on_dfl_key[ssid]);
 		} else {
 			dcgrp->subtree_control |= 1 << ssid;
-			cgroup_refresh_child_subsys_mask(dcgrp);
+			cgroup_refresh_subtree_ss_mask(dcgrp);
 			static_branch_disable(cgroup_subsys_on_dfl_key[ssid]);
 		}
 
@@ -2523,11 +2523,11 @@ static int cgroup_migrate_prepare_dst(struct cgroup *dst_cgrp,
 	lockdep_assert_held(&cgroup_mutex);
 
 	/*
-	 * Except for the root, child_subsys_mask must be zero for a cgroup
+	 * Except for the root, subtree_ss_mask must be zero for a cgroup
 	 * with tasks so that child cgroups don't compete against tasks.
 	 */
 	if (dst_cgrp && cgroup_on_dfl(dst_cgrp) && cgroup_parent(dst_cgrp) &&
-	    dst_cgrp->child_subsys_mask)
+	    dst_cgrp->subtree_ss_mask)
 		return -EBUSY;
 
 	/* look up the dst cset for each src cset and link it to src */
@@ -2880,7 +2880,7 @@ static int cgroup_subtree_control_show(struct seq_file *seq, void *v)
  * cgroup_update_dfl_csses - update css assoc of a subtree in default hierarchy
  * @cgrp: root of the subtree to update csses for
  *
- * @cgrp's child_subsys_mask has changed and its subtree's (self excluded)
+ * @cgrp's subtree_ss_mask has changed and its subtree's (self excluded)
  * css associations need to be updated accordingly.  This function looks up
  * all css_sets which are attached to the subtree, creates the matching
  * updated css_sets and migrates the tasks to the new ones.
@@ -2902,7 +2902,7 @@ static int cgroup_update_dfl_csses(struct cgroup *cgrp)
 	css_for_each_descendant_pre(css, cgroup_css(cgrp, NULL)) {
 		struct cgrp_cset_link *link;
 
-		/* self is not affected by child_subsys_mask change */
+		/* self is not affected by subtree_ss_mask change */
 		if (css->cgroup == cgrp)
 			continue;
 
@@ -3034,9 +3034,9 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 * depending on subsystem dependencies.
 	 */
 	old_sc = cgrp->subtree_control;
-	old_ss = cgrp->child_subsys_mask;
+	old_ss = cgrp->subtree_ss_mask;
 	new_sc = (old_sc | enable) & ~disable;
-	new_ss = cgroup_calc_child_subsys_mask(cgrp, new_sc);
+	new_ss = cgroup_calc_subtree_ss_mask(cgrp, new_sc);
 
 	css_enable = ~old_ss & new_ss;
 	css_disable = old_ss & ~new_ss;
@@ -3069,7 +3069,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	}
 
 	cgrp->subtree_control = new_sc;
-	cgrp->child_subsys_mask = new_ss;
+	cgrp->subtree_ss_mask = new_ss;
 
 	/*
 	 * Create new csses or make the existing ones visible.  A css is
@@ -3135,7 +3135,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 
 err_undo_css:
 	cgrp->subtree_control = old_sc;
-	cgrp->child_subsys_mask = old_ss;
+	cgrp->subtree_ss_mask = old_ss;
 
 	for_each_subsys(ss, ssid) {
 		if (!(enable & (1 << ssid)))
@@ -4969,7 +4969,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 
 	/* let's create and online css's */
 	for_each_subsys(ss, ssid) {
-		if (parent->child_subsys_mask & (1 << ssid)) {
+		if (parent->subtree_ss_mask & (1 << ssid)) {
 			ret = create_css(cgrp, ss,
 					 parent->subtree_control & (1 << ssid));
 			if (ret)
@@ -4983,7 +4983,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 	 */
 	if (!cgroup_on_dfl(cgrp)) {
 		cgrp->subtree_control = parent->subtree_control;
-		cgroup_refresh_child_subsys_mask(cgrp);
+		cgroup_refresh_subtree_ss_mask(cgrp);
 	}
 
 	kernfs_activate(kn);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/6] cgroup: convert for_each_subsys_which() to do-while style
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (2 preceding siblings ...)
  2016-02-22 23:05 ` [PATCH 3/6] cgroup: s/child_subsys_mask/subtree_ss_mask/ Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-22 23:05 ` [PATCH 5/6] cgroup: use do_each_subsys_mask() where applicable Tejun Heo
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes
  Cc: cgroups, linux-kernel, kernel-team, Tejun Heo, Aleksa Sarai

for_each_subsys_which() allows iterating subsystems specified in a
subsystem bitmask; unfortunately, it requires the mask to be an
unsigned long l-value which can be inconvenient and makes it awkward
to use a smaller type for subsystem masks.

This patch converts for_each_subsy_which() to do-while style which
allows it to drop the l-value requirement.  The new iterator is named
do_each_subsys_mask() / while_each_subsys_mask().

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Aleksa Sarai <cyphar@cyphar.com>
---
 kernel/cgroup.c | 72 ++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 32 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index f3cd67b..5d10298 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -514,22 +514,28 @@ static int notify_on_release(const struct cgroup *cgrp)
 	     (((ss) = cgroup_subsys[ssid]) || true); (ssid)++)
 
 /**
- * for_each_subsys_which - filter for_each_subsys with a bitmask
+ * do_each_subsys_mask - filter for_each_subsys with a bitmask
  * @ss: the iteration cursor
  * @ssid: the index of @ss, CGROUP_SUBSYS_COUNT after reaching the end
- * @ss_maskp: a pointer to the bitmask
+ * @ss_mask: the bitmask
  *
  * The block will only run for cases where the ssid-th bit (1 << ssid) of
- * mask is set to 1.
+ * @ss_mask is set.
  */
-#define for_each_subsys_which(ss, ssid, ss_maskp)			\
-	if (!CGROUP_SUBSYS_COUNT) /* to avoid spurious gcc warning */	\
+#define do_each_subsys_mask(ss, ssid, ss_mask) do {			\
+	unsigned long __ss_mask = (ss_mask);				\
+	if (!CGROUP_SUBSYS_COUNT) { /* to avoid spurious gcc warning */	\
 		(ssid) = 0;						\
-	else								\
-		for_each_set_bit(ssid, ss_maskp, CGROUP_SUBSYS_COUNT)	\
-			if (((ss) = cgroup_subsys[ssid]) && false)	\
-				break;					\
-			else
+		break;							\
+	}								\
+	for_each_set_bit(ssid, &__ss_mask, CGROUP_SUBSYS_COUNT) {	\
+		(ss) = cgroup_subsys[ssid];				\
+		{
+
+#define while_each_subsys_mask()					\
+		}							\
+	}								\
+} while (false)
 
 /* iterate across the hierarchies */
 #define for_each_root(root)						\
@@ -1284,8 +1290,9 @@ static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
 	while (true) {
 		unsigned long new_ss_mask = cur_ss_mask;
 
-		for_each_subsys_which(ss, ssid, &cur_ss_mask)
+		do_each_subsys_mask(ss, ssid, cur_ss_mask) {
 			new_ss_mask |= ss->depends_on;
+		} while_each_subsys_mask();
 
 		/*
 		 * Mask out subsystems which aren't available.  This can
@@ -1469,7 +1476,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 
 	lockdep_assert_held(&cgroup_mutex);
 
-	for_each_subsys_which(ss, ssid, &ss_mask) {
+	do_each_subsys_mask(ss, ssid, ss_mask) {
 		/* if @ss has non-root csses attached to it, can't move */
 		if (css_next_child(NULL, cgroup_css(&ss->root->cgrp, ss)))
 			return -EBUSY;
@@ -1477,14 +1484,14 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 		/* can't move between two non-dummy roots either */
 		if (ss->root != &cgrp_dfl_root && dst_root != &cgrp_dfl_root)
 			return -EBUSY;
-	}
+	} while_each_subsys_mask();
 
 	/* skip creating root files on dfl_root for inhibited subsystems */
 	tmp_ss_mask = ss_mask;
 	if (dst_root == &cgrp_dfl_root)
 		tmp_ss_mask &= ~cgrp_dfl_root_inhibit_ss_mask;
 
-	for_each_subsys_which(ss, ssid, &tmp_ss_mask) {
+	do_each_subsys_mask(ss, ssid, tmp_ss_mask) {
 		struct cgroup *scgrp = &ss->root->cgrp;
 		int tssid;
 
@@ -1507,19 +1514,19 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 			continue;
 		}
 
-		for_each_subsys_which(ss, tssid, &tmp_ss_mask) {
+		do_each_subsys_mask(ss, tssid, tmp_ss_mask) {
 			if (tssid == ssid)
 				break;
 			css_clear_dir(cgroup_css(scgrp, ss), dcgrp);
-		}
+		} while_each_subsys_mask();
 		return ret;
-	}
+	} while_each_subsys_mask();
 
 	/*
 	 * Nothing can fail from this point on.  Remove files for the
 	 * removed subsystems and rebind each subsystem.
 	 */
-	for_each_subsys_which(ss, ssid, &ss_mask) {
+	do_each_subsys_mask(ss, ssid, ss_mask) {
 		struct cgroup_root *src_root = ss->root;
 		struct cgroup *scgrp = &src_root->cgrp;
 		struct cgroup_subsys_state *css = cgroup_css(scgrp, ss);
@@ -1556,7 +1563,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 
 		if (ss->bind)
 			ss->bind(css);
-	}
+	} while_each_subsys_mask();
 
 	kernfs_activate(dcgrp->kn);
 	return 0;
@@ -2838,12 +2845,12 @@ static void cgroup_print_ss_mask(struct seq_file *seq, unsigned long ss_mask)
 	bool printed = false;
 	int ssid;
 
-	for_each_subsys_which(ss, ssid, &ss_mask) {
+	do_each_subsys_mask(ss, ssid, ss_mask) {
 		if (printed)
 			seq_putc(seq, ' ');
 		seq_printf(seq, "%s", ss->name);
 		printed = true;
-	}
+	} while_each_subsys_mask();
 	if (printed)
 		seq_putc(seq, '\n');
 }
@@ -2956,11 +2963,9 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 */
 	buf = strstrip(buf);
 	while ((tok = strsep(&buf, " "))) {
-		unsigned long tmp_ss_mask = ~cgrp_dfl_root_inhibit_ss_mask;
-
 		if (tok[0] == '\0')
 			continue;
-		for_each_subsys_which(ss, ssid, &tmp_ss_mask) {
+		do_each_subsys_mask(ss, ssid, ~cgrp_dfl_root_inhibit_ss_mask) {
 			if (!cgroup_ssid_enabled(ssid) ||
 			    strcmp(tok + 1, ss->name))
 				continue;
@@ -2975,7 +2980,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 				return -EINVAL;
 			}
 			break;
-		}
+		} while_each_subsys_mask();
 		if (ssid == CGROUP_SUBSYS_COUNT)
 			return -EINVAL;
 	}
@@ -3049,7 +3054,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 * still around.  In such cases, wait till it's gone using
 	 * offline_waitq.
 	 */
-	for_each_subsys_which(ss, ssid, &css_enable) {
+	do_each_subsys_mask(ss, ssid, css_enable) {
 		cgroup_for_each_live_child(child, cgrp) {
 			DEFINE_WAIT(wait);
 
@@ -3066,7 +3071,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 
 			return restart_syscall();
 		}
-	}
+	} while_each_subsys_mask();
 
 	cgrp->subtree_control = new_sc;
 	cgrp->subtree_ss_mask = new_ss;
@@ -5509,11 +5514,11 @@ int cgroup_can_fork(struct task_struct *child)
 	struct cgroup_subsys *ss;
 	int i, j, ret;
 
-	for_each_subsys_which(ss, i, &have_canfork_callback) {
+	do_each_subsys_mask(ss, i, have_canfork_callback) {
 		ret = ss->can_fork(child);
 		if (ret)
 			goto out_revert;
-	}
+	} while_each_subsys_mask();
 
 	return 0;
 
@@ -5598,8 +5603,9 @@ void cgroup_post_fork(struct task_struct *child)
 	 * css_set; otherwise, @child might change state between ->fork()
 	 * and addition to css_set.
 	 */
-	for_each_subsys_which(ss, i, &have_fork_callback)
+	do_each_subsys_mask(ss, i, have_fork_callback) {
 		ss->fork(child);
+	} while_each_subsys_mask();
 }
 
 /**
@@ -5642,8 +5648,9 @@ void cgroup_exit(struct task_struct *tsk)
 	}
 
 	/* see cgroup_post_fork() for details */
-	for_each_subsys_which(ss, i, &have_exit_callback)
+	do_each_subsys_mask(ss, i, have_exit_callback) {
 		ss->exit(tsk);
+	} while_each_subsys_mask();
 }
 
 void cgroup_free(struct task_struct *task)
@@ -5652,8 +5659,9 @@ void cgroup_free(struct task_struct *task)
 	struct cgroup_subsys *ss;
 	int ssid;
 
-	for_each_subsys_which(ss, ssid, &have_free_callback)
+	do_each_subsys_mask(ss, ssid, have_free_callback) {
 		ss->free(task);
+	} while_each_subsys_mask();
 
 	put_css_set(cset);
 }
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/6] cgroup: use do_each_subsys_mask() where applicable
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (3 preceding siblings ...)
  2016-02-22 23:05 ` [PATCH 4/6] cgroup: convert for_each_subsys_which() to do-while style Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-22 23:05 ` [PATCH 6/6] cgroup: make cgroup subsystem masks u16 Tejun Heo
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team, Tejun Heo

There are several places in cgroup_subtree_control_write() which can
use do_each_subsys_mask() instead of manual mask testing.  Use it.

No functional changes.

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

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 5d10298..1e561bd 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -3082,10 +3082,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 * dependency.  An invisible css is made visible when the userland
 	 * explicitly enables it.
 	 */
-	for_each_subsys(ss, ssid) {
-		if (!(enable & (1 << ssid)))
-			continue;
-
+	do_each_subsys_mask(ss, ssid, enable) {
 		cgroup_for_each_live_child(child, cgrp) {
 			if (css_enable & (1 << ssid))
 				ret = create_css(child, ss,
@@ -3096,7 +3093,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 			if (ret)
 				goto err_undo_css;
 		}
-	}
+	} while_each_subsys_mask();
 
 	/*
 	 * At this point, cgroup_e_css() results reflect the new csses
@@ -3115,10 +3112,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	 * state if it's made visible again later.  Controllers which may
 	 * be depended upon should provide ->css_reset() for this purpose.
 	 */
-	for_each_subsys(ss, ssid) {
-		if (!(disable & (1 << ssid)))
-			continue;
-
+	do_each_subsys_mask(ss, ssid, disable) {
 		cgroup_for_each_live_child(child, cgrp) {
 			struct cgroup_subsys_state *css = cgroup_css(child, ss);
 
@@ -3130,7 +3124,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 					ss->css_reset(css);
 			}
 		}
-	}
+	} while_each_subsys_mask();
 
 	kernfs_activate(cgrp->kn);
 	ret = 0;
@@ -3142,10 +3136,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 	cgrp->subtree_control = old_sc;
 	cgrp->subtree_ss_mask = old_ss;
 
-	for_each_subsys(ss, ssid) {
-		if (!(enable & (1 << ssid)))
-			continue;
-
+	do_each_subsys_mask(ss, ssid, enable) {
 		cgroup_for_each_live_child(child, cgrp) {
 			struct cgroup_subsys_state *css = cgroup_css(child, ss);
 
@@ -3157,7 +3148,7 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 			else
 				css_clear_dir(css, NULL);
 		}
-	}
+	} while_each_subsys_mask();
 	goto out_unlock;
 }
 
@@ -4973,14 +4964,12 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 		goto out_destroy;
 
 	/* let's create and online css's */
-	for_each_subsys(ss, ssid) {
-		if (parent->subtree_ss_mask & (1 << ssid)) {
-			ret = create_css(cgrp, ss,
-					 parent->subtree_control & (1 << ssid));
-			if (ret)
-				goto out_destroy;
-		}
-	}
+	do_each_subsys_mask(ss, ssid, parent->subtree_ss_mask) {
+		ret = create_css(cgrp, ss,
+				 parent->subtree_control & (1 << ssid));
+		if (ret)
+			goto out_destroy;
+	} while_each_subsys_mask();
 
 	/*
 	 * On the default hierarchy, a child doesn't automatically inherit
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/6] cgroup: make cgroup subsystem masks u16
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (4 preceding siblings ...)
  2016-02-22 23:05 ` [PATCH 5/6] cgroup: use do_each_subsys_mask() where applicable Tejun Heo
@ 2016-02-22 23:05 ` Tejun Heo
  2016-02-23  1:33   ` Johannes Weiner
  2016-02-23  3:27   ` [PATCH v2 " Tejun Heo
  2016-02-23  1:34 ` [PATCHSET] cgroup: misc fixes and cleanups Johannes Weiner
                   ` (2 subsequent siblings)
  8 siblings, 2 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-22 23:05 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team, Tejun Heo

After the recent do_each_subsys_mask() conversion, there's no reason
to use ulong for subsystem masks.  We'll be adding more subsystem
masks to persistent data structures, let's reduce its size to u16
which should be enough for now and the foreseeable future.

This doesn't create any noticeable behavior differences.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 include/linux/cgroup-defs.h |  4 ++--
 kernel/cgroup.c             | 46 ++++++++++++++++++++++-----------------------
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index c68ae7f..0abf6aa 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -257,8 +257,8 @@ struct cgroup {
 	 * one which may have more subsystems enabled.  Controller knobs
 	 * are made available iff it's enabled in ->subtree_control.
 	 */
-	unsigned long subtree_control;
-	unsigned long subtree_ss_mask;
+	u16 subtree_control;
+	u16 subtree_ss_mask;
 
 	/* Private pointers for each registered subsystem */
 	struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 1e561bd..a2f81ef 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -184,7 +184,7 @@ static bool cgrp_dfl_root_visible;
 static unsigned long cgroup_no_v1_mask;
 
 /* some controllers are not supported in the default hierarchy */
-static unsigned long cgrp_dfl_root_inhibit_ss_mask;
+static u16 cgrp_dfl_root_inhibit_ss_mask;
 
 /* The list of hierarchy roots */
 
@@ -208,19 +208,18 @@ static u64 css_serial_nr_next = 1;
  * fork/exit handlers to call. This avoids us having to do extra work in the
  * fork/exit path to check which subsystems have fork/exit callbacks.
  */
-static unsigned long have_fork_callback __read_mostly;
-static unsigned long have_exit_callback __read_mostly;
-static unsigned long have_free_callback __read_mostly;
+static u16 have_fork_callback __read_mostly;
+static u16 have_exit_callback __read_mostly;
+static u16 have_free_callback __read_mostly;
 
 /* Ditto for the can_fork callback. */
-static unsigned long have_canfork_callback __read_mostly;
+static u16 have_canfork_callback __read_mostly;
 
 static struct file_system_type cgroup2_fs_type;
 static struct cftype cgroup_dfl_base_files[];
 static struct cftype cgroup_legacy_base_files[];
 
-static int rebind_subsystems(struct cgroup_root *dst_root,
-			     unsigned long ss_mask);
+static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
 static void css_task_iter_advance(struct css_task_iter *it);
 static int cgroup_destroy_locked(struct cgroup *cgrp);
 static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss,
@@ -1274,11 +1273,10 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
  * @subtree_control is to be applied to @cgrp.  The returned mask is always
  * a superset of @subtree_control and follows the usual hierarchy rules.
  */
-static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
-						 unsigned long subtree_control)
+static u16 cgroup_calc_subtree_ss_mask(struct cgroup *cgrp, u16 subtree_control)
 {
 	struct cgroup *parent = cgroup_parent(cgrp);
-	unsigned long cur_ss_mask = subtree_control;
+	u16 cur_ss_mask = subtree_control;
 	struct cgroup_subsys *ss;
 	int ssid;
 
@@ -1288,7 +1286,7 @@ static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
 		return cur_ss_mask;
 
 	while (true) {
-		unsigned long new_ss_mask = cur_ss_mask;
+		u16 new_ss_mask = cur_ss_mask;
 
 		do_each_subsys_mask(ss, ssid, cur_ss_mask) {
 			new_ss_mask |= ss->depends_on;
@@ -1466,12 +1464,11 @@ static int css_populate_dir(struct cgroup_subsys_state *css,
 	return ret;
 }
 
-static int rebind_subsystems(struct cgroup_root *dst_root,
-			     unsigned long ss_mask)
+static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
 {
 	struct cgroup *dcgrp = &dst_root->cgrp;
 	struct cgroup_subsys *ss;
-	unsigned long tmp_ss_mask;
+	u16 tmp_ss_mask;
 	int ssid, i, ret;
 
 	lockdep_assert_held(&cgroup_mutex);
@@ -1507,7 +1504,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 		 */
 		if (dst_root == &cgrp_dfl_root) {
 			if (cgrp_dfl_root_visible) {
-				pr_warn("failed to create files (%d) while rebinding 0x%lx to default root\n",
+				pr_warn("failed to create files (%d) while rebinding 0x%x to default root\n",
 					ret, ss_mask);
 				pr_warn("you may retry by moving them to a different hierarchy and unbinding\n");
 			}
@@ -1599,7 +1596,7 @@ static int cgroup_show_options(struct seq_file *seq,
 }
 
 struct cgroup_sb_opts {
-	unsigned long subsys_mask;
+	u16 subsys_mask;
 	unsigned int flags;
 	char *release_agent;
 	bool cpuset_clone_children;
@@ -1612,13 +1609,13 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 {
 	char *token, *o = data;
 	bool all_ss = false, one_ss = false;
-	unsigned long mask = -1UL;
+	u16 mask = U16_MAX;
 	struct cgroup_subsys *ss;
 	int nr_opts = 0;
 	int i;
 
 #ifdef CONFIG_CPUSETS
-	mask = ~(1U << cpuset_cgrp_id);
+	mask = ~((u16)1 << cpuset_cgrp_id);
 #endif
 
 	memset(opts, 0, sizeof(*opts));
@@ -1745,7 +1742,7 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
 	int ret = 0;
 	struct cgroup_root *root = cgroup_root_from_kf(kf_root);
 	struct cgroup_sb_opts opts;
-	unsigned long added_mask, removed_mask;
+	u16 added_mask, removed_mask;
 
 	if (root == &cgrp_dfl_root) {
 		pr_err("remount is not allowed\n");
@@ -1893,7 +1890,7 @@ static void init_cgroup_root(struct cgroup_root *root,
 		set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
 }
 
-static int cgroup_setup_root(struct cgroup_root *root, unsigned long ss_mask)
+static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
 {
 	LIST_HEAD(tmp_links);
 	struct cgroup *root_cgrp = &root->cgrp;
@@ -2839,7 +2836,7 @@ static int cgroup_sane_behavior_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
-static void cgroup_print_ss_mask(struct seq_file *seq, unsigned long ss_mask)
+static void cgroup_print_ss_mask(struct seq_file *seq, u16 ss_mask)
 {
 	struct cgroup_subsys *ss;
 	bool printed = false;
@@ -2950,8 +2947,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 					    char *buf, size_t nbytes,
 					    loff_t off)
 {
-	unsigned long enable = 0, disable = 0;
-	unsigned long css_enable, css_disable, old_sc, new_sc, old_ss, new_ss;
+	u16 enable = 0, disable = 0;
+	u16 css_enable, css_disable, old_sc, new_sc, old_ss, new_ss;
 	struct cgroup *cgrp, *child;
 	struct cgroup_subsys *ss;
 	char *tok;
@@ -5255,7 +5252,7 @@ int __init cgroup_init_early(void)
 	return 0;
 }
 
-static unsigned long cgroup_disable_mask __initdata;
+static u16 cgroup_disable_mask __initdata;
 
 /**
  * cgroup_init - cgroup initialization
@@ -5269,6 +5266,7 @@ int __init cgroup_init(void)
 	unsigned long key;
 	int ssid;
 
+	BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
 	BUG_ON(percpu_init_rwsem(&cgroup_threadgroup_rwsem));
 	BUG_ON(cgroup_init_cftypes(NULL, cgroup_dfl_base_files));
 	BUG_ON(cgroup_init_cftypes(NULL, cgroup_legacy_base_files));
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 6/6] cgroup: make cgroup subsystem masks u16
  2016-02-22 23:05 ` [PATCH 6/6] cgroup: make cgroup subsystem masks u16 Tejun Heo
@ 2016-02-23  1:33   ` Johannes Weiner
  2016-02-23  3:27   ` [PATCH v2 " Tejun Heo
  1 sibling, 0 replies; 12+ messages in thread
From: Johannes Weiner @ 2016-02-23  1:33 UTC (permalink / raw)
  To: Tejun Heo; +Cc: lizefan, cgroups, linux-kernel, kernel-team

On Mon, Feb 22, 2016 at 06:05:49PM -0500, Tejun Heo wrote:
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -184,7 +184,7 @@ static bool cgrp_dfl_root_visible;
>  static unsigned long cgroup_no_v1_mask;

^ This one can be turned into a u16 too.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHSET] cgroup: misc fixes and cleanups
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (5 preceding siblings ...)
  2016-02-22 23:05 ` [PATCH 6/6] cgroup: make cgroup subsystem masks u16 Tejun Heo
@ 2016-02-23  1:34 ` Johannes Weiner
  2016-02-23  3:27 ` Tejun Heo
  2016-02-23  3:55 ` Zefan Li
  8 siblings, 0 replies; 12+ messages in thread
From: Johannes Weiner @ 2016-02-23  1:34 UTC (permalink / raw)
  To: Tejun Heo; +Cc: lizefan, cgroups, linux-kernel, kernel-team

On Mon, Feb 22, 2016 at 06:05:43PM -0500, Tejun Heo wrote:
> This patchset contains the following six patches.  The first one is a
> fix but should be safe to route through for-4.6.  The rest are misc
> cleanups and improvements which don't cause notable behavior changes.

These look good to me.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 6/6] cgroup: make cgroup subsystem masks u16
  2016-02-22 23:05 ` [PATCH 6/6] cgroup: make cgroup subsystem masks u16 Tejun Heo
  2016-02-23  1:33   ` Johannes Weiner
@ 2016-02-23  3:27   ` Tejun Heo
  1 sibling, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-23  3:27 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team

>From 6e5c830770f9045a17b1b931c3e11fbd5591e630 Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj@kernel.org>
Date: Mon, 22 Feb 2016 22:25:47 -0500

After the recent do_each_subsys_mask() conversion, there's no reason
to use ulong for subsystem masks.  We'll be adding more subsystem
masks to persistent data structures, let's reduce its size to u16
which should be enough for now and the foreseeable future.

This doesn't create any noticeable behavior differences.

v2: Johannes spotted that the initial patch missed cgroup_no_v1_mask.
    Converted.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
---
 include/linux/cgroup-defs.h |  4 ++--
 kernel/cgroup.c             | 50 ++++++++++++++++++++++-----------------------
 2 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index c68ae7f..0abf6aa 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -257,8 +257,8 @@ struct cgroup {
 	 * one which may have more subsystems enabled.  Controller knobs
 	 * are made available iff it's enabled in ->subtree_control.
 	 */
-	unsigned long subtree_control;
-	unsigned long subtree_ss_mask;
+	u16 subtree_control;
+	u16 subtree_ss_mask;
 
 	/* Private pointers for each registered subsystem */
 	struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT];
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 1e561bd..7669f68 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -181,10 +181,10 @@ EXPORT_SYMBOL_GPL(cgrp_dfl_root);
 static bool cgrp_dfl_root_visible;
 
 /* Controllers blocked by the commandline in v1 */
-static unsigned long cgroup_no_v1_mask;
+static u16 cgroup_no_v1_mask;
 
 /* some controllers are not supported in the default hierarchy */
-static unsigned long cgrp_dfl_root_inhibit_ss_mask;
+static u16 cgrp_dfl_root_inhibit_ss_mask;
 
 /* The list of hierarchy roots */
 
@@ -208,19 +208,18 @@ static u64 css_serial_nr_next = 1;
  * fork/exit handlers to call. This avoids us having to do extra work in the
  * fork/exit path to check which subsystems have fork/exit callbacks.
  */
-static unsigned long have_fork_callback __read_mostly;
-static unsigned long have_exit_callback __read_mostly;
-static unsigned long have_free_callback __read_mostly;
+static u16 have_fork_callback __read_mostly;
+static u16 have_exit_callback __read_mostly;
+static u16 have_free_callback __read_mostly;
 
 /* Ditto for the can_fork callback. */
-static unsigned long have_canfork_callback __read_mostly;
+static u16 have_canfork_callback __read_mostly;
 
 static struct file_system_type cgroup2_fs_type;
 static struct cftype cgroup_dfl_base_files[];
 static struct cftype cgroup_legacy_base_files[];
 
-static int rebind_subsystems(struct cgroup_root *dst_root,
-			     unsigned long ss_mask);
+static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask);
 static void css_task_iter_advance(struct css_task_iter *it);
 static int cgroup_destroy_locked(struct cgroup *cgrp);
 static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss,
@@ -1274,11 +1273,10 @@ static umode_t cgroup_file_mode(const struct cftype *cft)
  * @subtree_control is to be applied to @cgrp.  The returned mask is always
  * a superset of @subtree_control and follows the usual hierarchy rules.
  */
-static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
-						 unsigned long subtree_control)
+static u16 cgroup_calc_subtree_ss_mask(struct cgroup *cgrp, u16 subtree_control)
 {
 	struct cgroup *parent = cgroup_parent(cgrp);
-	unsigned long cur_ss_mask = subtree_control;
+	u16 cur_ss_mask = subtree_control;
 	struct cgroup_subsys *ss;
 	int ssid;
 
@@ -1288,7 +1286,7 @@ static unsigned long cgroup_calc_subtree_ss_mask(struct cgroup *cgrp,
 		return cur_ss_mask;
 
 	while (true) {
-		unsigned long new_ss_mask = cur_ss_mask;
+		u16 new_ss_mask = cur_ss_mask;
 
 		do_each_subsys_mask(ss, ssid, cur_ss_mask) {
 			new_ss_mask |= ss->depends_on;
@@ -1466,12 +1464,11 @@ static int css_populate_dir(struct cgroup_subsys_state *css,
 	return ret;
 }
 
-static int rebind_subsystems(struct cgroup_root *dst_root,
-			     unsigned long ss_mask)
+static int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask)
 {
 	struct cgroup *dcgrp = &dst_root->cgrp;
 	struct cgroup_subsys *ss;
-	unsigned long tmp_ss_mask;
+	u16 tmp_ss_mask;
 	int ssid, i, ret;
 
 	lockdep_assert_held(&cgroup_mutex);
@@ -1507,7 +1504,7 @@ static int rebind_subsystems(struct cgroup_root *dst_root,
 		 */
 		if (dst_root == &cgrp_dfl_root) {
 			if (cgrp_dfl_root_visible) {
-				pr_warn("failed to create files (%d) while rebinding 0x%lx to default root\n",
+				pr_warn("failed to create files (%d) while rebinding 0x%x to default root\n",
 					ret, ss_mask);
 				pr_warn("you may retry by moving them to a different hierarchy and unbinding\n");
 			}
@@ -1599,7 +1596,7 @@ static int cgroup_show_options(struct seq_file *seq,
 }
 
 struct cgroup_sb_opts {
-	unsigned long subsys_mask;
+	u16 subsys_mask;
 	unsigned int flags;
 	char *release_agent;
 	bool cpuset_clone_children;
@@ -1612,13 +1609,13 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 {
 	char *token, *o = data;
 	bool all_ss = false, one_ss = false;
-	unsigned long mask = -1UL;
+	u16 mask = U16_MAX;
 	struct cgroup_subsys *ss;
 	int nr_opts = 0;
 	int i;
 
 #ifdef CONFIG_CPUSETS
-	mask = ~(1U << cpuset_cgrp_id);
+	mask = ~((u16)1 << cpuset_cgrp_id);
 #endif
 
 	memset(opts, 0, sizeof(*opts));
@@ -1745,7 +1742,7 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
 	int ret = 0;
 	struct cgroup_root *root = cgroup_root_from_kf(kf_root);
 	struct cgroup_sb_opts opts;
-	unsigned long added_mask, removed_mask;
+	u16 added_mask, removed_mask;
 
 	if (root == &cgrp_dfl_root) {
 		pr_err("remount is not allowed\n");
@@ -1893,7 +1890,7 @@ static void init_cgroup_root(struct cgroup_root *root,
 		set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
 }
 
-static int cgroup_setup_root(struct cgroup_root *root, unsigned long ss_mask)
+static int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask)
 {
 	LIST_HEAD(tmp_links);
 	struct cgroup *root_cgrp = &root->cgrp;
@@ -2839,7 +2836,7 @@ static int cgroup_sane_behavior_show(struct seq_file *seq, void *v)
 	return 0;
 }
 
-static void cgroup_print_ss_mask(struct seq_file *seq, unsigned long ss_mask)
+static void cgroup_print_ss_mask(struct seq_file *seq, u16 ss_mask)
 {
 	struct cgroup_subsys *ss;
 	bool printed = false;
@@ -2950,8 +2947,8 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
 					    char *buf, size_t nbytes,
 					    loff_t off)
 {
-	unsigned long enable = 0, disable = 0;
-	unsigned long css_enable, css_disable, old_sc, new_sc, old_ss, new_ss;
+	u16 enable = 0, disable = 0;
+	u16 css_enable, css_disable, old_sc, new_sc, old_ss, new_ss;
 	struct cgroup *cgrp, *child;
 	struct cgroup_subsys *ss;
 	char *tok;
@@ -5255,7 +5252,7 @@ int __init cgroup_init_early(void)
 	return 0;
 }
 
-static unsigned long cgroup_disable_mask __initdata;
+static u16 cgroup_disable_mask __initdata;
 
 /**
  * cgroup_init - cgroup initialization
@@ -5269,6 +5266,7 @@ int __init cgroup_init(void)
 	unsigned long key;
 	int ssid;
 
+	BUILD_BUG_ON(CGROUP_SUBSYS_COUNT > 16);
 	BUG_ON(percpu_init_rwsem(&cgroup_threadgroup_rwsem));
 	BUG_ON(cgroup_init_cftypes(NULL, cgroup_dfl_base_files));
 	BUG_ON(cgroup_init_cftypes(NULL, cgroup_legacy_base_files));
@@ -5754,7 +5752,7 @@ static int __init cgroup_no_v1(char *str)
 			continue;
 
 		if (!strcmp(token, "all")) {
-			cgroup_no_v1_mask = ~0UL;
+			cgroup_no_v1_mask = U16_MAX;
 			break;
 		}
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCHSET] cgroup: misc fixes and cleanups
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (6 preceding siblings ...)
  2016-02-23  1:34 ` [PATCHSET] cgroup: misc fixes and cleanups Johannes Weiner
@ 2016-02-23  3:27 ` Tejun Heo
  2016-02-23  3:55 ` Zefan Li
  8 siblings, 0 replies; 12+ messages in thread
From: Tejun Heo @ 2016-02-23  3:27 UTC (permalink / raw)
  To: lizefan, hannes; +Cc: cgroups, linux-kernel, kernel-team

On Mon, Feb 22, 2016 at 06:05:43PM -0500, Tejun Heo wrote:
>  0001-cgroup-fix-error-return-value-of-cgroup_addrm_files.patch
>  0002-Revert-cgroup-add-cgroup_subsys-css_e_css_changed.patch
>  0003-cgroup-s-child_subsys_mask-subtree_ss_mask.patch
>  0004-cgroup-convert-for_each_subsys_which-to-do-while-sty.patch
>  0005-cgroup-use-do_each_subsys_mask-where-applicable.patch
>  0006-cgroup-make-cgroup-subsystem-masks-u16.patch

Applied 1-6 to cgroup/for-4.6.

-- 
tejun

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHSET] cgroup: misc fixes and cleanups
  2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
                   ` (7 preceding siblings ...)
  2016-02-23  3:27 ` Tejun Heo
@ 2016-02-23  3:55 ` Zefan Li
  8 siblings, 0 replies; 12+ messages in thread
From: Zefan Li @ 2016-02-23  3:55 UTC (permalink / raw)
  To: Tejun Heo, hannes; +Cc: cgroups, linux-kernel, kernel-team

On 2016/2/23 7:05, Tejun Heo wrote:
> Hello,
> 
> This patchset contains the following six patches.  The first one is a
> fix but should be safe to route through for-4.6.  The rest are misc
> cleanups and improvements which don't cause notable behavior changes.
> 
>  0001-cgroup-fix-error-return-value-of-cgroup_addrm_files.patch
>  0002-Revert-cgroup-add-cgroup_subsys-css_e_css_changed.patch
>  0003-cgroup-s-child_subsys_mask-subtree_ss_mask.patch
>  0004-cgroup-convert-for_each_subsys_which-to-do-while-sty.patch
>  0005-cgroup-use-do_each_subsys_mask-where-applicable.patch
>  0006-cgroup-make-cgroup-subsystem-masks-u16.patch
> 
> The patchset based on top of cgroup/for-4.6 223ffb29f972 ("cgroup:
> provide cgroup_nov1= to disable controllers in v1 mounts") and is
> available in the following git branch.
> 
>  git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-misc
> 
> diffstat follows.  I'll pull in the branch into cgroup/for-4.6
> soonish.
> 
>  include/linux/cgroup-defs.h |   12 +-
>  kernel/cgroup.c             |  217 +++++++++++++++++++-------------------------
>  2 files changed, 102 insertions(+), 127 deletions(-)
> 

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-02-23  3:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-22 23:05 [PATCHSET] cgroup: misc fixes and cleanups Tejun Heo
2016-02-22 23:05 ` [PATCH 1/6] cgroup: fix error return value of cgroup_addrm_files() Tejun Heo
2016-02-22 23:05 ` [PATCH 2/6] Revert "cgroup: add cgroup_subsys->css_e_css_changed()" Tejun Heo
2016-02-22 23:05 ` [PATCH 3/6] cgroup: s/child_subsys_mask/subtree_ss_mask/ Tejun Heo
2016-02-22 23:05 ` [PATCH 4/6] cgroup: convert for_each_subsys_which() to do-while style Tejun Heo
2016-02-22 23:05 ` [PATCH 5/6] cgroup: use do_each_subsys_mask() where applicable Tejun Heo
2016-02-22 23:05 ` [PATCH 6/6] cgroup: make cgroup subsystem masks u16 Tejun Heo
2016-02-23  1:33   ` Johannes Weiner
2016-02-23  3:27   ` [PATCH v2 " Tejun Heo
2016-02-23  1:34 ` [PATCHSET] cgroup: misc fixes and cleanups Johannes Weiner
2016-02-23  3:27 ` Tejun Heo
2016-02-23  3:55 ` Zefan Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).