Skip to contentSkip to conversation

Add cgroup support for enabling controllers at boot time (v2)

PATCH In review Balbir Singh 4 participants 11 messages Mar 7, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add cgroup support for enabling controllers at boot time (v2)

From: Paul Menage <[email protected]>

Changelog v2

1. Add enabled support in /proc/cgroups
2. Add support for parsing of several controller names

The effects of cgroup_disable=foo are:

- foo isn't auto-mounted if you mount all cgroups in a single hierarchy
- foo isn't visible as an individually mountable subsystem

As a result there will only ever be one call to foo->create(), at init time; all processes will stay in this group, and the group will never be mounted on a visible hierarchy. Any additional effects (e.g. not allocating metadata) are up to the foo subsystem.

This doesn't handle early_init subsystems (their "disabled" bit isn't set be, but it could easily be extended to do so if any of the early_init systems wanted it - I think it would just involve some nastier parameter processing since it would occur before the command-line argument parser had been run.

---

 Documentation/kernel-parameters.txt |    4 +++
 include/linux/cgroup.h              |    1 
 kernel/cgroup.c                     |   45 ++++++++++++++++++++++++++++++++----
 3 files changed, 45 insertions(+), 5 deletions(-)
include/linux/cgroup.h renamed from include/linux/cgroup.h~cgroup_disable +1 -0
diff -puN include/linux/cgroup.h~cgroup_disable include/linux/cgroup.h
@@ -256,6 +256,7 @@ struct cgroup_subsys {
 	void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
 	int subsys_id;
 	int active;
+	int disabled;
 	int early_init;
 #define MAX_CGROUP_TYPE_NAMELEN 32
 	const char *name;
kernel/cgroup.c renamed from kernel/cgroup.c~cgroup_disable +40 -5

70 lines not on this page · raw message

Documentation/kernel-parameters.txt renamed from Documentation/kernel-parameters.txt~cgroup_disable +4 -0
diff -puN Documentation/kernel-parameters.txt~cgroup_disable Documentation/kernel-parameters.txt
@@ -383,6 +383,10 @@ and is between 256 and 4096 characters. 
 	ccw_timeout_log [S390]
 			See Documentation/s390/CommonIO for details.
 
+	cgroup_disable= [KNL] Disable a particular controller
+			Format: {name of the controller(s) to disable}
+				{Currently supported controllers - "memory"}
+
 	checkreqprot	[SELINUX] Set initial checkreqprot flag value.
 			Format: { "0" | "1" }
 			See security/selinux/Kconfig help text.

_

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/1 Make memory resource control aware of boot options (v2)

A boot option for the memory controller was discussed on lkml. It is a good idea to add it, since it saves memory for people who want to turn off the memory controller.

By default the option is on for the following two reasons

1. It provides compatibility with the current scheme where the memory controller turns on if the config option is enabled
2. It allows for wider testing of the memory controller, once the config option is enabled

We still allow the create, destroy callbacks to succeed, since they are not aware of boot options. We do not populate the directory will memory resource controller specific files.

---

 mm/memcontrol.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
mm/memcontrol.c renamed from mm/memcontrol.c~memory-controller-add-boot-option +17 -0
diff -puN mm/memcontrol.c~memory-controller-add-boot-option mm/memcontrol.c
@@ -533,6 +533,9 @@ static int mem_cgroup_charge_common(stru
 	unsigned long nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
 	struct mem_cgroup_per_zone *mz;
 
+	if (mem_cgroup_subsys.disabled)
+		return 0;
+
 	/*
 	 * Should page_cgroup's go to their own slab?
 	 * One could optimize the performance of the charging routine
@@ -665,6 +668,9 @@ void mem_cgroup_uncharge_page(struct pag
 	struct mem_cgroup_per_zone *mz;
 	unsigned long flags;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	/*
 	 * Check if our page_cgroup is valid
 	 */
@@ -705,6 +711,9 @@ int mem_cgroup_prepare_migration(struct 
 {
 	struct page_cgroup *pc;
 
+	if (mem_cgroup_subsys.disabled)
+		return 0;
+
 	lock_page_cgroup(page);
 	pc = page_get_page_cgroup(page);
 	if (pc)
@@ -803,6 +812,9 @@ static int mem_cgroup_force_empty(struct
 	int ret = -EBUSY;
 	int node, zid;
 
+	if (mem_cgroup_subsys.disabled)
+		return 0;
+
 	css_get(&mem->css);
 	/*
 	 * page reclaim code (kswapd etc..) will move pages between
@@ -1053,6 +1065,8 @@ static void mem_cgroup_destroy(struct cg
 static int mem_cgroup_populate(struct cgroup_subsys *ss,
 				struct cgroup *cont)
 {
+	if (mem_cgroup_subsys.disabled)
+		return 0;
 	return cgroup_add_files(cont, ss, mem_cgroup_files,
 					ARRAY_SIZE(mem_cgroup_files));
 }
@@ -1065,6 +1079,9 @@ static void mem_cgroup_move_task(struct 
 	struct mm_struct *mm;
 	struct mem_cgroup *mem, *old_mem;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	mm = get_task_mm(p);
 	if (mm == NULL)
 		return;

_

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#2 lore raw

Re: [PATCH] Make memory resource control aware of boot options (v2)

Review

Quoted 1 line · On Fri, 07 Mar 2008 14:27:46 +0530 Balbir Singh <[email protected]>…
(quoted diff) +1 -0
+	if (mem_cgroup_subsys.disabled)

My copy of `struct cgroup_subsys' doesn't have a .disabled?

If it did, I might want it __read_mostly.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw

Re: [PATCH] Make memory resource control aware of boot options (v2)

Quoted 6 lines · On Fri, 7 Mar 2008 01:06:49 -0800 Andrew Morton <[email protected]>…

Review

Quoted 1 line · On Fri, 07 Mar 2008 14:27:46 +0530 Balbir Singh <[email protected]>…
(quoted diff) +1 -0
+	if (mem_cgroup_subsys.disabled)

My copy of `struct cgroup_subsys' doesn't have a .disabled?

Ah. You didn't sequence-number the patches, and they arrived out-of-order. tsk.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [PATCH] Make memory resource control aware of boot options (v2)

Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Fri, 7 Mar 2008 01:06:49 -0800 Andrew Morton <[email protected]>…

Review

Quoted 1 line · On Fri, 07 Mar 2008 14:27:46 +0530 Balbir Singh <[email protected]>…
(quoted diff) +1 -0
+	if (mem_cgroup_subsys.disabled)

My copy of `struct cgroup_subsys' doesn't have a .disabled?

Ah. You didn't sequence-number the patches, and they arrived out-of-order. tsk.

Oops -- sorry about that.

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
In reply to Balbir Singh
Quoted 4 lines · Balbir Singh

diff -puN Documentation/kernel-parameters.txt~cgroup_disable Documentation/kernel-parameters.txt

Documentation/kernel-parameters.txt and is between 256 and 4096 characters. · line 392

Quoted 10 lines
Documentation/kernel-parameters.txt renamed from Documentation/kernel-parameters.txt~cgroup_disable +4 -0
@@ -383,6 +383,10 @@ and is between 256 and 4096 characters. 
 	ccw_timeout_log [S390]
 			See Documentation/s390/CommonIO for details.
 
+	cgroup_disable= [KNL] Disable a particular controller
+			Format: {name of the controller(s) to disable}
+				{Currently supported controllers - "memory"}
+
 	checkreqprot	[SELINUX] Set initial checkreqprot flag value.
 			Format: { "0" | "1" }
 			See security/selinux/Kconfig help text.

It would probably be helpful to mention in the documentation that the names of the subsystems must now be delimited by commas.

[ I also find it very helpful to add [email protected] to the cc
list for any patch touching Documentation ]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
In reply to Balbir Singh
Quoted 3 lines · Balbir Singh

This doesn't handle early_init subsystems (their "disabled" bit isn't set be,

I think you meant something like

(their "disabled" bit isn't set before their initial "create" call is made)

Quoted 5 lines

+static int __init cgroup_disable(char *str)
+{
+ int i;
+
+ while (*str) {

Quoted 8 lines

+ for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
+ struct cgroup_subsys *ss = subsys[i];
+
+ if (!strncmp(str, ss->name, strlen(ss->name))) {
+ ss->disabled = 1;
+ printk(KERN_INFO "Disabling %s control group"
+ " subsystem\n", ss->name);
+ break;

Doesn't this mean that cgroup_disable=cpu will disable whichever comes first out of cpuset, cpuacct or cpu in the subsystem list?

I suggest just sticking with the original simpler version that required separate cgroup_disabled=foo options for each system that you want to disable.

Paul

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 3 lines · Paul Menage

Doesn't this mean that cgroup_disable=cpu will disable whichever comes first out of cpuset, cpuacct or cpu in the subsystem list?

Or rather, it's the other way around - cgroup_disable=cpuset will instead disable the "cpu" subsystem if "cpu" comes before "cpuset" in the subsystem list.

Paul

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 8 lines · Paul Menage
Quoted 2 lines · Paul Menage

Doesn't this mean that cgroup_disable=cpu will disable whichever comes first out of cpuset, cpuacct or cpu in the subsystem list?

Or rather, it's the other way around - cgroup_disable=cpuset will instead disable the "cpu" subsystem if "cpu" comes before "cpuset" in the subsystem list.

Would it? I must be missing something, since we do a strncmp with ss->name. I would expect that to match whole strings.

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw
Quoted 8 lines · Balbir Singh
Quoted 4 lines

Or rather, it's the other way around - cgroup_disable=cpuset will instead disable the "cpu" subsystem if "cpu" comes before "cpuset" in the subsystem list.

Would it? I must be missing something, since we do a strncmp with ss->name. I would expect that to match whole strings.

No, strncmp only checks the first n characters - so in that case, you'd be checking for !strncmp("cpuset", "cpu", 3), which will return true

Paul

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw
Quoted 6 lines · Paul Menage
Quoted 5 lines · Balbir Singh
Quoted 4 lines

Or rather, it's the other way around - cgroup_disable=cpuset will instead disable the "cpu" subsystem if "cpu" comes before "cpuset" in the subsystem list.

Quoted 7 lines
Quoted 3 lines

Would it? I must be missing something, since we do a strncmp with ss->name. I would expect that to match whole strings.

No, strncmp only checks the first n characters - so in that case, you'd be checking for !strncmp("cpuset", "cpu", 3), which will return true

Aaah.. I see the problem now.

Signature · 10 lines
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>